| 123456789101112131415161718192021222324252627282930 |
- /** JKES 乐跑任务队列(已无旧版工商队列) */
- const TASK_QUEUE = 'jkes_runforge_task_queue'
- 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
- }
|