enqueueLepaoStartRun.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. const mq = require('./index')
  2. const { assertRunforgeTaskIngress, publishRunforgeTask } = require('./runforgeTaskMq')
  3. const mqNames = require('./jkesMqNames')
  4. /**
  5. * 将乐跑任务写入 MQ,由 Worker 执行(JKES)
  6. */
  7. async function enqueueLepaoStartRun(studentNum, logger, options = {}) {
  8. try {
  9. const channel = await mq.getChannel(mqNames.channelAccountAutorun)
  10. await assertRunforgeTaskIngress(channel, logger)
  11. const taskId = `lepao:account:${Date.now()}:${studentNum}`
  12. const data = {
  13. taskId,
  14. account: studentNum
  15. }
  16. if (options.targetKm != null) {
  17. data.targetKm = options.targetKm
  18. }
  19. if (options.autoDoubleSlot) {
  20. data.autoDoubleSlot = true
  21. }
  22. if (options.paceRandomMinSecPerKm != null && options.paceRandomMaxSecPerKm != null) {
  23. data.paceRandomMinSecPerKm = options.paceRandomMinSecPerKm
  24. data.paceRandomMaxSecPerKm = options.paceRandomMaxSecPerKm
  25. }
  26. publishRunforgeTask(channel, {
  27. id: taskId,
  28. type: 'lepao.startRun',
  29. data,
  30. retry: 0
  31. })
  32. } catch (e) {
  33. logger?.error?.(`投递自动乐跑任务失败 ${studentNum}: ${e.message || e}`)
  34. }
  35. }
  36. module.exports = { enqueueLepaoStartRun }