"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MainQueueService = void 0;
const amqplib_1 = __importDefault(require("amqplib"));
const { NODE_ENV } = process.env;
class MainQueueService {
    async sendTaskToQueue(task, queueName) {
        console.log('sending a new task to queue...');
        const rabbitMQApi = NODE_ENV === 'development' ? 'localhost' : 'rabbitmq';
        const connection = await amqplib_1.default.connect(`amqp://${rabbitMQApi}`, { heartbeat: 10 });
        const channel = await connection.createChannel();
        await channel.assertQueue(queueName);
        channel.sendToQueue(queueName, Buffer.from(JSON.stringify(task)));
        await channel.close();
        await connection.close();
        console.log('new task is sent');
    }
}
exports.MainQueueService = MainQueueService;
