storeAndEnqueueJob.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --[[
  2. Shared helper to store a job and enqueue it into the appropriate list/set.
  3. Handles delayed, prioritized, and standard (LIFO/FIFO) jobs.
  4. Emits the appropriate event after enqueuing ("delayed" or "waiting").
  5. Returns delay, priority from storeJob.
  6. ]]
  7. -- Includes
  8. --- @include "addDelayedJob"
  9. --- @include "addJobInTargetList"
  10. --- @include "addJobWithPriority"
  11. --- @include "getTargetQueueList"
  12. --- @include "storeJob"
  13. local function storeAndEnqueueJob(eventsKey, jobIdKey, jobId, name, data, opts,
  14. timestamp, parentKey, parentData, repeatJobKey, maxEvents,
  15. waitKey, pausedKey, activeKey, metaKey, prioritizedKey,
  16. priorityCounterKey, delayedKey, markerKey)
  17. local delay, priority = storeJob(eventsKey, jobIdKey, jobId, name, data,
  18. opts, timestamp, parentKey, parentData, repeatJobKey)
  19. if delay ~= 0 and delayedKey then
  20. addDelayedJob(jobId, delayedKey, eventsKey, timestamp, maxEvents, markerKey, delay)
  21. else
  22. local target, isPausedOrMaxed = getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
  23. if priority > 0 then
  24. addJobWithPriority(markerKey, prioritizedKey, priority, jobId,
  25. priorityCounterKey, isPausedOrMaxed)
  26. else
  27. local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
  28. addJobInTargetList(target, markerKey, pushCmd, isPausedOrMaxed, jobId)
  29. end
  30. rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
  31. "jobId", jobId)
  32. end
  33. return delay, priority
  34. end