runforgeTaskMq.js 686 B

1234567891011121314151617181920212223242526
  1. const TASK_QUEUE = 'runforge_task_queue'
  2. /**
  3. * 声明乐跑任务主队列(无 RabbitMQ 插件)
  4. */
  5. async function assertRunforgeTaskIngress(channel, logger) {
  6. await channel.assertQueue(TASK_QUEUE, { durable: true })
  7. return { mode: 'direct', queue: TASK_QUEUE }
  8. }
  9. /**
  10. * 投递乐跑任务 JSON 消息体(与 Worker 消费格式一致)
  11. */
  12. function publishRunforgeTask(channel, messageObject) {
  13. const body = Buffer.from(JSON.stringify(messageObject))
  14. channel.sendToQueue(TASK_QUEUE, body, {
  15. persistent: true,
  16. contentType: 'application/json'
  17. })
  18. }
  19. module.exports = {
  20. TASK_QUEUE,
  21. assertRunforgeTaskIngress,
  22. publishRunforgeTask
  23. }