import json

import pika
import logging

from app.core.config import RABBITMQ_PARAMS

logger = logging.getLogger(__name__)


def publish_status(message, queue_name):
    connection = pika.BlockingConnection(pika.ConnectionParameters(**RABBITMQ_PARAMS))
    channel = connection.channel()
    channel.queue_declare(queue=queue_name, durable=True)
    channel.basic_publish(exchange='',
                          routing_key=queue_name,
                          body=message,
                          properties=pika.BasicProperties(
                              delivery_mode=2,
                          ))
    connection.close()

    logger.info(f" [x] Queue : {queue_name} | Sent message : {json.dumps(json.loads(message), indent=4)}")
