import json

import pika

from app.core.config import RABBITMQ_PARAMS, BATCH_DESIGN_RABBITMQ_QUEUES


def publish_status(task_id, progress, result):
    connection = pika.BlockingConnection(pika.ConnectionParameters(**RABBITMQ_PARAMS))
    channel = connection.channel()
    channel.queue_declare(queue=BATCH_DESIGN_RABBITMQ_QUEUES, durable=True)
    message = {'task_id': task_id, 'progress': progress, "result": result}
    channel.basic_publish(exchange='',
                          routing_key=BATCH_DESIGN_RABBITMQ_QUEUES,
                          body=json.dumps(message),
                          properties=pika.BasicProperties(
                              delivery_mode=2,
                          ))
    connection.close()
