const { mq } = require('./mqPrefix') const TASK_QUEUE = mq('runforge_task_queue') /** * 声明乐跑任务主队列(无 RabbitMQ 插件) */ async function assertRunforgeTaskIngress(channel, logger) { await channel.assertQueue(TASK_QUEUE, { durable: true }) return { mode: 'direct', queue: TASK_QUEUE } } /** * 投递乐跑任务 JSON 消息体(与 Worker 消费格式一致) */ function publishRunforgeTask(channel, messageObject, logger) { const body = Buffer.from(JSON.stringify(messageObject)) const ok = channel.sendToQueue(TASK_QUEUE, body, { persistent: true, contentType: 'application/json' }) if (!ok) { throw new Error(`MQ 背压,未能写入队列 ${TASK_QUEUE}`) } logger?.info?.( `乐跑任务已投递 MQ queue=${TASK_QUEUE} id=${messageObject?.id} type=${messageObject?.type}` ) } module.exports = { TASK_QUEUE, assertRunforgeTaskIngress, publishRunforgeTask }