43 lines
1.4 KiB
Lua
43 lines
1.4 KiB
Lua
--[[
|
|
Shared helper to store a job and enqueue it into the appropriate list/set.
|
|
Handles delayed, prioritized, and standard (LIFO/FIFO) jobs.
|
|
Emits the appropriate event after enqueuing ("delayed" or "waiting").
|
|
|
|
Returns delay, priority from storeJob.
|
|
]]
|
|
|
|
-- Includes
|
|
--- @include "addDelayedJob"
|
|
--- @include "addJobInTargetList"
|
|
--- @include "addJobWithPriority"
|
|
--- @include "isQueuePausedOrMaxed"
|
|
--- @include "storeJob"
|
|
|
|
local function storeAndEnqueueJob(eventsKey, jobIdKey, jobId, name, data, opts,
|
|
timestamp, parentKey, parentData, repeatJobKey, maxEvents,
|
|
waitKey, pausedKey, activeKey, metaKey, prioritizedKey,
|
|
priorityCounterKey, delayedKey, markerKey)
|
|
|
|
local delay, priority = storeJob(eventsKey, jobIdKey, jobId, name, data,
|
|
opts, timestamp, parentKey, parentData, repeatJobKey)
|
|
|
|
if delay ~= 0 and delayedKey then
|
|
addDelayedJob(jobId, delayedKey, eventsKey, timestamp, maxEvents, markerKey, delay)
|
|
else
|
|
local isPausedOrMaxed = isQueuePausedOrMaxed(metaKey, activeKey)
|
|
|
|
if priority > 0 then
|
|
addJobWithPriority(markerKey, prioritizedKey, priority, jobId,
|
|
priorityCounterKey, isPausedOrMaxed)
|
|
else
|
|
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
|
addJobInTargetList(waitKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
|
end
|
|
|
|
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
|
|
"jobId", jobId)
|
|
end
|
|
|
|
return delay, priority
|
|
end
|