const mq = require('./') 

const initmq = async () => {
    try {
        await mq.init()

        const ch = await mq.getChannel('init')

        // 结束交换机
        await ch.assertExchange('cg_run_finish_exchange', 'direct', { durable: true })

        // 结束队列
        await ch.assertQueue('cg_run_finish_queue', { durable: true })
        await ch.bindQueue(
            'cg_run_finish_queue',
            'cg_run_finish_exchange',
            'finish'
        )

        // 延迟队列
        await ch.assertQueue('cg_run_delay_queue', {
            durable: true,
            arguments: {
                'x-dead-letter-exchange': 'cg_run_finish_exchange',
                'x-dead-letter-routing-key': 'finish'
            }
        })
    } catch (e) {
        console.error('❌ RabbitMQ 初始化失败', e)
        process.exit(1)
    }
}

module.exports = initmq
