Auto-commit 2026-05-02 09:37
This commit is contained in:
5
node_modules/bullmq/dist/esm/scripts/addDelayedJob-6.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/addDelayedJob-6.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const addDelayedJob: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
575
node_modules/bullmq/dist/esm/scripts/addDelayedJob-6.js
generated
vendored
Normal file
575
node_modules/bullmq/dist/esm/scripts/addDelayedJob-6.js
generated
vendored
Normal file
@@ -0,0 +1,575 @@
|
||||
const content = `--[[
|
||||
Adds a delayed job to the queue by doing the following:
|
||||
- Increases the job counter if needed.
|
||||
- Creates a new job key with the job data.
|
||||
- computes timestamp.
|
||||
- adds to delayed zset.
|
||||
- Emits a global event 'delayed' if the job is delayed.
|
||||
Input:
|
||||
KEYS[1] 'marker',
|
||||
KEYS[2] 'meta'
|
||||
KEYS[3] 'id'
|
||||
KEYS[4] 'delayed'
|
||||
KEYS[5] 'completed'
|
||||
KEYS[6] events stream key
|
||||
ARGV[1] msgpacked arguments array
|
||||
[1] key prefix,
|
||||
[2] custom id (use custom instead of one generated automatically)
|
||||
[3] name
|
||||
[4] timestamp
|
||||
[5] parentKey?
|
||||
[6] parent dependencies key.
|
||||
[7] parent? {id, queueKey}
|
||||
[8] repeat job key
|
||||
[9] deduplication key
|
||||
ARGV[2] Json stringified job data
|
||||
ARGV[3] msgpacked options
|
||||
Output:
|
||||
jobId - OK
|
||||
-5 - Missing parent key
|
||||
]]
|
||||
local metaKey = KEYS[2]
|
||||
local idKey = KEYS[3]
|
||||
local delayedKey = KEYS[4]
|
||||
local completedKey = KEYS[5]
|
||||
local eventsKey = KEYS[6]
|
||||
local jobId
|
||||
local jobIdKey
|
||||
local rcall = redis.call
|
||||
local args = cmsgpack.unpack(ARGV[1])
|
||||
local data = ARGV[2]
|
||||
local parentKey = args[5]
|
||||
local parent = args[7]
|
||||
local repeatJobKey = args[8]
|
||||
local deduplicationKey = args[9]
|
||||
local parentData
|
||||
-- Includes
|
||||
--[[
|
||||
Adds a delayed job to the queue by doing the following:
|
||||
- Creates a new job key with the job data.
|
||||
- adds to delayed zset.
|
||||
- Emits a global event 'delayed' if the job is delayed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add delay marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to return the next delayed job timestamp.
|
||||
]]
|
||||
local function getNextDelayedTimestamp(delayedKey)
|
||||
local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
|
||||
if #result then
|
||||
local nextTimestamp = tonumber(result[2])
|
||||
if nextTimestamp ~= nil then
|
||||
return nextTimestamp / 0x1000
|
||||
end
|
||||
end
|
||||
end
|
||||
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
||||
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
||||
if nextTimestamp ~= nil then
|
||||
-- Replace the score of the marker with the newest known
|
||||
-- next timestamp.
|
||||
rcall("ZADD", markerKey, nextTimestamp, "1")
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Bake in the job id first 12 bits into the timestamp
|
||||
to guarantee correct execution order of delayed jobs
|
||||
(up to 4096 jobs per given timestamp or 4096 jobs apart per timestamp)
|
||||
WARNING: Jobs that are so far apart that they wrap around will cause FIFO to fail
|
||||
]]
|
||||
local function getDelayedScore(delayedKey, timestamp, delay)
|
||||
local delayedTimestamp = (delay > 0 and (tonumber(timestamp) + delay)) or tonumber(timestamp)
|
||||
local minScore = delayedTimestamp * 0x1000
|
||||
local maxScore = (delayedTimestamp + 1 ) * 0x1000 - 1
|
||||
local result = rcall("ZREVRANGEBYSCORE", delayedKey, maxScore,
|
||||
minScore, "WITHSCORES","LIMIT", 0, 1)
|
||||
if #result then
|
||||
local currentMaxScore = tonumber(result[2])
|
||||
if currentMaxScore ~= nil then
|
||||
if currentMaxScore >= maxScore then
|
||||
return maxScore, delayedTimestamp
|
||||
else
|
||||
return currentMaxScore + 1, delayedTimestamp
|
||||
end
|
||||
end
|
||||
end
|
||||
return minScore, delayedTimestamp
|
||||
end
|
||||
local function addDelayedJob(jobId, delayedKey, eventsKey, timestamp,
|
||||
maxEvents, markerKey, delay)
|
||||
local score, delayedTimestamp = getDelayedScore(delayedKey, timestamp, tonumber(delay))
|
||||
rcall("ZADD", delayedKey, score, jobId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "delayed",
|
||||
"jobId", jobId, "delay", delayedTimestamp)
|
||||
-- mark that a delayed job is available
|
||||
addDelayMarkerIfNeeded(markerKey, delayedKey)
|
||||
end
|
||||
--[[
|
||||
Function to debounce a job.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to deduplicate a job.
|
||||
]]
|
||||
--[[
|
||||
Function to set the deduplication key for a job.
|
||||
Uses TTL from deduplication opts if provided.
|
||||
]]
|
||||
local function setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
local ttl = deduplicationOpts and deduplicationOpts['ttl']
|
||||
if ttl and ttl > 0 then
|
||||
rcall('SET', deduplicationKey, jobId, 'PX', ttl)
|
||||
else
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to store a deduplicated next job if the existing job is active
|
||||
and keepLastIfActive is set. When the active job finishes, the stored
|
||||
proto-job is used to create a real job in the queue.
|
||||
Returns true if the proto-job was stored, false otherwise.
|
||||
]]
|
||||
--[[
|
||||
Function to check if an item belongs to a list.
|
||||
]]
|
||||
local function checkItemInList(list, item)
|
||||
for _, v in pairs(list) do
|
||||
if v == item then
|
||||
return 1
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
local function storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
if deduplicationOpts['keepLastIfActive'] and currentDebounceJobId then
|
||||
local activeKey = prefix .. "active"
|
||||
local activeItems = rcall('LRANGE', activeKey, 0, -1)
|
||||
if checkItemInList(activeItems, currentDebounceJobId) then
|
||||
local deduplicationNextKey = prefix .. "dn:" .. deduplicationId
|
||||
local fields = {'name', jobName, 'data', jobData, 'opts', cjson.encode(fullOpts)}
|
||||
if parentKey then
|
||||
fields[#fields+1] = 'pk'
|
||||
fields[#fields+1] = parentKey
|
||||
end
|
||||
if parentData then
|
||||
fields[#fields+1] = 'pd'
|
||||
fields[#fields+1] = parentData
|
||||
end
|
||||
if parentDependenciesKey then
|
||||
fields[#fields+1] = 'pdk'
|
||||
fields[#fields+1] = parentDependenciesKey
|
||||
end
|
||||
if repeatJobKey then
|
||||
fields[#fields+1] = 'rjk'
|
||||
fields[#fields+1] = repeatJobKey
|
||||
end
|
||||
rcall('HSET', deduplicationNextKey, unpack(fields))
|
||||
-- Ensure the dedup key does not expire while the job is active,
|
||||
-- so subsequent adds always hit the dedup path and never bypass
|
||||
-- the active-check because of a TTL expiry.
|
||||
local deduplicationKey = prefix .. "de:" .. deduplicationId
|
||||
rcall('PERSIST', deduplicationKey)
|
||||
-- TODO remove debounced event in next breaking change
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced", "jobId",
|
||||
currentDebounceJobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
currentDebounceJobId, "deduplicationId", deduplicationId, "deduplicatedJobId", jobId)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function deduplicateJobWithoutReplace(deduplicationId, deduplicationOpts, jobId, deduplicationKey,
|
||||
eventsKey, maxEvents, prefix, jobName, jobData, fullOpts,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
local ttl = deduplicationOpts['ttl']
|
||||
local deduplicationKeyExists
|
||||
if ttl and ttl > 0 then
|
||||
if deduplicationOpts['extend'] then
|
||||
local currentDebounceJobId = rcall('GET', deduplicationKey)
|
||||
if currentDebounceJobId then
|
||||
if storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey) then
|
||||
return currentDebounceJobId
|
||||
end
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, currentDebounceJobId)
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, currentDebounceJobId, deduplicationOpts)
|
||||
end
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced",
|
||||
"jobId", currentDebounceJobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
currentDebounceJobId, "deduplicationId", deduplicationId, "deduplicatedJobId", jobId)
|
||||
return currentDebounceJobId
|
||||
else
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
end
|
||||
return
|
||||
end
|
||||
else
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'NX')
|
||||
else
|
||||
deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'PX', ttl, 'NX')
|
||||
end
|
||||
end
|
||||
else
|
||||
deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'NX')
|
||||
end
|
||||
if deduplicationKeyExists then
|
||||
local currentDebounceJobId = rcall('GET', deduplicationKey)
|
||||
if storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey) then
|
||||
return currentDebounceJobId
|
||||
end
|
||||
-- TODO remove debounced event in next breaking change
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced", "jobId",
|
||||
currentDebounceJobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
currentDebounceJobId, "deduplicationId", deduplicationId, "deduplicatedJobId", jobId)
|
||||
return currentDebounceJobId
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to remove job keys.
|
||||
]]
|
||||
local function removeJobKeys(jobKey)
|
||||
return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
|
||||
jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
|
||||
end
|
||||
local function removeDelayedJob(delayedKey, deduplicationKey, eventsKey, maxEvents, currentDeduplicatedJobId,
|
||||
jobId, deduplicationId, prefix)
|
||||
if rcall("ZREM", delayedKey, currentDeduplicatedJobId) > 0 then
|
||||
removeJobKeys(prefix .. currentDeduplicatedJobId)
|
||||
rcall("XADD", eventsKey, "*", "event", "removed", "jobId", currentDeduplicatedJobId,
|
||||
"prev", "delayed")
|
||||
-- TODO remove debounced event in next breaking change
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced", "jobId",
|
||||
jobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
jobId, "deduplicationId", deduplicationId, "deduplicatedJobId", currentDeduplicatedJobId)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function deduplicateJob(deduplicationOpts, jobId, delayedKey, deduplicationKey, eventsKey, maxEvents,
|
||||
prefix, jobName, jobData, fullOpts, parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
local deduplicationId = deduplicationOpts and deduplicationOpts['id']
|
||||
if deduplicationId then
|
||||
if deduplicationOpts['replace'] then
|
||||
local currentDebounceJobId = rcall('GET', deduplicationKey)
|
||||
if currentDebounceJobId then
|
||||
local isRemoved = removeDelayedJob(delayedKey, deduplicationKey, eventsKey, maxEvents,
|
||||
currentDebounceJobId, jobId, deduplicationId, prefix)
|
||||
if isRemoved then
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
else
|
||||
local ttl = deduplicationOpts['ttl']
|
||||
if not deduplicationOpts['extend'] and ttl and ttl > 0 then
|
||||
rcall('SET', deduplicationKey, jobId, 'KEEPTTL')
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
end
|
||||
end
|
||||
return
|
||||
else
|
||||
storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
return currentDebounceJobId
|
||||
end
|
||||
else
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
end
|
||||
return
|
||||
end
|
||||
else
|
||||
return deduplicateJobWithoutReplace(deduplicationId, deduplicationOpts,
|
||||
jobId, deduplicationKey, eventsKey, maxEvents, prefix, jobName, jobData, fullOpts,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to get max events value or set by default 10000.
|
||||
]]
|
||||
local function getOrSetMaxEvents(metaKey)
|
||||
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
||||
if not maxEvents then
|
||||
maxEvents = 10000
|
||||
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
||||
end
|
||||
return maxEvents
|
||||
end
|
||||
--[[
|
||||
Function to handle the case when job is duplicated.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
This function is used to update the parent's dependencies if the job
|
||||
is already completed and about to be ignored. The parent must get its
|
||||
dependencies updated to avoid the parent job being stuck forever in
|
||||
the waiting-children state.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Validate and move or add dependencies to parent.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Validate and move parent to a wait status (waiting, delayed or prioritized)
|
||||
if no pending dependencies.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Move parent to a wait status (wait, prioritized or delayed)
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to add job in target list and add marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall(pushCmd, targetKey, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to add job considering priority.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to get priority score.
|
||||
]]
|
||||
local function getPriorityScore(priority, priorityCounterKey)
|
||||
local prioCounter = rcall("INCR", priorityCounterKey)
|
||||
return priority * 0x100000000 + prioCounter % 0x100000000
|
||||
end
|
||||
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
|
||||
isPausedOrMaxed)
|
||||
local score = getPriorityScore(priority, priorityCounterKey)
|
||||
rcall("ZADD", prioritizedKey, score, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to check if queue is paused or maxed
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
|
||||
if queueAttributes[1] then
|
||||
return true
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
return activeCount >= tonumber(queueAttributes[2])
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
||||
local parentWaitKey = parentQueueKey .. ":wait"
|
||||
local parentPausedKey = parentQueueKey .. ":paused"
|
||||
local parentActiveKey = parentQueueKey .. ":active"
|
||||
local parentMetaKey = parentQueueKey .. ":meta"
|
||||
local parentMarkerKey = parentQueueKey .. ":marker"
|
||||
local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
|
||||
local priority = tonumber(jobAttributes[1]) or 0
|
||||
local delay = tonumber(jobAttributes[2]) or 0
|
||||
if delay > 0 then
|
||||
local delayedTimestamp = tonumber(timestamp) + delay
|
||||
local score = delayedTimestamp * 0x1000
|
||||
local parentDelayedKey = parentQueueKey .. ":delayed"
|
||||
rcall("ZADD", parentDelayedKey, score, parentId)
|
||||
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
|
||||
delayedTimestamp)
|
||||
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
||||
else
|
||||
if priority == 0 then
|
||||
local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
|
||||
parentWaitKey, parentPausedKey)
|
||||
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
||||
else
|
||||
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
||||
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
||||
parentQueueKey .. ":pc", isPausedOrMaxed)
|
||||
end
|
||||
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
||||
"waiting-children")
|
||||
end
|
||||
end
|
||||
local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
||||
if rcall("EXISTS", parentKey) == 1 then
|
||||
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
||||
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
||||
rcall("ZREM", parentWaitingChildrenKey, parentId)
|
||||
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
|
||||
parentId, timestamp)
|
||||
local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
|
||||
if doNotHavePendingDependencies then
|
||||
moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
||||
end
|
||||
end
|
||||
local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
|
||||
parentId, jobIdKey, returnvalue, timestamp )
|
||||
local processedSet = parentKey .. ":processed"
|
||||
rcall("HSET", processedSet, jobIdKey, returnvalue)
|
||||
moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
|
||||
end
|
||||
local function updateExistingJobsParent(parentKey, parent, parentData,
|
||||
parentDependenciesKey, completedKey,
|
||||
jobIdKey, jobId, timestamp)
|
||||
if parentKey ~= nil then
|
||||
if rcall("ZSCORE", completedKey, jobId) then
|
||||
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
||||
updateParentDepsIfNeeded(parentKey, parent['queueKey'],
|
||||
parentDependenciesKey, parent['id'],
|
||||
jobIdKey, returnvalue, timestamp)
|
||||
else
|
||||
if parentDependenciesKey ~= nil then
|
||||
rcall("SADD", parentDependenciesKey, jobIdKey)
|
||||
end
|
||||
end
|
||||
rcall("HMSET", jobIdKey, "parentKey", parentKey, "parent", parentData)
|
||||
end
|
||||
end
|
||||
local function handleDuplicatedJob(jobKey, jobId, currentParentKey, currentParent,
|
||||
parentData, parentDependenciesKey, completedKey, eventsKey, maxEvents, timestamp)
|
||||
local existedParentKey = rcall("HGET", jobKey, "parentKey")
|
||||
if not existedParentKey or existedParentKey == currentParentKey then
|
||||
updateExistingJobsParent(currentParentKey, currentParent, parentData,
|
||||
parentDependenciesKey, completedKey, jobKey,
|
||||
jobId, timestamp)
|
||||
else
|
||||
if currentParentKey ~= nil and currentParentKey ~= existedParentKey
|
||||
and (rcall("EXISTS", existedParentKey) == 1) then
|
||||
return -7
|
||||
end
|
||||
end
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
|
||||
"duplicated", "jobId", jobId)
|
||||
return jobId .. "" -- convert to string
|
||||
end
|
||||
--[[
|
||||
Function to store a job
|
||||
]]
|
||||
local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
|
||||
parentKey, parentData, repeatJobKey)
|
||||
local jsonOpts = cjson.encode(opts)
|
||||
local delay = opts['delay'] or 0
|
||||
local priority = opts['priority'] or 0
|
||||
local debounceId = opts['de'] and opts['de']['id']
|
||||
local optionalValues = {}
|
||||
if parentKey ~= nil then
|
||||
table.insert(optionalValues, "parentKey")
|
||||
table.insert(optionalValues, parentKey)
|
||||
table.insert(optionalValues, "parent")
|
||||
table.insert(optionalValues, parentData)
|
||||
end
|
||||
if repeatJobKey then
|
||||
table.insert(optionalValues, "rjk")
|
||||
table.insert(optionalValues, repeatJobKey)
|
||||
end
|
||||
if debounceId then
|
||||
table.insert(optionalValues, "deid")
|
||||
table.insert(optionalValues, debounceId)
|
||||
end
|
||||
rcall("HMSET", jobIdKey, "name", name, "data", data, "opts", jsonOpts,
|
||||
"timestamp", timestamp, "delay", delay, "priority", priority,
|
||||
unpack(optionalValues))
|
||||
rcall("XADD", eventsKey, "*", "event", "added", "jobId", jobId, "name", name)
|
||||
return delay, priority
|
||||
end
|
||||
if parentKey ~= nil then
|
||||
if rcall("EXISTS", parentKey) ~= 1 then return -5 end
|
||||
parentData = cjson.encode(parent)
|
||||
end
|
||||
local jobCounter = rcall("INCR", idKey)
|
||||
local maxEvents = getOrSetMaxEvents(metaKey)
|
||||
local opts = cmsgpack.unpack(ARGV[3])
|
||||
local parentDependenciesKey = args[6]
|
||||
local timestamp = args[4]
|
||||
if args[2] == "" then
|
||||
jobId = jobCounter
|
||||
jobIdKey = args[1] .. jobId
|
||||
else
|
||||
jobId = args[2]
|
||||
jobIdKey = args[1] .. jobId
|
||||
if rcall("EXISTS", jobIdKey) == 1 then
|
||||
return handleDuplicatedJob(jobIdKey, jobId, parentKey, parent,
|
||||
parentData, parentDependenciesKey, completedKey, eventsKey,
|
||||
maxEvents, timestamp)
|
||||
end
|
||||
end
|
||||
local deduplicationJobId = deduplicateJob(opts['de'], jobId, delayedKey, deduplicationKey,
|
||||
eventsKey, maxEvents, args[1], args[3], ARGV[2], opts,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
if deduplicationJobId then
|
||||
return deduplicationJobId
|
||||
end
|
||||
local delay, priority = storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2],
|
||||
opts, timestamp, parentKey, parentData, repeatJobKey)
|
||||
addDelayedJob(jobId, delayedKey, eventsKey, timestamp, maxEvents, KEYS[1], delay)
|
||||
-- Check if this job is a child of another job, if so add it to the parents dependencies
|
||||
if parentDependenciesKey ~= nil then
|
||||
rcall("SADD", parentDependenciesKey, jobIdKey)
|
||||
end
|
||||
return jobId .. "" -- convert to string
|
||||
`;
|
||||
export const addDelayedJob = {
|
||||
name: 'addDelayedJob',
|
||||
content,
|
||||
keys: 6,
|
||||
};
|
||||
//# sourceMappingURL=addDelayedJob-6.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/addDelayedJob-6.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/addDelayedJob-6.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"addDelayedJob-6.js","sourceRoot":"","sources":["../../../src/scripts/addDelayedJob-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwjBf,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/addJobScheduler-11.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/addJobScheduler-11.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const addJobScheduler: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
581
node_modules/bullmq/dist/esm/scripts/addJobScheduler-11.js
generated
vendored
Normal file
581
node_modules/bullmq/dist/esm/scripts/addJobScheduler-11.js
generated
vendored
Normal file
@@ -0,0 +1,581 @@
|
||||
const content = `--[[
|
||||
Adds a job scheduler, i.e. a job factory that creates jobs based on a given schedule (repeat options).
|
||||
Input:
|
||||
KEYS[1] 'repeat' key
|
||||
KEYS[2] 'delayed' key
|
||||
KEYS[3] 'wait' key
|
||||
KEYS[4] 'paused' key
|
||||
KEYS[5] 'meta' key
|
||||
KEYS[6] 'prioritized' key
|
||||
KEYS[7] 'marker' key
|
||||
KEYS[8] 'id' key
|
||||
KEYS[9] 'events' key
|
||||
KEYS[10] 'pc' priority counter
|
||||
KEYS[11] 'active' key
|
||||
ARGV[1] next milliseconds
|
||||
ARGV[2] msgpacked options
|
||||
[1] name
|
||||
[2] tz?
|
||||
[3] pattern?
|
||||
[4] endDate?
|
||||
[5] every?
|
||||
ARGV[3] jobs scheduler id
|
||||
ARGV[4] Json stringified template data
|
||||
ARGV[5] mspacked template opts
|
||||
ARGV[6] msgpacked delayed opts
|
||||
ARGV[7] timestamp
|
||||
ARGV[8] prefix key
|
||||
ARGV[9] producer key
|
||||
Output:
|
||||
repeatableKey - OK
|
||||
]] local rcall = redis.call
|
||||
local repeatKey = KEYS[1]
|
||||
local delayedKey = KEYS[2]
|
||||
local waitKey = KEYS[3]
|
||||
local pausedKey = KEYS[4]
|
||||
local metaKey = KEYS[5]
|
||||
local prioritizedKey = KEYS[6]
|
||||
local eventsKey = KEYS[9]
|
||||
local nextMillis = ARGV[1]
|
||||
local jobSchedulerId = ARGV[3]
|
||||
local templateOpts = cmsgpack.unpack(ARGV[5])
|
||||
local now = tonumber(ARGV[7])
|
||||
local prefixKey = ARGV[8]
|
||||
local jobOpts = cmsgpack.unpack(ARGV[6])
|
||||
-- Includes
|
||||
--[[
|
||||
Add delay marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
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
|
||||
--[[
|
||||
Adds a delayed job to the queue by doing the following:
|
||||
- Creates a new job key with the job data.
|
||||
- adds to delayed zset.
|
||||
- Emits a global event 'delayed' if the job is delayed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add delay marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to return the next delayed job timestamp.
|
||||
]]
|
||||
local function getNextDelayedTimestamp(delayedKey)
|
||||
local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
|
||||
if #result then
|
||||
local nextTimestamp = tonumber(result[2])
|
||||
if nextTimestamp ~= nil then
|
||||
return nextTimestamp / 0x1000
|
||||
end
|
||||
end
|
||||
end
|
||||
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
||||
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
||||
if nextTimestamp ~= nil then
|
||||
-- Replace the score of the marker with the newest known
|
||||
-- next timestamp.
|
||||
rcall("ZADD", markerKey, nextTimestamp, "1")
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Bake in the job id first 12 bits into the timestamp
|
||||
to guarantee correct execution order of delayed jobs
|
||||
(up to 4096 jobs per given timestamp or 4096 jobs apart per timestamp)
|
||||
WARNING: Jobs that are so far apart that they wrap around will cause FIFO to fail
|
||||
]]
|
||||
local function getDelayedScore(delayedKey, timestamp, delay)
|
||||
local delayedTimestamp = (delay > 0 and (tonumber(timestamp) + delay)) or tonumber(timestamp)
|
||||
local minScore = delayedTimestamp * 0x1000
|
||||
local maxScore = (delayedTimestamp + 1 ) * 0x1000 - 1
|
||||
local result = rcall("ZREVRANGEBYSCORE", delayedKey, maxScore,
|
||||
minScore, "WITHSCORES","LIMIT", 0, 1)
|
||||
if #result then
|
||||
local currentMaxScore = tonumber(result[2])
|
||||
if currentMaxScore ~= nil then
|
||||
if currentMaxScore >= maxScore then
|
||||
return maxScore, delayedTimestamp
|
||||
else
|
||||
return currentMaxScore + 1, delayedTimestamp
|
||||
end
|
||||
end
|
||||
end
|
||||
return minScore, delayedTimestamp
|
||||
end
|
||||
local function addDelayedJob(jobId, delayedKey, eventsKey, timestamp,
|
||||
maxEvents, markerKey, delay)
|
||||
local score, delayedTimestamp = getDelayedScore(delayedKey, timestamp, tonumber(delay))
|
||||
rcall("ZADD", delayedKey, score, jobId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "delayed",
|
||||
"jobId", jobId, "delay", delayedTimestamp)
|
||||
-- mark that a delayed job is available
|
||||
addDelayMarkerIfNeeded(markerKey, delayedKey)
|
||||
end
|
||||
--[[
|
||||
Function to add job in target list and add marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall(pushCmd, targetKey, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to add job considering priority.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to get priority score.
|
||||
]]
|
||||
local function getPriorityScore(priority, priorityCounterKey)
|
||||
local prioCounter = rcall("INCR", priorityCounterKey)
|
||||
return priority * 0x100000000 + prioCounter % 0x100000000
|
||||
end
|
||||
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
|
||||
isPausedOrMaxed)
|
||||
local score = getPriorityScore(priority, priorityCounterKey)
|
||||
rcall("ZADD", prioritizedKey, score, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
--[[
|
||||
Function to store a job
|
||||
]]
|
||||
local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
|
||||
parentKey, parentData, repeatJobKey)
|
||||
local jsonOpts = cjson.encode(opts)
|
||||
local delay = opts['delay'] or 0
|
||||
local priority = opts['priority'] or 0
|
||||
local debounceId = opts['de'] and opts['de']['id']
|
||||
local optionalValues = {}
|
||||
if parentKey ~= nil then
|
||||
table.insert(optionalValues, "parentKey")
|
||||
table.insert(optionalValues, parentKey)
|
||||
table.insert(optionalValues, "parent")
|
||||
table.insert(optionalValues, parentData)
|
||||
end
|
||||
if repeatJobKey then
|
||||
table.insert(optionalValues, "rjk")
|
||||
table.insert(optionalValues, repeatJobKey)
|
||||
end
|
||||
if debounceId then
|
||||
table.insert(optionalValues, "deid")
|
||||
table.insert(optionalValues, debounceId)
|
||||
end
|
||||
rcall("HMSET", jobIdKey, "name", name, "data", data, "opts", jsonOpts,
|
||||
"timestamp", timestamp, "delay", delay, "priority", priority,
|
||||
unpack(optionalValues))
|
||||
rcall("XADD", eventsKey, "*", "event", "added", "jobId", jobId, "name", name)
|
||||
return delay, priority
|
||||
end
|
||||
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 target, isPausedOrMaxed = getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
|
||||
if priority > 0 then
|
||||
addJobWithPriority(markerKey, prioritizedKey, priority, jobId,
|
||||
priorityCounterKey, isPausedOrMaxed)
|
||||
else
|
||||
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
||||
addJobInTargetList(target, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
end
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
|
||||
"jobId", jobId)
|
||||
end
|
||||
return delay, priority
|
||||
end
|
||||
local function addJobFromScheduler(jobKey, jobId, opts, waitKey, pausedKey, activeKey, metaKey,
|
||||
prioritizedKey, priorityCounter, delayedKey, markerKey, eventsKey, name, maxEvents, timestamp,
|
||||
data, jobSchedulerId, repeatDelay)
|
||||
opts['delay'] = repeatDelay
|
||||
opts['jobId'] = jobId
|
||||
storeAndEnqueueJob(eventsKey, jobKey, jobId, name, data, opts,
|
||||
timestamp, nil, nil, jobSchedulerId, maxEvents,
|
||||
waitKey, pausedKey, activeKey, metaKey, prioritizedKey,
|
||||
priorityCounter, delayedKey, markerKey)
|
||||
end
|
||||
--[[
|
||||
Function to get max events value or set by default 10000.
|
||||
]]
|
||||
local function getOrSetMaxEvents(metaKey)
|
||||
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
||||
if not maxEvents then
|
||||
maxEvents = 10000
|
||||
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
||||
end
|
||||
return maxEvents
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function isQueuePaused(queueMetaKey)
|
||||
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
||||
end
|
||||
--[[
|
||||
Function to remove job.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to remove deduplication key if needed
|
||||
when a job is being removed.
|
||||
]]
|
||||
local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
|
||||
jobId, deduplicationId)
|
||||
if deduplicationId then
|
||||
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
||||
local currentJobId = rcall('GET', deduplicationKey)
|
||||
if currentJobId and currentJobId == jobId then
|
||||
rcall("DEL", deduplicationKey)
|
||||
-- Also clean up any pending dedup-next data for this dedup ID
|
||||
rcall("DEL", prefixKey .. "dn:" .. deduplicationId)
|
||||
return 1
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to remove job keys.
|
||||
]]
|
||||
local function removeJobKeys(jobKey)
|
||||
return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
|
||||
jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
|
||||
end
|
||||
--[[
|
||||
Check if this job has a parent. If so we will just remove it from
|
||||
the parent child list, but if it is the last child we should move the parent to "wait/paused"
|
||||
which requires code from "moveToFinished"
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Functions to destructure job key.
|
||||
Just a bit of warning, these functions may be a bit slow and affect performance significantly.
|
||||
]]
|
||||
local getJobIdFromKey = function (jobKey)
|
||||
return string.match(jobKey, ".*:(.*)")
|
||||
end
|
||||
local getJobKeyPrefix = function (jobKey, jobId)
|
||||
return string.sub(jobKey, 0, #jobKey - #jobId)
|
||||
end
|
||||
local function _moveParentToWait(parentPrefix, parentId, emitEvent)
|
||||
local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
|
||||
parentPrefix .. "wait", parentPrefix .. "paused")
|
||||
addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
|
||||
if emitEvent then
|
||||
local parentEventStream = parentPrefix .. "events"
|
||||
rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
|
||||
end
|
||||
end
|
||||
local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
|
||||
if parentKey then
|
||||
local parentDependenciesKey = parentKey .. ":dependencies"
|
||||
local result = rcall("SREM", parentDependenciesKey, jobKey)
|
||||
if result > 0 then
|
||||
local pendingDependencies = rcall("SCARD", parentDependenciesKey)
|
||||
if pendingDependencies == 0 then
|
||||
local parentId = getJobIdFromKey(parentKey)
|
||||
local parentPrefix = getJobKeyPrefix(parentKey, parentId)
|
||||
local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
|
||||
if numRemovedElements == 1 then
|
||||
if hard then -- remove parent in same queue
|
||||
if parentPrefix == baseKey then
|
||||
removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
|
||||
removeJobKeys(parentKey)
|
||||
if debounceId then
|
||||
rcall("DEL", parentPrefix .. "de:" .. debounceId)
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId)
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
else
|
||||
local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
|
||||
local missedParentKey = parentAttributes[1]
|
||||
if( (type(missedParentKey) == "string") and missedParentKey ~= ""
|
||||
and (rcall("EXISTS", missedParentKey) == 1)) then
|
||||
local parentDependenciesKey = missedParentKey .. ":dependencies"
|
||||
local result = rcall("SREM", parentDependenciesKey, jobKey)
|
||||
if result > 0 then
|
||||
local pendingDependencies = rcall("SCARD", parentDependenciesKey)
|
||||
if pendingDependencies == 0 then
|
||||
local parentId = getJobIdFromKey(missedParentKey)
|
||||
local parentPrefix = getJobKeyPrefix(missedParentKey, parentId)
|
||||
local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
|
||||
if numRemovedElements == 1 then
|
||||
if hard then
|
||||
if parentPrefix == baseKey then
|
||||
removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
|
||||
removeJobKeys(missedParentKey)
|
||||
if parentAttributes[2] then
|
||||
rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId)
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
||||
local jobKey = baseKey .. jobId
|
||||
removeParentDependencyKey(jobKey, hard, nil, baseKey)
|
||||
if shouldRemoveDeduplicationKey then
|
||||
local deduplicationId = rcall("HGET", jobKey, "deid")
|
||||
removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobId, deduplicationId)
|
||||
end
|
||||
removeJobKeys(jobKey)
|
||||
end
|
||||
--[[
|
||||
Function to store a job scheduler
|
||||
]]
|
||||
local function storeJobScheduler(schedulerId, schedulerKey, repeatKey, nextMillis, opts,
|
||||
templateData, templateOpts)
|
||||
rcall("ZADD", repeatKey, nextMillis, schedulerId)
|
||||
local optionalValues = {}
|
||||
if opts['tz'] then
|
||||
table.insert(optionalValues, "tz")
|
||||
table.insert(optionalValues, opts['tz'])
|
||||
end
|
||||
if opts['limit'] then
|
||||
table.insert(optionalValues, "limit")
|
||||
table.insert(optionalValues, opts['limit'])
|
||||
end
|
||||
if opts['pattern'] then
|
||||
table.insert(optionalValues, "pattern")
|
||||
table.insert(optionalValues, opts['pattern'])
|
||||
end
|
||||
if opts['startDate'] then
|
||||
table.insert(optionalValues, "startDate")
|
||||
table.insert(optionalValues, opts['startDate'])
|
||||
end
|
||||
if opts['endDate'] then
|
||||
table.insert(optionalValues, "endDate")
|
||||
table.insert(optionalValues, opts['endDate'])
|
||||
end
|
||||
if opts['every'] then
|
||||
table.insert(optionalValues, "every")
|
||||
table.insert(optionalValues, opts['every'])
|
||||
end
|
||||
if opts['offset'] then
|
||||
table.insert(optionalValues, "offset")
|
||||
table.insert(optionalValues, opts['offset'])
|
||||
else
|
||||
local offset = rcall("HGET", schedulerKey, "offset")
|
||||
if offset then
|
||||
table.insert(optionalValues, "offset")
|
||||
table.insert(optionalValues, tonumber(offset))
|
||||
end
|
||||
end
|
||||
local jsonTemplateOpts = cjson.encode(templateOpts)
|
||||
if jsonTemplateOpts and jsonTemplateOpts ~= '{}' then
|
||||
table.insert(optionalValues, "opts")
|
||||
table.insert(optionalValues, jsonTemplateOpts)
|
||||
end
|
||||
if templateData and templateData ~= '{}' then
|
||||
table.insert(optionalValues, "data")
|
||||
table.insert(optionalValues, templateData)
|
||||
end
|
||||
table.insert(optionalValues, "ic")
|
||||
table.insert(optionalValues, rcall("HGET", schedulerKey, "ic") or 1)
|
||||
rcall("DEL", schedulerKey) -- remove all attributes and then re-insert new ones
|
||||
rcall("HMSET", schedulerKey, "name", opts['name'], unpack(optionalValues))
|
||||
end
|
||||
local function getJobSchedulerEveryNextMillis(prevMillis, every, now, offset, startDate)
|
||||
local nextMillis
|
||||
if not prevMillis then
|
||||
if startDate then
|
||||
-- Assuming startDate is passed as milliseconds from JavaScript
|
||||
nextMillis = tonumber(startDate)
|
||||
nextMillis = nextMillis > now and nextMillis or now
|
||||
else
|
||||
nextMillis = now
|
||||
end
|
||||
else
|
||||
nextMillis = prevMillis + every
|
||||
-- check if we may have missed some iterations
|
||||
if nextMillis < now then
|
||||
nextMillis = math.floor(now / every) * every + every + (offset or 0)
|
||||
end
|
||||
end
|
||||
if not offset or offset == 0 then
|
||||
local timeSlot = math.floor(nextMillis / every) * every;
|
||||
offset = nextMillis - timeSlot;
|
||||
end
|
||||
-- Return a tuple nextMillis, offset
|
||||
return math.floor(nextMillis), math.floor(offset)
|
||||
end
|
||||
-- If we are overriding a repeatable job we must delete the delayed job for
|
||||
-- the next iteration.
|
||||
local schedulerKey = repeatKey .. ":" .. jobSchedulerId
|
||||
local maxEvents = getOrSetMaxEvents(metaKey)
|
||||
local templateData = ARGV[4]
|
||||
local prevMillis = rcall("ZSCORE", repeatKey, jobSchedulerId)
|
||||
if prevMillis then
|
||||
prevMillis = tonumber(prevMillis)
|
||||
end
|
||||
local schedulerOpts = cmsgpack.unpack(ARGV[2])
|
||||
local every = schedulerOpts['every']
|
||||
-- For backwards compatibility we also check the offset from the job itself.
|
||||
-- could be removed in future major versions.
|
||||
local jobOffset = jobOpts['repeat'] and jobOpts['repeat']['offset'] or 0
|
||||
local offset = schedulerOpts['offset'] or jobOffset or 0
|
||||
local newOffset = offset
|
||||
local updatedEvery = false
|
||||
if every then
|
||||
-- if we changed the 'every' value we need to reset millis to nil
|
||||
local millis = prevMillis
|
||||
if prevMillis then
|
||||
local prevEvery = tonumber(rcall("HGET", schedulerKey, "every"))
|
||||
if prevEvery ~= every then
|
||||
millis = nil
|
||||
updatedEvery = true
|
||||
end
|
||||
end
|
||||
local startDate = schedulerOpts['startDate']
|
||||
nextMillis, newOffset = getJobSchedulerEveryNextMillis(millis, every, now, offset, startDate)
|
||||
end
|
||||
local function removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey, jobId, metaKey,
|
||||
eventsKey)
|
||||
if rcall("ZSCORE", delayedKey, jobId) then
|
||||
removeJob(jobId, true, prefixKey, true --[[remove debounce key]] )
|
||||
rcall("ZREM", delayedKey, jobId)
|
||||
return true
|
||||
elseif rcall("ZSCORE", prioritizedKey, jobId) then
|
||||
removeJob(jobId, true, prefixKey, true --[[remove debounce key]] )
|
||||
rcall("ZREM", prioritizedKey, jobId)
|
||||
return true
|
||||
else
|
||||
local pausedOrWaitKey = waitKey
|
||||
if isQueuePaused(metaKey) then
|
||||
pausedOrWaitKey = pausedKey
|
||||
end
|
||||
if rcall("LREM", pausedOrWaitKey, 1, jobId) > 0 then
|
||||
removeJob(jobId, true, prefixKey, true --[[remove debounce key]] )
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
local removedPrevJob = false
|
||||
if prevMillis then
|
||||
local currentJobId = "repeat:" .. jobSchedulerId .. ":" .. prevMillis
|
||||
local currentJobKey = schedulerKey .. ":" .. prevMillis
|
||||
-- In theory it should always exist the currentJobKey if there is a prevMillis unless something has
|
||||
-- gone really wrong.
|
||||
if rcall("EXISTS", currentJobKey) == 1 then
|
||||
removedPrevJob = removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey, currentJobId,
|
||||
metaKey, eventsKey)
|
||||
end
|
||||
end
|
||||
if removedPrevJob then
|
||||
-- The jobs has been removed and we want to replace it, so lets use the same millis.
|
||||
if every and not updatedEvery then
|
||||
nextMillis = prevMillis
|
||||
end
|
||||
else
|
||||
-- Special case where no job was removed, and we need to add the next iteration.
|
||||
schedulerOpts['offset'] = newOffset
|
||||
end
|
||||
-- Check for job ID collision with existing jobs (in any state)
|
||||
local jobId = "repeat:" .. jobSchedulerId .. ":" .. nextMillis
|
||||
local jobKey = prefixKey .. jobId
|
||||
-- If there's already a job with this ID, in a state
|
||||
-- that is not updatable (active, completed, failed) we must
|
||||
-- handle the collision
|
||||
local hasCollision = false
|
||||
if rcall("EXISTS", jobKey) == 1 then
|
||||
if every then
|
||||
-- For 'every' case: try next time slot to avoid collision
|
||||
local nextSlotMillis = nextMillis + every
|
||||
local nextSlotJobId = "repeat:" .. jobSchedulerId .. ":" .. nextSlotMillis
|
||||
local nextSlotJobKey = prefixKey .. nextSlotJobId
|
||||
if rcall("EXISTS", nextSlotJobKey) == 0 then
|
||||
-- Next slot is free, use it
|
||||
nextMillis = nextSlotMillis
|
||||
jobId = nextSlotJobId
|
||||
else
|
||||
-- Next slot also has a job, return error code
|
||||
return -11 -- SchedulerJobSlotsBusy
|
||||
end
|
||||
else
|
||||
hasCollision = true
|
||||
end
|
||||
end
|
||||
local delay = nextMillis - now
|
||||
-- Fast Clamp delay to minimum of 0
|
||||
if delay < 0 then
|
||||
delay = 0
|
||||
end
|
||||
local nextJobKey = schedulerKey .. ":" .. nextMillis
|
||||
if not hasCollision or removedPrevJob then
|
||||
-- jobId already calculated above during collision check
|
||||
storeJobScheduler(jobSchedulerId, schedulerKey, repeatKey, nextMillis, schedulerOpts, templateData, templateOpts)
|
||||
rcall("INCR", KEYS[8])
|
||||
addJobFromScheduler(nextJobKey, jobId, jobOpts, waitKey, pausedKey, KEYS[11], metaKey, prioritizedKey, KEYS[10],
|
||||
delayedKey, KEYS[7], eventsKey, schedulerOpts['name'], maxEvents, now, templateData, jobSchedulerId, delay)
|
||||
elseif hasCollision then
|
||||
-- For 'pattern' case: return error code
|
||||
return -10 -- SchedulerJobIdCollision
|
||||
end
|
||||
if ARGV[9] ~= "" then
|
||||
rcall("HSET", ARGV[9], "nrjid", jobId)
|
||||
end
|
||||
return {jobId .. "", delay}
|
||||
`;
|
||||
export const addJobScheduler = {
|
||||
name: 'addJobScheduler',
|
||||
content,
|
||||
keys: 11,
|
||||
};
|
||||
//# sourceMappingURL=addJobScheduler-11.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/addJobScheduler-11.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/addJobScheduler-11.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"addJobScheduler-11.js","sourceRoot":"","sources":["../../../src/scripts/addJobScheduler-11.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8jBf,CAAC;AACF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,iBAAiB;IACvB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/addLog-2.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/addLog-2.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const addLog: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
30
node_modules/bullmq/dist/esm/scripts/addLog-2.js
generated
vendored
Normal file
30
node_modules/bullmq/dist/esm/scripts/addLog-2.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
const content = `--[[
|
||||
Add job log
|
||||
Input:
|
||||
KEYS[1] job id key
|
||||
KEYS[2] job logs key
|
||||
ARGV[1] id
|
||||
ARGV[2] log
|
||||
ARGV[3] keepLogs
|
||||
Output:
|
||||
-1 - Missing job.
|
||||
]]
|
||||
local rcall = redis.call
|
||||
if rcall("EXISTS", KEYS[1]) == 1 then -- // Make sure job exists
|
||||
local logCount = rcall("RPUSH", KEYS[2], ARGV[2])
|
||||
if ARGV[3] ~= '' then
|
||||
local keepLogs = tonumber(ARGV[3])
|
||||
rcall("LTRIM", KEYS[2], -keepLogs, -1)
|
||||
return math.min(keepLogs, logCount)
|
||||
end
|
||||
return logCount
|
||||
else
|
||||
return -1
|
||||
end
|
||||
`;
|
||||
export const addLog = {
|
||||
name: 'addLog',
|
||||
content,
|
||||
keys: 2,
|
||||
};
|
||||
//# sourceMappingURL=addLog-2.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/addLog-2.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/addLog-2.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"addLog-2.js","sourceRoot":"","sources":["../../../src/scripts/addLog-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;CAuBf,CAAC;AACF,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/addParentJob-6.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/addParentJob-6.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const addParentJob: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
472
node_modules/bullmq/dist/esm/scripts/addParentJob-6.js
generated
vendored
Normal file
472
node_modules/bullmq/dist/esm/scripts/addParentJob-6.js
generated
vendored
Normal file
@@ -0,0 +1,472 @@
|
||||
const content = `--[[
|
||||
Adds a parent job to the queue by doing the following:
|
||||
- Increases the job counter if needed.
|
||||
- Creates a new job key with the job data.
|
||||
- adds the job to the waiting-children zset
|
||||
Input:
|
||||
KEYS[1] 'meta'
|
||||
KEYS[2] 'id'
|
||||
KEYS[3] 'delayed'
|
||||
KEYS[4] 'waiting-children'
|
||||
KEYS[5] 'completed'
|
||||
KEYS[6] events stream key
|
||||
ARGV[1] msgpacked arguments array
|
||||
[1] key prefix,
|
||||
[2] custom id (will not generate one automatically)
|
||||
[3] name
|
||||
[4] timestamp
|
||||
[5] parentKey?
|
||||
[6] parent dependencies key.
|
||||
[7] parent? {id, queueKey}
|
||||
[8] repeat job key
|
||||
[9] deduplication key
|
||||
ARGV[2] Json stringified job data
|
||||
ARGV[3] msgpacked options
|
||||
Output:
|
||||
jobId - OK
|
||||
-5 - Missing parent key
|
||||
]]
|
||||
local metaKey = KEYS[1]
|
||||
local idKey = KEYS[2]
|
||||
local delayedKey = KEYS[3]
|
||||
local completedKey = KEYS[5]
|
||||
local eventsKey = KEYS[6]
|
||||
local jobId
|
||||
local jobIdKey
|
||||
local rcall = redis.call
|
||||
local args = cmsgpack.unpack(ARGV[1])
|
||||
local data = ARGV[2]
|
||||
local opts = cmsgpack.unpack(ARGV[3])
|
||||
local parentKey = args[5]
|
||||
local parent = args[7]
|
||||
local repeatJobKey = args[8]
|
||||
local deduplicationKey = args[9]
|
||||
local parentData
|
||||
-- Includes
|
||||
--[[
|
||||
Function to deduplicate a job.
|
||||
]]
|
||||
--[[
|
||||
Function to set the deduplication key for a job.
|
||||
Uses TTL from deduplication opts if provided.
|
||||
]]
|
||||
local function setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
local ttl = deduplicationOpts and deduplicationOpts['ttl']
|
||||
if ttl and ttl > 0 then
|
||||
rcall('SET', deduplicationKey, jobId, 'PX', ttl)
|
||||
else
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to store a deduplicated next job if the existing job is active
|
||||
and keepLastIfActive is set. When the active job finishes, the stored
|
||||
proto-job is used to create a real job in the queue.
|
||||
Returns true if the proto-job was stored, false otherwise.
|
||||
]]
|
||||
--[[
|
||||
Function to check if an item belongs to a list.
|
||||
]]
|
||||
local function checkItemInList(list, item)
|
||||
for _, v in pairs(list) do
|
||||
if v == item then
|
||||
return 1
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
local function storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
if deduplicationOpts['keepLastIfActive'] and currentDebounceJobId then
|
||||
local activeKey = prefix .. "active"
|
||||
local activeItems = rcall('LRANGE', activeKey, 0, -1)
|
||||
if checkItemInList(activeItems, currentDebounceJobId) then
|
||||
local deduplicationNextKey = prefix .. "dn:" .. deduplicationId
|
||||
local fields = {'name', jobName, 'data', jobData, 'opts', cjson.encode(fullOpts)}
|
||||
if parentKey then
|
||||
fields[#fields+1] = 'pk'
|
||||
fields[#fields+1] = parentKey
|
||||
end
|
||||
if parentData then
|
||||
fields[#fields+1] = 'pd'
|
||||
fields[#fields+1] = parentData
|
||||
end
|
||||
if parentDependenciesKey then
|
||||
fields[#fields+1] = 'pdk'
|
||||
fields[#fields+1] = parentDependenciesKey
|
||||
end
|
||||
if repeatJobKey then
|
||||
fields[#fields+1] = 'rjk'
|
||||
fields[#fields+1] = repeatJobKey
|
||||
end
|
||||
rcall('HSET', deduplicationNextKey, unpack(fields))
|
||||
-- Ensure the dedup key does not expire while the job is active,
|
||||
-- so subsequent adds always hit the dedup path and never bypass
|
||||
-- the active-check because of a TTL expiry.
|
||||
local deduplicationKey = prefix .. "de:" .. deduplicationId
|
||||
rcall('PERSIST', deduplicationKey)
|
||||
-- TODO remove debounced event in next breaking change
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced", "jobId",
|
||||
currentDebounceJobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
currentDebounceJobId, "deduplicationId", deduplicationId, "deduplicatedJobId", jobId)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function deduplicateJobWithoutReplace(deduplicationId, deduplicationOpts, jobId, deduplicationKey,
|
||||
eventsKey, maxEvents, prefix, jobName, jobData, fullOpts,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
local ttl = deduplicationOpts['ttl']
|
||||
local deduplicationKeyExists
|
||||
if ttl and ttl > 0 then
|
||||
if deduplicationOpts['extend'] then
|
||||
local currentDebounceJobId = rcall('GET', deduplicationKey)
|
||||
if currentDebounceJobId then
|
||||
if storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey) then
|
||||
return currentDebounceJobId
|
||||
end
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, currentDebounceJobId)
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, currentDebounceJobId, deduplicationOpts)
|
||||
end
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced",
|
||||
"jobId", currentDebounceJobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
currentDebounceJobId, "deduplicationId", deduplicationId, "deduplicatedJobId", jobId)
|
||||
return currentDebounceJobId
|
||||
else
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
end
|
||||
return
|
||||
end
|
||||
else
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'NX')
|
||||
else
|
||||
deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'PX', ttl, 'NX')
|
||||
end
|
||||
end
|
||||
else
|
||||
deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'NX')
|
||||
end
|
||||
if deduplicationKeyExists then
|
||||
local currentDebounceJobId = rcall('GET', deduplicationKey)
|
||||
if storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey) then
|
||||
return currentDebounceJobId
|
||||
end
|
||||
-- TODO remove debounced event in next breaking change
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced", "jobId",
|
||||
currentDebounceJobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
currentDebounceJobId, "deduplicationId", deduplicationId, "deduplicatedJobId", jobId)
|
||||
return currentDebounceJobId
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to get max events value or set by default 10000.
|
||||
]]
|
||||
local function getOrSetMaxEvents(metaKey)
|
||||
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
||||
if not maxEvents then
|
||||
maxEvents = 10000
|
||||
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
||||
end
|
||||
return maxEvents
|
||||
end
|
||||
--[[
|
||||
Function to handle the case when job is duplicated.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
This function is used to update the parent's dependencies if the job
|
||||
is already completed and about to be ignored. The parent must get its
|
||||
dependencies updated to avoid the parent job being stuck forever in
|
||||
the waiting-children state.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Validate and move or add dependencies to parent.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Validate and move parent to a wait status (waiting, delayed or prioritized)
|
||||
if no pending dependencies.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Move parent to a wait status (wait, prioritized or delayed)
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add delay marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to return the next delayed job timestamp.
|
||||
]]
|
||||
local function getNextDelayedTimestamp(delayedKey)
|
||||
local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
|
||||
if #result then
|
||||
local nextTimestamp = tonumber(result[2])
|
||||
if nextTimestamp ~= nil then
|
||||
return nextTimestamp / 0x1000
|
||||
end
|
||||
end
|
||||
end
|
||||
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
||||
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
||||
if nextTimestamp ~= nil then
|
||||
-- Replace the score of the marker with the newest known
|
||||
-- next timestamp.
|
||||
rcall("ZADD", markerKey, nextTimestamp, "1")
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to add job in target list and add marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall(pushCmd, targetKey, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to add job considering priority.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to get priority score.
|
||||
]]
|
||||
local function getPriorityScore(priority, priorityCounterKey)
|
||||
local prioCounter = rcall("INCR", priorityCounterKey)
|
||||
return priority * 0x100000000 + prioCounter % 0x100000000
|
||||
end
|
||||
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
|
||||
isPausedOrMaxed)
|
||||
local score = getPriorityScore(priority, priorityCounterKey)
|
||||
rcall("ZADD", prioritizedKey, score, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to check if queue is paused or maxed
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
|
||||
if queueAttributes[1] then
|
||||
return true
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
return activeCount >= tonumber(queueAttributes[2])
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
||||
local parentWaitKey = parentQueueKey .. ":wait"
|
||||
local parentPausedKey = parentQueueKey .. ":paused"
|
||||
local parentActiveKey = parentQueueKey .. ":active"
|
||||
local parentMetaKey = parentQueueKey .. ":meta"
|
||||
local parentMarkerKey = parentQueueKey .. ":marker"
|
||||
local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
|
||||
local priority = tonumber(jobAttributes[1]) or 0
|
||||
local delay = tonumber(jobAttributes[2]) or 0
|
||||
if delay > 0 then
|
||||
local delayedTimestamp = tonumber(timestamp) + delay
|
||||
local score = delayedTimestamp * 0x1000
|
||||
local parentDelayedKey = parentQueueKey .. ":delayed"
|
||||
rcall("ZADD", parentDelayedKey, score, parentId)
|
||||
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
|
||||
delayedTimestamp)
|
||||
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
||||
else
|
||||
if priority == 0 then
|
||||
local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
|
||||
parentWaitKey, parentPausedKey)
|
||||
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
||||
else
|
||||
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
||||
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
||||
parentQueueKey .. ":pc", isPausedOrMaxed)
|
||||
end
|
||||
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
||||
"waiting-children")
|
||||
end
|
||||
end
|
||||
local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
||||
if rcall("EXISTS", parentKey) == 1 then
|
||||
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
||||
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
||||
rcall("ZREM", parentWaitingChildrenKey, parentId)
|
||||
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
|
||||
parentId, timestamp)
|
||||
local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
|
||||
if doNotHavePendingDependencies then
|
||||
moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
||||
end
|
||||
end
|
||||
local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
|
||||
parentId, jobIdKey, returnvalue, timestamp )
|
||||
local processedSet = parentKey .. ":processed"
|
||||
rcall("HSET", processedSet, jobIdKey, returnvalue)
|
||||
moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
|
||||
end
|
||||
local function updateExistingJobsParent(parentKey, parent, parentData,
|
||||
parentDependenciesKey, completedKey,
|
||||
jobIdKey, jobId, timestamp)
|
||||
if parentKey ~= nil then
|
||||
if rcall("ZSCORE", completedKey, jobId) then
|
||||
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
||||
updateParentDepsIfNeeded(parentKey, parent['queueKey'],
|
||||
parentDependenciesKey, parent['id'],
|
||||
jobIdKey, returnvalue, timestamp)
|
||||
else
|
||||
if parentDependenciesKey ~= nil then
|
||||
rcall("SADD", parentDependenciesKey, jobIdKey)
|
||||
end
|
||||
end
|
||||
rcall("HMSET", jobIdKey, "parentKey", parentKey, "parent", parentData)
|
||||
end
|
||||
end
|
||||
local function handleDuplicatedJob(jobKey, jobId, currentParentKey, currentParent,
|
||||
parentData, parentDependenciesKey, completedKey, eventsKey, maxEvents, timestamp)
|
||||
local existedParentKey = rcall("HGET", jobKey, "parentKey")
|
||||
if not existedParentKey or existedParentKey == currentParentKey then
|
||||
updateExistingJobsParent(currentParentKey, currentParent, parentData,
|
||||
parentDependenciesKey, completedKey, jobKey,
|
||||
jobId, timestamp)
|
||||
else
|
||||
if currentParentKey ~= nil and currentParentKey ~= existedParentKey
|
||||
and (rcall("EXISTS", existedParentKey) == 1) then
|
||||
return -7
|
||||
end
|
||||
end
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
|
||||
"duplicated", "jobId", jobId)
|
||||
return jobId .. "" -- convert to string
|
||||
end
|
||||
--[[
|
||||
Function to store a job
|
||||
]]
|
||||
local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
|
||||
parentKey, parentData, repeatJobKey)
|
||||
local jsonOpts = cjson.encode(opts)
|
||||
local delay = opts['delay'] or 0
|
||||
local priority = opts['priority'] or 0
|
||||
local debounceId = opts['de'] and opts['de']['id']
|
||||
local optionalValues = {}
|
||||
if parentKey ~= nil then
|
||||
table.insert(optionalValues, "parentKey")
|
||||
table.insert(optionalValues, parentKey)
|
||||
table.insert(optionalValues, "parent")
|
||||
table.insert(optionalValues, parentData)
|
||||
end
|
||||
if repeatJobKey then
|
||||
table.insert(optionalValues, "rjk")
|
||||
table.insert(optionalValues, repeatJobKey)
|
||||
end
|
||||
if debounceId then
|
||||
table.insert(optionalValues, "deid")
|
||||
table.insert(optionalValues, debounceId)
|
||||
end
|
||||
rcall("HMSET", jobIdKey, "name", name, "data", data, "opts", jsonOpts,
|
||||
"timestamp", timestamp, "delay", delay, "priority", priority,
|
||||
unpack(optionalValues))
|
||||
rcall("XADD", eventsKey, "*", "event", "added", "jobId", jobId, "name", name)
|
||||
return delay, priority
|
||||
end
|
||||
if parentKey ~= nil then
|
||||
if rcall("EXISTS", parentKey) ~= 1 then return -5 end
|
||||
parentData = cjson.encode(parent)
|
||||
end
|
||||
local jobCounter = rcall("INCR", idKey)
|
||||
local maxEvents = getOrSetMaxEvents(metaKey)
|
||||
local parentDependenciesKey = args[6]
|
||||
local timestamp = args[4]
|
||||
if args[2] == "" then
|
||||
jobId = jobCounter
|
||||
jobIdKey = args[1] .. jobId
|
||||
else
|
||||
jobId = args[2]
|
||||
jobIdKey = args[1] .. jobId
|
||||
if rcall("EXISTS", jobIdKey) == 1 then
|
||||
return handleDuplicatedJob(jobIdKey, jobId, parentKey, parent,
|
||||
parentData, parentDependenciesKey, completedKey, eventsKey,
|
||||
maxEvents, timestamp)
|
||||
end
|
||||
end
|
||||
local deduplicationId = opts['de'] and opts['de']['id']
|
||||
if deduplicationId then
|
||||
local deduplicationJobId = deduplicateJobWithoutReplace(deduplicationId, opts['de'],
|
||||
jobId, deduplicationKey, eventsKey, maxEvents, args[1], args[3], ARGV[2], opts,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
if deduplicationJobId then
|
||||
return deduplicationJobId
|
||||
end
|
||||
end
|
||||
-- Store the job.
|
||||
storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2], opts, timestamp,
|
||||
parentKey, parentData, repeatJobKey)
|
||||
local waitChildrenKey = KEYS[4]
|
||||
rcall("ZADD", waitChildrenKey, timestamp, jobId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
|
||||
"waiting-children", "jobId", jobId)
|
||||
-- Check if this job is a child of another job, if so add it to the parents dependencies
|
||||
if parentDependenciesKey ~= nil then
|
||||
rcall("SADD", parentDependenciesKey, jobIdKey)
|
||||
end
|
||||
return jobId .. "" -- convert to string
|
||||
`;
|
||||
export const addParentJob = {
|
||||
name: 'addParentJob',
|
||||
content,
|
||||
keys: 6,
|
||||
};
|
||||
//# sourceMappingURL=addParentJob-6.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/addParentJob-6.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/addParentJob-6.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"addParentJob-6.js","sourceRoot":"","sources":["../../../src/scripts/addParentJob-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAidf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/addPrioritizedJob-9.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/addPrioritizedJob-9.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const addPrioritizedJob: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
545
node_modules/bullmq/dist/esm/scripts/addPrioritizedJob-9.js
generated
vendored
Normal file
545
node_modules/bullmq/dist/esm/scripts/addPrioritizedJob-9.js
generated
vendored
Normal file
@@ -0,0 +1,545 @@
|
||||
const content = `--[[
|
||||
Adds a priotitized job to the queue by doing the following:
|
||||
- Increases the job counter if needed.
|
||||
- Creates a new job key with the job data.
|
||||
- Adds the job to the "added" list so that workers gets notified.
|
||||
Input:
|
||||
KEYS[1] 'marker',
|
||||
KEYS[2] 'meta'
|
||||
KEYS[3] 'id'
|
||||
KEYS[4] 'prioritized'
|
||||
KEYS[5] 'delayed'
|
||||
KEYS[6] 'completed'
|
||||
KEYS[7] 'active'
|
||||
KEYS[8] events stream key
|
||||
KEYS[9] 'pc' priority counter
|
||||
ARGV[1] msgpacked arguments array
|
||||
[1] key prefix,
|
||||
[2] custom id (will not generate one automatically)
|
||||
[3] name
|
||||
[4] timestamp
|
||||
[5] parentKey?
|
||||
[6] parent dependencies key.
|
||||
[7] parent? {id, queueKey}
|
||||
[8] repeat job key
|
||||
[9] deduplication key
|
||||
ARGV[2] Json stringified job data
|
||||
ARGV[3] msgpacked options
|
||||
Output:
|
||||
jobId - OK
|
||||
-5 - Missing parent key
|
||||
]]
|
||||
local metaKey = KEYS[2]
|
||||
local idKey = KEYS[3]
|
||||
local priorityKey = KEYS[4]
|
||||
local completedKey = KEYS[6]
|
||||
local activeKey = KEYS[7]
|
||||
local eventsKey = KEYS[8]
|
||||
local priorityCounterKey = KEYS[9]
|
||||
local jobId
|
||||
local jobIdKey
|
||||
local rcall = redis.call
|
||||
local args = cmsgpack.unpack(ARGV[1])
|
||||
local data = ARGV[2]
|
||||
local opts = cmsgpack.unpack(ARGV[3])
|
||||
local parentKey = args[5]
|
||||
local parent = args[7]
|
||||
local repeatJobKey = args[8]
|
||||
local deduplicationKey = args[9]
|
||||
local parentData
|
||||
-- Includes
|
||||
--[[
|
||||
Function to add job considering priority.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to get priority score.
|
||||
]]
|
||||
local function getPriorityScore(priority, priorityCounterKey)
|
||||
local prioCounter = rcall("INCR", priorityCounterKey)
|
||||
return priority * 0x100000000 + prioCounter % 0x100000000
|
||||
end
|
||||
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
|
||||
isPausedOrMaxed)
|
||||
local score = getPriorityScore(priority, priorityCounterKey)
|
||||
rcall("ZADD", prioritizedKey, score, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to debounce a job.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to deduplicate a job.
|
||||
]]
|
||||
--[[
|
||||
Function to set the deduplication key for a job.
|
||||
Uses TTL from deduplication opts if provided.
|
||||
]]
|
||||
local function setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
local ttl = deduplicationOpts and deduplicationOpts['ttl']
|
||||
if ttl and ttl > 0 then
|
||||
rcall('SET', deduplicationKey, jobId, 'PX', ttl)
|
||||
else
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to store a deduplicated next job if the existing job is active
|
||||
and keepLastIfActive is set. When the active job finishes, the stored
|
||||
proto-job is used to create a real job in the queue.
|
||||
Returns true if the proto-job was stored, false otherwise.
|
||||
]]
|
||||
--[[
|
||||
Function to check if an item belongs to a list.
|
||||
]]
|
||||
local function checkItemInList(list, item)
|
||||
for _, v in pairs(list) do
|
||||
if v == item then
|
||||
return 1
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
local function storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
if deduplicationOpts['keepLastIfActive'] and currentDebounceJobId then
|
||||
local activeKey = prefix .. "active"
|
||||
local activeItems = rcall('LRANGE', activeKey, 0, -1)
|
||||
if checkItemInList(activeItems, currentDebounceJobId) then
|
||||
local deduplicationNextKey = prefix .. "dn:" .. deduplicationId
|
||||
local fields = {'name', jobName, 'data', jobData, 'opts', cjson.encode(fullOpts)}
|
||||
if parentKey then
|
||||
fields[#fields+1] = 'pk'
|
||||
fields[#fields+1] = parentKey
|
||||
end
|
||||
if parentData then
|
||||
fields[#fields+1] = 'pd'
|
||||
fields[#fields+1] = parentData
|
||||
end
|
||||
if parentDependenciesKey then
|
||||
fields[#fields+1] = 'pdk'
|
||||
fields[#fields+1] = parentDependenciesKey
|
||||
end
|
||||
if repeatJobKey then
|
||||
fields[#fields+1] = 'rjk'
|
||||
fields[#fields+1] = repeatJobKey
|
||||
end
|
||||
rcall('HSET', deduplicationNextKey, unpack(fields))
|
||||
-- Ensure the dedup key does not expire while the job is active,
|
||||
-- so subsequent adds always hit the dedup path and never bypass
|
||||
-- the active-check because of a TTL expiry.
|
||||
local deduplicationKey = prefix .. "de:" .. deduplicationId
|
||||
rcall('PERSIST', deduplicationKey)
|
||||
-- TODO remove debounced event in next breaking change
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced", "jobId",
|
||||
currentDebounceJobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
currentDebounceJobId, "deduplicationId", deduplicationId, "deduplicatedJobId", jobId)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function deduplicateJobWithoutReplace(deduplicationId, deduplicationOpts, jobId, deduplicationKey,
|
||||
eventsKey, maxEvents, prefix, jobName, jobData, fullOpts,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
local ttl = deduplicationOpts['ttl']
|
||||
local deduplicationKeyExists
|
||||
if ttl and ttl > 0 then
|
||||
if deduplicationOpts['extend'] then
|
||||
local currentDebounceJobId = rcall('GET', deduplicationKey)
|
||||
if currentDebounceJobId then
|
||||
if storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey) then
|
||||
return currentDebounceJobId
|
||||
end
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, currentDebounceJobId)
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, currentDebounceJobId, deduplicationOpts)
|
||||
end
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced",
|
||||
"jobId", currentDebounceJobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
currentDebounceJobId, "deduplicationId", deduplicationId, "deduplicatedJobId", jobId)
|
||||
return currentDebounceJobId
|
||||
else
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
end
|
||||
return
|
||||
end
|
||||
else
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'NX')
|
||||
else
|
||||
deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'PX', ttl, 'NX')
|
||||
end
|
||||
end
|
||||
else
|
||||
deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'NX')
|
||||
end
|
||||
if deduplicationKeyExists then
|
||||
local currentDebounceJobId = rcall('GET', deduplicationKey)
|
||||
if storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey) then
|
||||
return currentDebounceJobId
|
||||
end
|
||||
-- TODO remove debounced event in next breaking change
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced", "jobId",
|
||||
currentDebounceJobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
currentDebounceJobId, "deduplicationId", deduplicationId, "deduplicatedJobId", jobId)
|
||||
return currentDebounceJobId
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to remove job keys.
|
||||
]]
|
||||
local function removeJobKeys(jobKey)
|
||||
return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
|
||||
jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
|
||||
end
|
||||
local function removeDelayedJob(delayedKey, deduplicationKey, eventsKey, maxEvents, currentDeduplicatedJobId,
|
||||
jobId, deduplicationId, prefix)
|
||||
if rcall("ZREM", delayedKey, currentDeduplicatedJobId) > 0 then
|
||||
removeJobKeys(prefix .. currentDeduplicatedJobId)
|
||||
rcall("XADD", eventsKey, "*", "event", "removed", "jobId", currentDeduplicatedJobId,
|
||||
"prev", "delayed")
|
||||
-- TODO remove debounced event in next breaking change
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced", "jobId",
|
||||
jobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
jobId, "deduplicationId", deduplicationId, "deduplicatedJobId", currentDeduplicatedJobId)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function deduplicateJob(deduplicationOpts, jobId, delayedKey, deduplicationKey, eventsKey, maxEvents,
|
||||
prefix, jobName, jobData, fullOpts, parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
local deduplicationId = deduplicationOpts and deduplicationOpts['id']
|
||||
if deduplicationId then
|
||||
if deduplicationOpts['replace'] then
|
||||
local currentDebounceJobId = rcall('GET', deduplicationKey)
|
||||
if currentDebounceJobId then
|
||||
local isRemoved = removeDelayedJob(delayedKey, deduplicationKey, eventsKey, maxEvents,
|
||||
currentDebounceJobId, jobId, deduplicationId, prefix)
|
||||
if isRemoved then
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
else
|
||||
local ttl = deduplicationOpts['ttl']
|
||||
if not deduplicationOpts['extend'] and ttl and ttl > 0 then
|
||||
rcall('SET', deduplicationKey, jobId, 'KEEPTTL')
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
end
|
||||
end
|
||||
return
|
||||
else
|
||||
storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
return currentDebounceJobId
|
||||
end
|
||||
else
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
end
|
||||
return
|
||||
end
|
||||
else
|
||||
return deduplicateJobWithoutReplace(deduplicationId, deduplicationOpts,
|
||||
jobId, deduplicationKey, eventsKey, maxEvents, prefix, jobName, jobData, fullOpts,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to store a job
|
||||
]]
|
||||
local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
|
||||
parentKey, parentData, repeatJobKey)
|
||||
local jsonOpts = cjson.encode(opts)
|
||||
local delay = opts['delay'] or 0
|
||||
local priority = opts['priority'] or 0
|
||||
local debounceId = opts['de'] and opts['de']['id']
|
||||
local optionalValues = {}
|
||||
if parentKey ~= nil then
|
||||
table.insert(optionalValues, "parentKey")
|
||||
table.insert(optionalValues, parentKey)
|
||||
table.insert(optionalValues, "parent")
|
||||
table.insert(optionalValues, parentData)
|
||||
end
|
||||
if repeatJobKey then
|
||||
table.insert(optionalValues, "rjk")
|
||||
table.insert(optionalValues, repeatJobKey)
|
||||
end
|
||||
if debounceId then
|
||||
table.insert(optionalValues, "deid")
|
||||
table.insert(optionalValues, debounceId)
|
||||
end
|
||||
rcall("HMSET", jobIdKey, "name", name, "data", data, "opts", jsonOpts,
|
||||
"timestamp", timestamp, "delay", delay, "priority", priority,
|
||||
unpack(optionalValues))
|
||||
rcall("XADD", eventsKey, "*", "event", "added", "jobId", jobId, "name", name)
|
||||
return delay, priority
|
||||
end
|
||||
--[[
|
||||
Function to get max events value or set by default 10000.
|
||||
]]
|
||||
local function getOrSetMaxEvents(metaKey)
|
||||
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
||||
if not maxEvents then
|
||||
maxEvents = 10000
|
||||
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
||||
end
|
||||
return maxEvents
|
||||
end
|
||||
--[[
|
||||
Function to handle the case when job is duplicated.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
This function is used to update the parent's dependencies if the job
|
||||
is already completed and about to be ignored. The parent must get its
|
||||
dependencies updated to avoid the parent job being stuck forever in
|
||||
the waiting-children state.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Validate and move or add dependencies to parent.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Validate and move parent to a wait status (waiting, delayed or prioritized)
|
||||
if no pending dependencies.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Move parent to a wait status (wait, prioritized or delayed)
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add delay marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to return the next delayed job timestamp.
|
||||
]]
|
||||
local function getNextDelayedTimestamp(delayedKey)
|
||||
local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
|
||||
if #result then
|
||||
local nextTimestamp = tonumber(result[2])
|
||||
if nextTimestamp ~= nil then
|
||||
return nextTimestamp / 0x1000
|
||||
end
|
||||
end
|
||||
end
|
||||
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
||||
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
||||
if nextTimestamp ~= nil then
|
||||
-- Replace the score of the marker with the newest known
|
||||
-- next timestamp.
|
||||
rcall("ZADD", markerKey, nextTimestamp, "1")
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to add job in target list and add marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall(pushCmd, targetKey, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to check if queue is paused or maxed
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
|
||||
if queueAttributes[1] then
|
||||
return true
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
return activeCount >= tonumber(queueAttributes[2])
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
||||
local parentWaitKey = parentQueueKey .. ":wait"
|
||||
local parentPausedKey = parentQueueKey .. ":paused"
|
||||
local parentActiveKey = parentQueueKey .. ":active"
|
||||
local parentMetaKey = parentQueueKey .. ":meta"
|
||||
local parentMarkerKey = parentQueueKey .. ":marker"
|
||||
local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
|
||||
local priority = tonumber(jobAttributes[1]) or 0
|
||||
local delay = tonumber(jobAttributes[2]) or 0
|
||||
if delay > 0 then
|
||||
local delayedTimestamp = tonumber(timestamp) + delay
|
||||
local score = delayedTimestamp * 0x1000
|
||||
local parentDelayedKey = parentQueueKey .. ":delayed"
|
||||
rcall("ZADD", parentDelayedKey, score, parentId)
|
||||
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
|
||||
delayedTimestamp)
|
||||
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
||||
else
|
||||
if priority == 0 then
|
||||
local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
|
||||
parentWaitKey, parentPausedKey)
|
||||
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
||||
else
|
||||
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
||||
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
||||
parentQueueKey .. ":pc", isPausedOrMaxed)
|
||||
end
|
||||
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
||||
"waiting-children")
|
||||
end
|
||||
end
|
||||
local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
||||
if rcall("EXISTS", parentKey) == 1 then
|
||||
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
||||
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
||||
rcall("ZREM", parentWaitingChildrenKey, parentId)
|
||||
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
|
||||
parentId, timestamp)
|
||||
local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
|
||||
if doNotHavePendingDependencies then
|
||||
moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
||||
end
|
||||
end
|
||||
local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
|
||||
parentId, jobIdKey, returnvalue, timestamp )
|
||||
local processedSet = parentKey .. ":processed"
|
||||
rcall("HSET", processedSet, jobIdKey, returnvalue)
|
||||
moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
|
||||
end
|
||||
local function updateExistingJobsParent(parentKey, parent, parentData,
|
||||
parentDependenciesKey, completedKey,
|
||||
jobIdKey, jobId, timestamp)
|
||||
if parentKey ~= nil then
|
||||
if rcall("ZSCORE", completedKey, jobId) then
|
||||
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
||||
updateParentDepsIfNeeded(parentKey, parent['queueKey'],
|
||||
parentDependenciesKey, parent['id'],
|
||||
jobIdKey, returnvalue, timestamp)
|
||||
else
|
||||
if parentDependenciesKey ~= nil then
|
||||
rcall("SADD", parentDependenciesKey, jobIdKey)
|
||||
end
|
||||
end
|
||||
rcall("HMSET", jobIdKey, "parentKey", parentKey, "parent", parentData)
|
||||
end
|
||||
end
|
||||
local function handleDuplicatedJob(jobKey, jobId, currentParentKey, currentParent,
|
||||
parentData, parentDependenciesKey, completedKey, eventsKey, maxEvents, timestamp)
|
||||
local existedParentKey = rcall("HGET", jobKey, "parentKey")
|
||||
if not existedParentKey or existedParentKey == currentParentKey then
|
||||
updateExistingJobsParent(currentParentKey, currentParent, parentData,
|
||||
parentDependenciesKey, completedKey, jobKey,
|
||||
jobId, timestamp)
|
||||
else
|
||||
if currentParentKey ~= nil and currentParentKey ~= existedParentKey
|
||||
and (rcall("EXISTS", existedParentKey) == 1) then
|
||||
return -7
|
||||
end
|
||||
end
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
|
||||
"duplicated", "jobId", jobId)
|
||||
return jobId .. "" -- convert to string
|
||||
end
|
||||
if parentKey ~= nil then
|
||||
if rcall("EXISTS", parentKey) ~= 1 then return -5 end
|
||||
parentData = cjson.encode(parent)
|
||||
end
|
||||
local jobCounter = rcall("INCR", idKey)
|
||||
local maxEvents = getOrSetMaxEvents(metaKey)
|
||||
local parentDependenciesKey = args[6]
|
||||
local timestamp = args[4]
|
||||
if args[2] == "" then
|
||||
jobId = jobCounter
|
||||
jobIdKey = args[1] .. jobId
|
||||
else
|
||||
jobId = args[2]
|
||||
jobIdKey = args[1] .. jobId
|
||||
if rcall("EXISTS", jobIdKey) == 1 then
|
||||
return handleDuplicatedJob(jobIdKey, jobId, parentKey, parent,
|
||||
parentData, parentDependenciesKey, completedKey, eventsKey,
|
||||
maxEvents, timestamp)
|
||||
end
|
||||
end
|
||||
local deduplicationJobId = deduplicateJob(opts['de'], jobId, KEYS[5],
|
||||
deduplicationKey, eventsKey, maxEvents, args[1], args[3], ARGV[2], opts,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
if deduplicationJobId then
|
||||
return deduplicationJobId
|
||||
end
|
||||
-- Store the job.
|
||||
local delay, priority = storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2],
|
||||
opts, timestamp, parentKey, parentData,
|
||||
repeatJobKey)
|
||||
-- Add the job to the prioritized set
|
||||
local isPausedOrMaxed = isQueuePausedOrMaxed(metaKey, activeKey)
|
||||
addJobWithPriority( KEYS[1], priorityKey, priority, jobId, priorityCounterKey, isPausedOrMaxed)
|
||||
-- Emit waiting event
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
|
||||
"jobId", jobId)
|
||||
-- Check if this job is a child of another job, if so add it to the parents dependencies
|
||||
if parentDependenciesKey ~= nil then
|
||||
rcall("SADD", parentDependenciesKey, jobIdKey)
|
||||
end
|
||||
return jobId .. "" -- convert to string
|
||||
`;
|
||||
export const addPrioritizedJob = {
|
||||
name: 'addPrioritizedJob',
|
||||
content,
|
||||
keys: 9,
|
||||
};
|
||||
//# sourceMappingURL=addPrioritizedJob-9.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/addPrioritizedJob-9.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/addPrioritizedJob-9.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"addPrioritizedJob-9.js","sourceRoot":"","sources":["../../../src/scripts/addPrioritizedJob-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0hBf,CAAC;AACF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,mBAAmB;IACzB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/addRepeatableJob-2.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/addRepeatableJob-2.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const addRepeatableJob: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
235
node_modules/bullmq/dist/esm/scripts/addRepeatableJob-2.js
generated
vendored
Normal file
235
node_modules/bullmq/dist/esm/scripts/addRepeatableJob-2.js
generated
vendored
Normal file
@@ -0,0 +1,235 @@
|
||||
const content = `--[[
|
||||
Adds a repeatable job
|
||||
Input:
|
||||
KEYS[1] 'repeat' key
|
||||
KEYS[2] 'delayed' key
|
||||
ARGV[1] next milliseconds
|
||||
ARGV[2] msgpacked options
|
||||
[1] name
|
||||
[2] tz?
|
||||
[3] pattern?
|
||||
[4] endDate?
|
||||
[5] every?
|
||||
ARGV[3] legacy custom key TODO: remove this logic in next breaking change
|
||||
ARGV[4] custom key
|
||||
ARGV[5] prefix key
|
||||
Output:
|
||||
repeatableKey - OK
|
||||
]]
|
||||
local rcall = redis.call
|
||||
local repeatKey = KEYS[1]
|
||||
local delayedKey = KEYS[2]
|
||||
local nextMillis = ARGV[1]
|
||||
local legacyCustomKey = ARGV[3]
|
||||
local customKey = ARGV[4]
|
||||
local prefixKey = ARGV[5]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to remove job.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to remove deduplication key if needed
|
||||
when a job is being removed.
|
||||
]]
|
||||
local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
|
||||
jobId, deduplicationId)
|
||||
if deduplicationId then
|
||||
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
||||
local currentJobId = rcall('GET', deduplicationKey)
|
||||
if currentJobId and currentJobId == jobId then
|
||||
rcall("DEL", deduplicationKey)
|
||||
-- Also clean up any pending dedup-next data for this dedup ID
|
||||
rcall("DEL", prefixKey .. "dn:" .. deduplicationId)
|
||||
return 1
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to remove job keys.
|
||||
]]
|
||||
local function removeJobKeys(jobKey)
|
||||
return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
|
||||
jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
|
||||
end
|
||||
--[[
|
||||
Check if this job has a parent. If so we will just remove it from
|
||||
the parent child list, but if it is the last child we should move the parent to "wait/paused"
|
||||
which requires code from "moveToFinished"
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to add job in target list and add marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall(pushCmd, targetKey, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Functions to destructure job key.
|
||||
Just a bit of warning, these functions may be a bit slow and affect performance significantly.
|
||||
]]
|
||||
local getJobIdFromKey = function (jobKey)
|
||||
return string.match(jobKey, ".*:(.*)")
|
||||
end
|
||||
local getJobKeyPrefix = function (jobKey, jobId)
|
||||
return string.sub(jobKey, 0, #jobKey - #jobId)
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
local function _moveParentToWait(parentPrefix, parentId, emitEvent)
|
||||
local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
|
||||
parentPrefix .. "wait", parentPrefix .. "paused")
|
||||
addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
|
||||
if emitEvent then
|
||||
local parentEventStream = parentPrefix .. "events"
|
||||
rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
|
||||
end
|
||||
end
|
||||
local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
|
||||
if parentKey then
|
||||
local parentDependenciesKey = parentKey .. ":dependencies"
|
||||
local result = rcall("SREM", parentDependenciesKey, jobKey)
|
||||
if result > 0 then
|
||||
local pendingDependencies = rcall("SCARD", parentDependenciesKey)
|
||||
if pendingDependencies == 0 then
|
||||
local parentId = getJobIdFromKey(parentKey)
|
||||
local parentPrefix = getJobKeyPrefix(parentKey, parentId)
|
||||
local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
|
||||
if numRemovedElements == 1 then
|
||||
if hard then -- remove parent in same queue
|
||||
if parentPrefix == baseKey then
|
||||
removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
|
||||
removeJobKeys(parentKey)
|
||||
if debounceId then
|
||||
rcall("DEL", parentPrefix .. "de:" .. debounceId)
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId)
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
else
|
||||
local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
|
||||
local missedParentKey = parentAttributes[1]
|
||||
if( (type(missedParentKey) == "string") and missedParentKey ~= ""
|
||||
and (rcall("EXISTS", missedParentKey) == 1)) then
|
||||
local parentDependenciesKey = missedParentKey .. ":dependencies"
|
||||
local result = rcall("SREM", parentDependenciesKey, jobKey)
|
||||
if result > 0 then
|
||||
local pendingDependencies = rcall("SCARD", parentDependenciesKey)
|
||||
if pendingDependencies == 0 then
|
||||
local parentId = getJobIdFromKey(missedParentKey)
|
||||
local parentPrefix = getJobKeyPrefix(missedParentKey, parentId)
|
||||
local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
|
||||
if numRemovedElements == 1 then
|
||||
if hard then
|
||||
if parentPrefix == baseKey then
|
||||
removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
|
||||
removeJobKeys(missedParentKey)
|
||||
if parentAttributes[2] then
|
||||
rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId)
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
||||
local jobKey = baseKey .. jobId
|
||||
removeParentDependencyKey(jobKey, hard, nil, baseKey)
|
||||
if shouldRemoveDeduplicationKey then
|
||||
local deduplicationId = rcall("HGET", jobKey, "deid")
|
||||
removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobId, deduplicationId)
|
||||
end
|
||||
removeJobKeys(jobKey)
|
||||
end
|
||||
local function storeRepeatableJob(repeatKey, customKey, nextMillis, rawOpts)
|
||||
rcall("ZADD", repeatKey, nextMillis, customKey)
|
||||
local opts = cmsgpack.unpack(rawOpts)
|
||||
local optionalValues = {}
|
||||
if opts['tz'] then
|
||||
table.insert(optionalValues, "tz")
|
||||
table.insert(optionalValues, opts['tz'])
|
||||
end
|
||||
if opts['pattern'] then
|
||||
table.insert(optionalValues, "pattern")
|
||||
table.insert(optionalValues, opts['pattern'])
|
||||
end
|
||||
if opts['endDate'] then
|
||||
table.insert(optionalValues, "endDate")
|
||||
table.insert(optionalValues, opts['endDate'])
|
||||
end
|
||||
if opts['every'] then
|
||||
table.insert(optionalValues, "every")
|
||||
table.insert(optionalValues, opts['every'])
|
||||
end
|
||||
rcall("HMSET", repeatKey .. ":" .. customKey, "name", opts['name'],
|
||||
unpack(optionalValues))
|
||||
return customKey
|
||||
end
|
||||
-- If we are overriding a repeatable job we must delete the delayed job for
|
||||
-- the next iteration.
|
||||
local prevMillis = rcall("ZSCORE", repeatKey, customKey)
|
||||
if prevMillis then
|
||||
local delayedJobId = "repeat:" .. customKey .. ":" .. prevMillis
|
||||
local nextDelayedJobId = repeatKey .. ":" .. customKey .. ":" .. nextMillis
|
||||
if rcall("ZSCORE", delayedKey, delayedJobId)
|
||||
and rcall("EXISTS", nextDelayedJobId) ~= 1 then
|
||||
removeJob(delayedJobId, true, prefixKey, true --[[remove debounce key]])
|
||||
rcall("ZREM", delayedKey, delayedJobId)
|
||||
end
|
||||
end
|
||||
-- Keep backwards compatibility with old repeatable jobs (<= 3.0.0)
|
||||
if rcall("ZSCORE", repeatKey, legacyCustomKey) ~= false then
|
||||
return storeRepeatableJob(repeatKey, legacyCustomKey, nextMillis, ARGV[2])
|
||||
end
|
||||
return storeRepeatableJob(repeatKey, customKey, nextMillis, ARGV[2])
|
||||
`;
|
||||
export const addRepeatableJob = {
|
||||
name: 'addRepeatableJob',
|
||||
content,
|
||||
keys: 2,
|
||||
};
|
||||
//# sourceMappingURL=addRepeatableJob-2.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/addRepeatableJob-2.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/addRepeatableJob-2.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"addRepeatableJob-2.js","sourceRoot":"","sources":["../../../src/scripts/addRepeatableJob-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoOf,CAAC;AACF,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,kBAAkB;IACxB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/addStandardJob-9.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/addStandardJob-9.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const addStandardJob: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
549
node_modules/bullmq/dist/esm/scripts/addStandardJob-9.js
generated
vendored
Normal file
549
node_modules/bullmq/dist/esm/scripts/addStandardJob-9.js
generated
vendored
Normal file
@@ -0,0 +1,549 @@
|
||||
const content = `--[[
|
||||
Adds a job to the queue by doing the following:
|
||||
- Increases the job counter if needed.
|
||||
- Creates a new job key with the job data.
|
||||
- if delayed:
|
||||
- computes timestamp.
|
||||
- adds to delayed zset.
|
||||
- Emits a global event 'delayed' if the job is delayed.
|
||||
- if not delayed
|
||||
- Adds the jobId to the wait/paused list in one of three ways:
|
||||
- LIFO
|
||||
- FIFO
|
||||
- prioritized.
|
||||
- Adds the job to the "added" list so that workers gets notified.
|
||||
Input:
|
||||
KEYS[1] 'wait',
|
||||
KEYS[2] 'paused'
|
||||
KEYS[3] 'meta'
|
||||
KEYS[4] 'id'
|
||||
KEYS[5] 'completed'
|
||||
KEYS[6] 'delayed'
|
||||
KEYS[7] 'active'
|
||||
KEYS[8] events stream key
|
||||
KEYS[9] marker key
|
||||
ARGV[1] msgpacked arguments array
|
||||
[1] key prefix,
|
||||
[2] custom id (will not generate one automatically)
|
||||
[3] name
|
||||
[4] timestamp
|
||||
[5] parentKey?
|
||||
[6] parent dependencies key.
|
||||
[7] parent? {id, queueKey}
|
||||
[8] repeat job key
|
||||
[9] deduplication key
|
||||
ARGV[2] Json stringified job data
|
||||
ARGV[3] msgpacked options
|
||||
Output:
|
||||
jobId - OK
|
||||
-5 - Missing parent key
|
||||
]]
|
||||
local eventsKey = KEYS[8]
|
||||
local jobId
|
||||
local jobIdKey
|
||||
local rcall = redis.call
|
||||
local args = cmsgpack.unpack(ARGV[1])
|
||||
local data = ARGV[2]
|
||||
local opts = cmsgpack.unpack(ARGV[3])
|
||||
local parentKey = args[5]
|
||||
local parent = args[7]
|
||||
local repeatJobKey = args[8]
|
||||
local deduplicationKey = args[9]
|
||||
local parentData
|
||||
-- Includes
|
||||
--[[
|
||||
Function to add job in target list and add marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall(pushCmd, targetKey, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to debounce a job.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to deduplicate a job.
|
||||
]]
|
||||
--[[
|
||||
Function to set the deduplication key for a job.
|
||||
Uses TTL from deduplication opts if provided.
|
||||
]]
|
||||
local function setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
local ttl = deduplicationOpts and deduplicationOpts['ttl']
|
||||
if ttl and ttl > 0 then
|
||||
rcall('SET', deduplicationKey, jobId, 'PX', ttl)
|
||||
else
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to store a deduplicated next job if the existing job is active
|
||||
and keepLastIfActive is set. When the active job finishes, the stored
|
||||
proto-job is used to create a real job in the queue.
|
||||
Returns true if the proto-job was stored, false otherwise.
|
||||
]]
|
||||
--[[
|
||||
Function to check if an item belongs to a list.
|
||||
]]
|
||||
local function checkItemInList(list, item)
|
||||
for _, v in pairs(list) do
|
||||
if v == item then
|
||||
return 1
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
local function storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
if deduplicationOpts['keepLastIfActive'] and currentDebounceJobId then
|
||||
local activeKey = prefix .. "active"
|
||||
local activeItems = rcall('LRANGE', activeKey, 0, -1)
|
||||
if checkItemInList(activeItems, currentDebounceJobId) then
|
||||
local deduplicationNextKey = prefix .. "dn:" .. deduplicationId
|
||||
local fields = {'name', jobName, 'data', jobData, 'opts', cjson.encode(fullOpts)}
|
||||
if parentKey then
|
||||
fields[#fields+1] = 'pk'
|
||||
fields[#fields+1] = parentKey
|
||||
end
|
||||
if parentData then
|
||||
fields[#fields+1] = 'pd'
|
||||
fields[#fields+1] = parentData
|
||||
end
|
||||
if parentDependenciesKey then
|
||||
fields[#fields+1] = 'pdk'
|
||||
fields[#fields+1] = parentDependenciesKey
|
||||
end
|
||||
if repeatJobKey then
|
||||
fields[#fields+1] = 'rjk'
|
||||
fields[#fields+1] = repeatJobKey
|
||||
end
|
||||
rcall('HSET', deduplicationNextKey, unpack(fields))
|
||||
-- Ensure the dedup key does not expire while the job is active,
|
||||
-- so subsequent adds always hit the dedup path and never bypass
|
||||
-- the active-check because of a TTL expiry.
|
||||
local deduplicationKey = prefix .. "de:" .. deduplicationId
|
||||
rcall('PERSIST', deduplicationKey)
|
||||
-- TODO remove debounced event in next breaking change
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced", "jobId",
|
||||
currentDebounceJobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
currentDebounceJobId, "deduplicationId", deduplicationId, "deduplicatedJobId", jobId)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function deduplicateJobWithoutReplace(deduplicationId, deduplicationOpts, jobId, deduplicationKey,
|
||||
eventsKey, maxEvents, prefix, jobName, jobData, fullOpts,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
local ttl = deduplicationOpts['ttl']
|
||||
local deduplicationKeyExists
|
||||
if ttl and ttl > 0 then
|
||||
if deduplicationOpts['extend'] then
|
||||
local currentDebounceJobId = rcall('GET', deduplicationKey)
|
||||
if currentDebounceJobId then
|
||||
if storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey) then
|
||||
return currentDebounceJobId
|
||||
end
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, currentDebounceJobId)
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, currentDebounceJobId, deduplicationOpts)
|
||||
end
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced",
|
||||
"jobId", currentDebounceJobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
currentDebounceJobId, "deduplicationId", deduplicationId, "deduplicatedJobId", jobId)
|
||||
return currentDebounceJobId
|
||||
else
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
end
|
||||
return
|
||||
end
|
||||
else
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'NX')
|
||||
else
|
||||
deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'PX', ttl, 'NX')
|
||||
end
|
||||
end
|
||||
else
|
||||
deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'NX')
|
||||
end
|
||||
if deduplicationKeyExists then
|
||||
local currentDebounceJobId = rcall('GET', deduplicationKey)
|
||||
if storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey) then
|
||||
return currentDebounceJobId
|
||||
end
|
||||
-- TODO remove debounced event in next breaking change
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced", "jobId",
|
||||
currentDebounceJobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
currentDebounceJobId, "deduplicationId", deduplicationId, "deduplicatedJobId", jobId)
|
||||
return currentDebounceJobId
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to remove job keys.
|
||||
]]
|
||||
local function removeJobKeys(jobKey)
|
||||
return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
|
||||
jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
|
||||
end
|
||||
local function removeDelayedJob(delayedKey, deduplicationKey, eventsKey, maxEvents, currentDeduplicatedJobId,
|
||||
jobId, deduplicationId, prefix)
|
||||
if rcall("ZREM", delayedKey, currentDeduplicatedJobId) > 0 then
|
||||
removeJobKeys(prefix .. currentDeduplicatedJobId)
|
||||
rcall("XADD", eventsKey, "*", "event", "removed", "jobId", currentDeduplicatedJobId,
|
||||
"prev", "delayed")
|
||||
-- TODO remove debounced event in next breaking change
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "debounced", "jobId",
|
||||
jobId, "debounceId", deduplicationId)
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "deduplicated", "jobId",
|
||||
jobId, "deduplicationId", deduplicationId, "deduplicatedJobId", currentDeduplicatedJobId)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function deduplicateJob(deduplicationOpts, jobId, delayedKey, deduplicationKey, eventsKey, maxEvents,
|
||||
prefix, jobName, jobData, fullOpts, parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
local deduplicationId = deduplicationOpts and deduplicationOpts['id']
|
||||
if deduplicationId then
|
||||
if deduplicationOpts['replace'] then
|
||||
local currentDebounceJobId = rcall('GET', deduplicationKey)
|
||||
if currentDebounceJobId then
|
||||
local isRemoved = removeDelayedJob(delayedKey, deduplicationKey, eventsKey, maxEvents,
|
||||
currentDebounceJobId, jobId, deduplicationId, prefix)
|
||||
if isRemoved then
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
else
|
||||
local ttl = deduplicationOpts['ttl']
|
||||
if not deduplicationOpts['extend'] and ttl and ttl > 0 then
|
||||
rcall('SET', deduplicationKey, jobId, 'KEEPTTL')
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
end
|
||||
end
|
||||
return
|
||||
else
|
||||
storeDeduplicatedNextJob(deduplicationOpts, currentDebounceJobId, prefix,
|
||||
deduplicationId, jobName, jobData, fullOpts, eventsKey, maxEvents, jobId,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
return currentDebounceJobId
|
||||
end
|
||||
else
|
||||
if deduplicationOpts['keepLastIfActive'] then
|
||||
rcall('SET', deduplicationKey, jobId)
|
||||
else
|
||||
setDeduplicationKey(deduplicationKey, jobId, deduplicationOpts)
|
||||
end
|
||||
return
|
||||
end
|
||||
else
|
||||
return deduplicateJobWithoutReplace(deduplicationId, deduplicationOpts,
|
||||
jobId, deduplicationKey, eventsKey, maxEvents, prefix, jobName, jobData, fullOpts,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to get max events value or set by default 10000.
|
||||
]]
|
||||
local function getOrSetMaxEvents(metaKey)
|
||||
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
||||
if not maxEvents then
|
||||
maxEvents = 10000
|
||||
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
||||
end
|
||||
return maxEvents
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
--[[
|
||||
Function to handle the case when job is duplicated.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
This function is used to update the parent's dependencies if the job
|
||||
is already completed and about to be ignored. The parent must get its
|
||||
dependencies updated to avoid the parent job being stuck forever in
|
||||
the waiting-children state.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Validate and move or add dependencies to parent.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Validate and move parent to a wait status (waiting, delayed or prioritized)
|
||||
if no pending dependencies.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Move parent to a wait status (wait, prioritized or delayed)
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add delay marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to return the next delayed job timestamp.
|
||||
]]
|
||||
local function getNextDelayedTimestamp(delayedKey)
|
||||
local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
|
||||
if #result then
|
||||
local nextTimestamp = tonumber(result[2])
|
||||
if nextTimestamp ~= nil then
|
||||
return nextTimestamp / 0x1000
|
||||
end
|
||||
end
|
||||
end
|
||||
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
||||
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
||||
if nextTimestamp ~= nil then
|
||||
-- Replace the score of the marker with the newest known
|
||||
-- next timestamp.
|
||||
rcall("ZADD", markerKey, nextTimestamp, "1")
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to add job considering priority.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to get priority score.
|
||||
]]
|
||||
local function getPriorityScore(priority, priorityCounterKey)
|
||||
local prioCounter = rcall("INCR", priorityCounterKey)
|
||||
return priority * 0x100000000 + prioCounter % 0x100000000
|
||||
end
|
||||
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
|
||||
isPausedOrMaxed)
|
||||
local score = getPriorityScore(priority, priorityCounterKey)
|
||||
rcall("ZADD", prioritizedKey, score, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to check if queue is paused or maxed
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
|
||||
if queueAttributes[1] then
|
||||
return true
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
return activeCount >= tonumber(queueAttributes[2])
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
||||
local parentWaitKey = parentQueueKey .. ":wait"
|
||||
local parentPausedKey = parentQueueKey .. ":paused"
|
||||
local parentActiveKey = parentQueueKey .. ":active"
|
||||
local parentMetaKey = parentQueueKey .. ":meta"
|
||||
local parentMarkerKey = parentQueueKey .. ":marker"
|
||||
local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
|
||||
local priority = tonumber(jobAttributes[1]) or 0
|
||||
local delay = tonumber(jobAttributes[2]) or 0
|
||||
if delay > 0 then
|
||||
local delayedTimestamp = tonumber(timestamp) + delay
|
||||
local score = delayedTimestamp * 0x1000
|
||||
local parentDelayedKey = parentQueueKey .. ":delayed"
|
||||
rcall("ZADD", parentDelayedKey, score, parentId)
|
||||
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
|
||||
delayedTimestamp)
|
||||
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
||||
else
|
||||
if priority == 0 then
|
||||
local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
|
||||
parentWaitKey, parentPausedKey)
|
||||
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
||||
else
|
||||
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
||||
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
||||
parentQueueKey .. ":pc", isPausedOrMaxed)
|
||||
end
|
||||
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
||||
"waiting-children")
|
||||
end
|
||||
end
|
||||
local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
||||
if rcall("EXISTS", parentKey) == 1 then
|
||||
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
||||
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
||||
rcall("ZREM", parentWaitingChildrenKey, parentId)
|
||||
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
|
||||
parentId, timestamp)
|
||||
local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
|
||||
if doNotHavePendingDependencies then
|
||||
moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
||||
end
|
||||
end
|
||||
local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
|
||||
parentId, jobIdKey, returnvalue, timestamp )
|
||||
local processedSet = parentKey .. ":processed"
|
||||
rcall("HSET", processedSet, jobIdKey, returnvalue)
|
||||
moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
|
||||
end
|
||||
local function updateExistingJobsParent(parentKey, parent, parentData,
|
||||
parentDependenciesKey, completedKey,
|
||||
jobIdKey, jobId, timestamp)
|
||||
if parentKey ~= nil then
|
||||
if rcall("ZSCORE", completedKey, jobId) then
|
||||
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
||||
updateParentDepsIfNeeded(parentKey, parent['queueKey'],
|
||||
parentDependenciesKey, parent['id'],
|
||||
jobIdKey, returnvalue, timestamp)
|
||||
else
|
||||
if parentDependenciesKey ~= nil then
|
||||
rcall("SADD", parentDependenciesKey, jobIdKey)
|
||||
end
|
||||
end
|
||||
rcall("HMSET", jobIdKey, "parentKey", parentKey, "parent", parentData)
|
||||
end
|
||||
end
|
||||
local function handleDuplicatedJob(jobKey, jobId, currentParentKey, currentParent,
|
||||
parentData, parentDependenciesKey, completedKey, eventsKey, maxEvents, timestamp)
|
||||
local existedParentKey = rcall("HGET", jobKey, "parentKey")
|
||||
if not existedParentKey or existedParentKey == currentParentKey then
|
||||
updateExistingJobsParent(currentParentKey, currentParent, parentData,
|
||||
parentDependenciesKey, completedKey, jobKey,
|
||||
jobId, timestamp)
|
||||
else
|
||||
if currentParentKey ~= nil and currentParentKey ~= existedParentKey
|
||||
and (rcall("EXISTS", existedParentKey) == 1) then
|
||||
return -7
|
||||
end
|
||||
end
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
|
||||
"duplicated", "jobId", jobId)
|
||||
return jobId .. "" -- convert to string
|
||||
end
|
||||
--[[
|
||||
Function to store a job
|
||||
]]
|
||||
local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
|
||||
parentKey, parentData, repeatJobKey)
|
||||
local jsonOpts = cjson.encode(opts)
|
||||
local delay = opts['delay'] or 0
|
||||
local priority = opts['priority'] or 0
|
||||
local debounceId = opts['de'] and opts['de']['id']
|
||||
local optionalValues = {}
|
||||
if parentKey ~= nil then
|
||||
table.insert(optionalValues, "parentKey")
|
||||
table.insert(optionalValues, parentKey)
|
||||
table.insert(optionalValues, "parent")
|
||||
table.insert(optionalValues, parentData)
|
||||
end
|
||||
if repeatJobKey then
|
||||
table.insert(optionalValues, "rjk")
|
||||
table.insert(optionalValues, repeatJobKey)
|
||||
end
|
||||
if debounceId then
|
||||
table.insert(optionalValues, "deid")
|
||||
table.insert(optionalValues, debounceId)
|
||||
end
|
||||
rcall("HMSET", jobIdKey, "name", name, "data", data, "opts", jsonOpts,
|
||||
"timestamp", timestamp, "delay", delay, "priority", priority,
|
||||
unpack(optionalValues))
|
||||
rcall("XADD", eventsKey, "*", "event", "added", "jobId", jobId, "name", name)
|
||||
return delay, priority
|
||||
end
|
||||
if parentKey ~= nil then
|
||||
if rcall("EXISTS", parentKey) ~= 1 then return -5 end
|
||||
parentData = cjson.encode(parent)
|
||||
end
|
||||
local jobCounter = rcall("INCR", KEYS[4])
|
||||
local metaKey = KEYS[3]
|
||||
local maxEvents = getOrSetMaxEvents(metaKey)
|
||||
local parentDependenciesKey = args[6]
|
||||
local timestamp = args[4]
|
||||
if args[2] == "" then
|
||||
jobId = jobCounter
|
||||
jobIdKey = args[1] .. jobId
|
||||
else
|
||||
jobId = args[2]
|
||||
jobIdKey = args[1] .. jobId
|
||||
if rcall("EXISTS", jobIdKey) == 1 then
|
||||
return handleDuplicatedJob(jobIdKey, jobId, parentKey, parent,
|
||||
parentData, parentDependenciesKey, KEYS[5], eventsKey,
|
||||
maxEvents, timestamp)
|
||||
end
|
||||
end
|
||||
local deduplicationJobId = deduplicateJob(opts['de'], jobId, KEYS[6],
|
||||
deduplicationKey, eventsKey, maxEvents, args[1], args[3], ARGV[2], opts,
|
||||
parentKey, parentData, parentDependenciesKey, repeatJobKey)
|
||||
if deduplicationJobId then
|
||||
return deduplicationJobId
|
||||
end
|
||||
-- Store the job.
|
||||
storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2], opts, timestamp,
|
||||
parentKey, parentData, repeatJobKey)
|
||||
local target, isPausedOrMaxed = getTargetQueueList(metaKey, KEYS[7], KEYS[1], KEYS[2])
|
||||
-- LIFO or FIFO
|
||||
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
||||
addJobInTargetList(target, KEYS[9], pushCmd, isPausedOrMaxed, jobId)
|
||||
-- Emit waiting event
|
||||
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
|
||||
"jobId", jobId)
|
||||
-- Check if this job is a child of another job, if so add it to the parents dependencies
|
||||
if parentDependenciesKey ~= nil then
|
||||
rcall("SADD", parentDependenciesKey, jobIdKey)
|
||||
end
|
||||
return jobId .. "" -- convert to string
|
||||
`;
|
||||
export const addStandardJob = {
|
||||
name: 'addStandardJob',
|
||||
content,
|
||||
keys: 9,
|
||||
};
|
||||
//# sourceMappingURL=addStandardJob-9.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/addStandardJob-9.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/addStandardJob-9.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"addStandardJob-9.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8hBf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/changeDelay-4.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/changeDelay-4.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const changeDelay: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
104
node_modules/bullmq/dist/esm/scripts/changeDelay-4.js
generated
vendored
Normal file
104
node_modules/bullmq/dist/esm/scripts/changeDelay-4.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
const content = `--[[
|
||||
Change job delay when it is in delayed set.
|
||||
Input:
|
||||
KEYS[1] delayed key
|
||||
KEYS[2] meta key
|
||||
KEYS[3] marker key
|
||||
KEYS[4] events stream
|
||||
ARGV[1] delay
|
||||
ARGV[2] timestamp
|
||||
ARGV[3] the id of the job
|
||||
ARGV[4] job key
|
||||
Output:
|
||||
0 - OK
|
||||
-1 - Missing job.
|
||||
-3 - Job not in delayed set.
|
||||
Events:
|
||||
- delayed key.
|
||||
]]
|
||||
local rcall = redis.call
|
||||
-- Includes
|
||||
--[[
|
||||
Add delay marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to return the next delayed job timestamp.
|
||||
]]
|
||||
local function getNextDelayedTimestamp(delayedKey)
|
||||
local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
|
||||
if #result then
|
||||
local nextTimestamp = tonumber(result[2])
|
||||
if nextTimestamp ~= nil then
|
||||
return nextTimestamp / 0x1000
|
||||
end
|
||||
end
|
||||
end
|
||||
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
||||
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
||||
if nextTimestamp ~= nil then
|
||||
-- Replace the score of the marker with the newest known
|
||||
-- next timestamp.
|
||||
rcall("ZADD", markerKey, nextTimestamp, "1")
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Bake in the job id first 12 bits into the timestamp
|
||||
to guarantee correct execution order of delayed jobs
|
||||
(up to 4096 jobs per given timestamp or 4096 jobs apart per timestamp)
|
||||
WARNING: Jobs that are so far apart that they wrap around will cause FIFO to fail
|
||||
]]
|
||||
local function getDelayedScore(delayedKey, timestamp, delay)
|
||||
local delayedTimestamp = (delay > 0 and (tonumber(timestamp) + delay)) or tonumber(timestamp)
|
||||
local minScore = delayedTimestamp * 0x1000
|
||||
local maxScore = (delayedTimestamp + 1 ) * 0x1000 - 1
|
||||
local result = rcall("ZREVRANGEBYSCORE", delayedKey, maxScore,
|
||||
minScore, "WITHSCORES","LIMIT", 0, 1)
|
||||
if #result then
|
||||
local currentMaxScore = tonumber(result[2])
|
||||
if currentMaxScore ~= nil then
|
||||
if currentMaxScore >= maxScore then
|
||||
return maxScore, delayedTimestamp
|
||||
else
|
||||
return currentMaxScore + 1, delayedTimestamp
|
||||
end
|
||||
end
|
||||
end
|
||||
return minScore, delayedTimestamp
|
||||
end
|
||||
--[[
|
||||
Function to get max events value or set by default 10000.
|
||||
]]
|
||||
local function getOrSetMaxEvents(metaKey)
|
||||
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
||||
if not maxEvents then
|
||||
maxEvents = 10000
|
||||
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
||||
end
|
||||
return maxEvents
|
||||
end
|
||||
if rcall("EXISTS", ARGV[4]) == 1 then
|
||||
local jobId = ARGV[3]
|
||||
local delay = tonumber(ARGV[1])
|
||||
local score, delayedTimestamp = getDelayedScore(KEYS[1], ARGV[2], delay)
|
||||
local numRemovedElements = rcall("ZREM", KEYS[1], jobId)
|
||||
if numRemovedElements < 1 then
|
||||
return -3
|
||||
end
|
||||
rcall("HSET", ARGV[4], "delay", delay)
|
||||
rcall("ZADD", KEYS[1], score, jobId)
|
||||
local maxEvents = getOrSetMaxEvents(KEYS[2])
|
||||
rcall("XADD", KEYS[4], "MAXLEN", "~", maxEvents, "*", "event", "delayed",
|
||||
"jobId", jobId, "delay", delayedTimestamp)
|
||||
-- mark that a delayed job is available
|
||||
addDelayMarkerIfNeeded(KEYS[3], KEYS[1])
|
||||
return 0
|
||||
else
|
||||
return -1
|
||||
end`;
|
||||
export const changeDelay = {
|
||||
name: 'changeDelay',
|
||||
content,
|
||||
keys: 4,
|
||||
};
|
||||
//# sourceMappingURL=changeDelay-4.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/changeDelay-4.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/changeDelay-4.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"changeDelay-4.js","sourceRoot":"","sources":["../../../src/scripts/changeDelay-4.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAiGZ,CAAC;AACL,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,aAAa;IACnB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/changePriority-7.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/changePriority-7.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const changePriority: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
125
node_modules/bullmq/dist/esm/scripts/changePriority-7.js
generated
vendored
Normal file
125
node_modules/bullmq/dist/esm/scripts/changePriority-7.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
const content = `--[[
|
||||
Change job priority
|
||||
Input:
|
||||
KEYS[1] 'wait',
|
||||
KEYS[2] 'paused'
|
||||
KEYS[3] 'meta'
|
||||
KEYS[4] 'prioritized'
|
||||
KEYS[5] 'active'
|
||||
KEYS[6] 'pc' priority counter
|
||||
KEYS[7] 'marker'
|
||||
ARGV[1] priority value
|
||||
ARGV[2] prefix key
|
||||
ARGV[3] job id
|
||||
ARGV[4] lifo
|
||||
Output:
|
||||
0 - OK
|
||||
-1 - Missing job
|
||||
]]
|
||||
local jobId = ARGV[3]
|
||||
local jobKey = ARGV[2] .. jobId
|
||||
local priority = tonumber(ARGV[1])
|
||||
local rcall = redis.call
|
||||
-- Includes
|
||||
--[[
|
||||
Function to add job in target list and add marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall(pushCmd, targetKey, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to add job considering priority.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to get priority score.
|
||||
]]
|
||||
local function getPriorityScore(priority, priorityCounterKey)
|
||||
local prioCounter = rcall("INCR", priorityCounterKey)
|
||||
return priority * 0x100000000 + prioCounter % 0x100000000
|
||||
end
|
||||
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
|
||||
isPausedOrMaxed)
|
||||
local score = getPriorityScore(priority, priorityCounterKey)
|
||||
rcall("ZADD", prioritizedKey, score, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
--[[
|
||||
Function to push back job considering priority in front of same prioritized jobs.
|
||||
]]
|
||||
local function pushBackJobWithPriority(prioritizedKey, priority, jobId)
|
||||
-- in order to put it at front of same prioritized jobs
|
||||
-- we consider prioritized counter as 0
|
||||
local score = priority * 0x100000000
|
||||
rcall("ZADD", prioritizedKey, score, jobId)
|
||||
end
|
||||
local function reAddJobWithNewPriority( prioritizedKey, markerKey, targetKey,
|
||||
priorityCounter, lifo, priority, jobId, isPausedOrMaxed)
|
||||
if priority == 0 then
|
||||
local pushCmd = lifo and 'RPUSH' or 'LPUSH'
|
||||
addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
else
|
||||
if lifo then
|
||||
pushBackJobWithPriority(prioritizedKey, priority, jobId)
|
||||
else
|
||||
addJobWithPriority(markerKey, prioritizedKey, priority, jobId,
|
||||
priorityCounter, isPausedOrMaxed)
|
||||
end
|
||||
end
|
||||
end
|
||||
if rcall("EXISTS", jobKey) == 1 then
|
||||
local metaKey = KEYS[3]
|
||||
local target, isPausedOrMaxed = getTargetQueueList(metaKey, KEYS[5], KEYS[1], KEYS[2])
|
||||
local prioritizedKey = KEYS[4]
|
||||
local priorityCounterKey = KEYS[6]
|
||||
local markerKey = KEYS[7]
|
||||
-- Re-add with the new priority
|
||||
if rcall("ZREM", prioritizedKey, jobId) > 0 then
|
||||
reAddJobWithNewPriority( prioritizedKey, markerKey, target,
|
||||
priorityCounterKey, ARGV[4] == '1', priority, jobId, isPausedOrMaxed)
|
||||
elseif rcall("LREM", target, -1, jobId) > 0 then
|
||||
reAddJobWithNewPriority( prioritizedKey, markerKey, target,
|
||||
priorityCounterKey, ARGV[4] == '1', priority, jobId, isPausedOrMaxed)
|
||||
end
|
||||
rcall("HSET", jobKey, "priority", priority)
|
||||
return 0
|
||||
else
|
||||
return -1
|
||||
end
|
||||
`;
|
||||
export const changePriority = {
|
||||
name: 'changePriority',
|
||||
content,
|
||||
keys: 7,
|
||||
};
|
||||
//# sourceMappingURL=changePriority-7.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/changePriority-7.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/changePriority-7.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"changePriority-7.js","sourceRoot":"","sources":["../../../src/scripts/changePriority-7.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsHf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/cleanJobsInSet-3.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/cleanJobsInSet-3.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const cleanJobsInSet: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
366
node_modules/bullmq/dist/esm/scripts/cleanJobsInSet-3.js
generated
vendored
Normal file
366
node_modules/bullmq/dist/esm/scripts/cleanJobsInSet-3.js
generated
vendored
Normal file
@@ -0,0 +1,366 @@
|
||||
const content = `--[[
|
||||
Remove jobs from the specific set.
|
||||
Input:
|
||||
KEYS[1] set key,
|
||||
KEYS[2] events stream key
|
||||
KEYS[3] repeat key
|
||||
ARGV[1] jobKey prefix
|
||||
ARGV[2] timestamp
|
||||
ARGV[3] limit the number of jobs to be removed. 0 is unlimited
|
||||
ARGV[4] set name, can be any of 'wait', 'active', 'paused', 'delayed', 'completed', or 'failed'
|
||||
]]
|
||||
local rcall = redis.call
|
||||
local repeatKey = KEYS[3]
|
||||
local rangeStart = 0
|
||||
local rangeEnd = -1
|
||||
local limit = tonumber(ARGV[3])
|
||||
-- If we're only deleting _n_ items, avoid retrieving all items
|
||||
-- for faster performance
|
||||
--
|
||||
-- Start from the tail of the list, since that's where oldest elements
|
||||
-- are generally added for FIFO lists
|
||||
if limit > 0 then
|
||||
rangeStart = -1 - limit + 1
|
||||
rangeEnd = -1
|
||||
end
|
||||
-- Includes
|
||||
--[[
|
||||
Function to clean job list.
|
||||
Returns jobIds and deleted count number.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to get the latest saved timestamp.
|
||||
]]
|
||||
local function getTimestamp(jobKey, attributes)
|
||||
if #attributes == 1 then
|
||||
return rcall("HGET", jobKey, attributes[1])
|
||||
end
|
||||
local jobTs
|
||||
for _, ts in ipairs(rcall("HMGET", jobKey, unpack(attributes))) do
|
||||
if (ts) then
|
||||
jobTs = ts
|
||||
break
|
||||
end
|
||||
end
|
||||
return jobTs
|
||||
end
|
||||
--[[
|
||||
Function to check if the job belongs to a job scheduler and
|
||||
current delayed job matches with jobId
|
||||
]]
|
||||
local function isJobSchedulerJob(jobId, jobKey, jobSchedulersKey)
|
||||
local repeatJobKey = rcall("HGET", jobKey, "rjk")
|
||||
if repeatJobKey then
|
||||
local prevMillis = rcall("ZSCORE", jobSchedulersKey, repeatJobKey)
|
||||
if prevMillis then
|
||||
local currentDelayedJobId = "repeat:" .. repeatJobKey .. ":" .. prevMillis
|
||||
return jobId == currentDelayedJobId
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
--[[
|
||||
Function to remove job.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to remove deduplication key if needed
|
||||
when a job is being removed.
|
||||
]]
|
||||
local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
|
||||
jobId, deduplicationId)
|
||||
if deduplicationId then
|
||||
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
||||
local currentJobId = rcall('GET', deduplicationKey)
|
||||
if currentJobId and currentJobId == jobId then
|
||||
rcall("DEL", deduplicationKey)
|
||||
-- Also clean up any pending dedup-next data for this dedup ID
|
||||
rcall("DEL", prefixKey .. "dn:" .. deduplicationId)
|
||||
return 1
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to remove job keys.
|
||||
]]
|
||||
local function removeJobKeys(jobKey)
|
||||
return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
|
||||
jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
|
||||
end
|
||||
--[[
|
||||
Check if this job has a parent. If so we will just remove it from
|
||||
the parent child list, but if it is the last child we should move the parent to "wait/paused"
|
||||
which requires code from "moveToFinished"
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to add job in target list and add marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall(pushCmd, targetKey, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Functions to destructure job key.
|
||||
Just a bit of warning, these functions may be a bit slow and affect performance significantly.
|
||||
]]
|
||||
local getJobIdFromKey = function (jobKey)
|
||||
return string.match(jobKey, ".*:(.*)")
|
||||
end
|
||||
local getJobKeyPrefix = function (jobKey, jobId)
|
||||
return string.sub(jobKey, 0, #jobKey - #jobId)
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
local function _moveParentToWait(parentPrefix, parentId, emitEvent)
|
||||
local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
|
||||
parentPrefix .. "wait", parentPrefix .. "paused")
|
||||
addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
|
||||
if emitEvent then
|
||||
local parentEventStream = parentPrefix .. "events"
|
||||
rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
|
||||
end
|
||||
end
|
||||
local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
|
||||
if parentKey then
|
||||
local parentDependenciesKey = parentKey .. ":dependencies"
|
||||
local result = rcall("SREM", parentDependenciesKey, jobKey)
|
||||
if result > 0 then
|
||||
local pendingDependencies = rcall("SCARD", parentDependenciesKey)
|
||||
if pendingDependencies == 0 then
|
||||
local parentId = getJobIdFromKey(parentKey)
|
||||
local parentPrefix = getJobKeyPrefix(parentKey, parentId)
|
||||
local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
|
||||
if numRemovedElements == 1 then
|
||||
if hard then -- remove parent in same queue
|
||||
if parentPrefix == baseKey then
|
||||
removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
|
||||
removeJobKeys(parentKey)
|
||||
if debounceId then
|
||||
rcall("DEL", parentPrefix .. "de:" .. debounceId)
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId)
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
else
|
||||
local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
|
||||
local missedParentKey = parentAttributes[1]
|
||||
if( (type(missedParentKey) == "string") and missedParentKey ~= ""
|
||||
and (rcall("EXISTS", missedParentKey) == 1)) then
|
||||
local parentDependenciesKey = missedParentKey .. ":dependencies"
|
||||
local result = rcall("SREM", parentDependenciesKey, jobKey)
|
||||
if result > 0 then
|
||||
local pendingDependencies = rcall("SCARD", parentDependenciesKey)
|
||||
if pendingDependencies == 0 then
|
||||
local parentId = getJobIdFromKey(missedParentKey)
|
||||
local parentPrefix = getJobKeyPrefix(missedParentKey, parentId)
|
||||
local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
|
||||
if numRemovedElements == 1 then
|
||||
if hard then
|
||||
if parentPrefix == baseKey then
|
||||
removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
|
||||
removeJobKeys(missedParentKey)
|
||||
if parentAttributes[2] then
|
||||
rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId)
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
||||
local jobKey = baseKey .. jobId
|
||||
removeParentDependencyKey(jobKey, hard, nil, baseKey)
|
||||
if shouldRemoveDeduplicationKey then
|
||||
local deduplicationId = rcall("HGET", jobKey, "deid")
|
||||
removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobId, deduplicationId)
|
||||
end
|
||||
removeJobKeys(jobKey)
|
||||
end
|
||||
local function cleanList(listKey, jobKeyPrefix, rangeStart, rangeEnd,
|
||||
timestamp, isWaiting, jobSchedulersKey)
|
||||
local jobs = rcall("LRANGE", listKey, rangeStart, rangeEnd)
|
||||
local deleted = {}
|
||||
local deletedCount = 0
|
||||
local jobTS
|
||||
local deletionMarker = ''
|
||||
local jobIdsLen = #jobs
|
||||
for i, job in ipairs(jobs) do
|
||||
if limit > 0 and deletedCount >= limit then
|
||||
break
|
||||
end
|
||||
local jobKey = jobKeyPrefix .. job
|
||||
if (isWaiting or rcall("EXISTS", jobKey .. ":lock") == 0) and
|
||||
not isJobSchedulerJob(job, jobKey, jobSchedulersKey) then
|
||||
-- Find the right timestamp of the job to compare to maxTimestamp:
|
||||
-- * finishedOn says when the job was completed, but it isn't set unless the job has actually completed
|
||||
-- * processedOn represents when the job was last attempted, but it doesn't get populated until
|
||||
-- the job is first tried
|
||||
-- * timestamp is the original job submission time
|
||||
-- Fetch all three of these (in that order) and use the first one that is set so that we'll leave jobs
|
||||
-- that have been active within the grace period:
|
||||
jobTS = getTimestamp(jobKey, {"finishedOn", "processedOn", "timestamp"})
|
||||
if (not jobTS or jobTS <= timestamp) then
|
||||
-- replace the entry with a deletion marker; the actual deletion will
|
||||
-- occur at the end of the script
|
||||
rcall("LSET", listKey, rangeEnd - jobIdsLen + i, deletionMarker)
|
||||
removeJob(job, true, jobKeyPrefix, true --[[remove debounce key]])
|
||||
deletedCount = deletedCount + 1
|
||||
table.insert(deleted, job)
|
||||
end
|
||||
end
|
||||
end
|
||||
rcall("LREM", listKey, 0, deletionMarker)
|
||||
return {deleted, deletedCount}
|
||||
end
|
||||
--[[
|
||||
Function to clean job set.
|
||||
Returns jobIds and deleted count number.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to loop in batches.
|
||||
Just a bit of warning, some commands as ZREM
|
||||
could receive a maximum of 7000 parameters per call.
|
||||
]]
|
||||
local function batches(n, batchSize)
|
||||
local i = 0
|
||||
return function()
|
||||
local from = i * batchSize + 1
|
||||
i = i + 1
|
||||
if (from <= n) then
|
||||
local to = math.min(from + batchSize - 1, n)
|
||||
return from, to
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
We use ZRANGEBYSCORE to make the case where we're deleting a limited number
|
||||
of items in a sorted set only run a single iteration. If we simply used
|
||||
ZRANGE, we may take a long time traversing through jobs that are within the
|
||||
grace period.
|
||||
]]
|
||||
local function getJobsInZset(zsetKey, rangeEnd, limit)
|
||||
if limit > 0 then
|
||||
return rcall("ZRANGEBYSCORE", zsetKey, 0, rangeEnd, "LIMIT", 0, limit)
|
||||
else
|
||||
return rcall("ZRANGEBYSCORE", zsetKey, 0, rangeEnd)
|
||||
end
|
||||
end
|
||||
local function cleanSet(
|
||||
setKey,
|
||||
jobKeyPrefix,
|
||||
rangeEnd,
|
||||
timestamp,
|
||||
limit,
|
||||
attributes,
|
||||
isFinished,
|
||||
jobSchedulersKey)
|
||||
local jobs = getJobsInZset(setKey, rangeEnd, limit)
|
||||
local deleted = {}
|
||||
local deletedCount = 0
|
||||
local jobTS
|
||||
for i, job in ipairs(jobs) do
|
||||
if limit > 0 and deletedCount >= limit then
|
||||
break
|
||||
end
|
||||
local jobKey = jobKeyPrefix .. job
|
||||
-- Extract a Job Scheduler Id from jobId ("repeat:job-scheduler-id:millis")
|
||||
-- and check if it is in the scheduled jobs
|
||||
if not (jobSchedulersKey and isJobSchedulerJob(job, jobKey, jobSchedulersKey)) then
|
||||
if isFinished then
|
||||
removeJob(job, true, jobKeyPrefix, true --[[remove debounce key]] )
|
||||
deletedCount = deletedCount + 1
|
||||
table.insert(deleted, job)
|
||||
else
|
||||
-- * finishedOn says when the job was completed, but it isn't set unless the job has actually completed
|
||||
jobTS = getTimestamp(jobKey, attributes)
|
||||
if (not jobTS or jobTS <= timestamp) then
|
||||
removeJob(job, true, jobKeyPrefix, true --[[remove debounce key]] )
|
||||
deletedCount = deletedCount + 1
|
||||
table.insert(deleted, job)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if (#deleted > 0) then
|
||||
for from, to in batches(#deleted, 7000) do
|
||||
rcall("ZREM", setKey, unpack(deleted, from, to))
|
||||
end
|
||||
end
|
||||
return {deleted, deletedCount}
|
||||
end
|
||||
local result
|
||||
if ARGV[4] == "active" then
|
||||
result = cleanList(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], false --[[ hasFinished ]],
|
||||
repeatKey)
|
||||
elseif ARGV[4] == "delayed" then
|
||||
rangeEnd = "+inf"
|
||||
result = cleanSet(KEYS[1], ARGV[1], rangeEnd, ARGV[2], limit,
|
||||
{"processedOn", "timestamp"}, false --[[ hasFinished ]], repeatKey)
|
||||
elseif ARGV[4] == "prioritized" then
|
||||
rangeEnd = "+inf"
|
||||
result = cleanSet(KEYS[1], ARGV[1], rangeEnd, ARGV[2], limit,
|
||||
{"timestamp"}, false --[[ hasFinished ]], repeatKey)
|
||||
elseif ARGV[4] == "wait" or ARGV[4] == "paused" then
|
||||
result = cleanList(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], true --[[ hasFinished ]],
|
||||
repeatKey)
|
||||
else
|
||||
rangeEnd = ARGV[2]
|
||||
-- No need to pass repeat key as in that moment job won't be related to a job scheduler
|
||||
result = cleanSet(KEYS[1], ARGV[1], rangeEnd, ARGV[2], limit,
|
||||
{"finishedOn"}, true --[[ hasFinished ]])
|
||||
end
|
||||
rcall("XADD", KEYS[2], "*", "event", "cleaned", "count", result[2])
|
||||
return result[1]
|
||||
`;
|
||||
export const cleanJobsInSet = {
|
||||
name: 'cleanJobsInSet',
|
||||
content,
|
||||
keys: 3,
|
||||
};
|
||||
//# sourceMappingURL=cleanJobsInSet-3.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/cleanJobsInSet-3.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/cleanJobsInSet-3.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"cleanJobsInSet-3.js","sourceRoot":"","sources":["../../../src/scripts/cleanJobsInSet-3.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuWf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/drain-5.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/drain-5.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const drain: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
272
node_modules/bullmq/dist/esm/scripts/drain-5.js
generated
vendored
Normal file
272
node_modules/bullmq/dist/esm/scripts/drain-5.js
generated
vendored
Normal file
@@ -0,0 +1,272 @@
|
||||
const content = `--[[
|
||||
Drains the queue, removes all jobs that are waiting
|
||||
or delayed, but not active, completed or failed
|
||||
Input:
|
||||
KEYS[1] 'wait',
|
||||
KEYS[2] 'paused'
|
||||
KEYS[3] 'delayed'
|
||||
KEYS[4] 'prioritized'
|
||||
KEYS[5] 'jobschedulers' (repeat)
|
||||
ARGV[1] queue key prefix
|
||||
ARGV[2] should clean delayed jobs
|
||||
]]
|
||||
local rcall = redis.call
|
||||
local queueBaseKey = ARGV[1]
|
||||
--[[
|
||||
Functions to remove jobs.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to filter out jobs to ignore from a table.
|
||||
]]
|
||||
local function filterOutJobsToIgnore(jobs, jobsToIgnore)
|
||||
local filteredJobs = {}
|
||||
for i = 1, #jobs do
|
||||
if not jobsToIgnore[jobs[i]] then
|
||||
table.insert(filteredJobs, jobs[i])
|
||||
end
|
||||
end
|
||||
return filteredJobs
|
||||
end
|
||||
--[[
|
||||
Functions to remove jobs.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to remove job.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to remove deduplication key if needed
|
||||
when a job is being removed.
|
||||
]]
|
||||
local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
|
||||
jobId, deduplicationId)
|
||||
if deduplicationId then
|
||||
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
||||
local currentJobId = rcall('GET', deduplicationKey)
|
||||
if currentJobId and currentJobId == jobId then
|
||||
rcall("DEL", deduplicationKey)
|
||||
-- Also clean up any pending dedup-next data for this dedup ID
|
||||
rcall("DEL", prefixKey .. "dn:" .. deduplicationId)
|
||||
return 1
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to remove job keys.
|
||||
]]
|
||||
local function removeJobKeys(jobKey)
|
||||
return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
|
||||
jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
|
||||
end
|
||||
--[[
|
||||
Check if this job has a parent. If so we will just remove it from
|
||||
the parent child list, but if it is the last child we should move the parent to "wait/paused"
|
||||
which requires code from "moveToFinished"
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to add job in target list and add marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall(pushCmd, targetKey, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Functions to destructure job key.
|
||||
Just a bit of warning, these functions may be a bit slow and affect performance significantly.
|
||||
]]
|
||||
local getJobIdFromKey = function (jobKey)
|
||||
return string.match(jobKey, ".*:(.*)")
|
||||
end
|
||||
local getJobKeyPrefix = function (jobKey, jobId)
|
||||
return string.sub(jobKey, 0, #jobKey - #jobId)
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
local function _moveParentToWait(parentPrefix, parentId, emitEvent)
|
||||
local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
|
||||
parentPrefix .. "wait", parentPrefix .. "paused")
|
||||
addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
|
||||
if emitEvent then
|
||||
local parentEventStream = parentPrefix .. "events"
|
||||
rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
|
||||
end
|
||||
end
|
||||
local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
|
||||
if parentKey then
|
||||
local parentDependenciesKey = parentKey .. ":dependencies"
|
||||
local result = rcall("SREM", parentDependenciesKey, jobKey)
|
||||
if result > 0 then
|
||||
local pendingDependencies = rcall("SCARD", parentDependenciesKey)
|
||||
if pendingDependencies == 0 then
|
||||
local parentId = getJobIdFromKey(parentKey)
|
||||
local parentPrefix = getJobKeyPrefix(parentKey, parentId)
|
||||
local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
|
||||
if numRemovedElements == 1 then
|
||||
if hard then -- remove parent in same queue
|
||||
if parentPrefix == baseKey then
|
||||
removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
|
||||
removeJobKeys(parentKey)
|
||||
if debounceId then
|
||||
rcall("DEL", parentPrefix .. "de:" .. debounceId)
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId)
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
else
|
||||
local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
|
||||
local missedParentKey = parentAttributes[1]
|
||||
if( (type(missedParentKey) == "string") and missedParentKey ~= ""
|
||||
and (rcall("EXISTS", missedParentKey) == 1)) then
|
||||
local parentDependenciesKey = missedParentKey .. ":dependencies"
|
||||
local result = rcall("SREM", parentDependenciesKey, jobKey)
|
||||
if result > 0 then
|
||||
local pendingDependencies = rcall("SCARD", parentDependenciesKey)
|
||||
if pendingDependencies == 0 then
|
||||
local parentId = getJobIdFromKey(missedParentKey)
|
||||
local parentPrefix = getJobKeyPrefix(missedParentKey, parentId)
|
||||
local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
|
||||
if numRemovedElements == 1 then
|
||||
if hard then
|
||||
if parentPrefix == baseKey then
|
||||
removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
|
||||
removeJobKeys(missedParentKey)
|
||||
if parentAttributes[2] then
|
||||
rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId)
|
||||
end
|
||||
else
|
||||
_moveParentToWait(parentPrefix, parentId, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
||||
local jobKey = baseKey .. jobId
|
||||
removeParentDependencyKey(jobKey, hard, nil, baseKey)
|
||||
if shouldRemoveDeduplicationKey then
|
||||
local deduplicationId = rcall("HGET", jobKey, "deid")
|
||||
removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobId, deduplicationId)
|
||||
end
|
||||
removeJobKeys(jobKey)
|
||||
end
|
||||
local function removeJobs(keys, hard, baseKey, max)
|
||||
for i, key in ipairs(keys) do
|
||||
removeJob(key, hard, baseKey, true --[[remove debounce key]])
|
||||
end
|
||||
return max - #keys
|
||||
end
|
||||
local function getListItems(keyName, max)
|
||||
return rcall('LRANGE', keyName, 0, max - 1)
|
||||
end
|
||||
local function removeListJobs(keyName, hard, baseKey, max, jobsToIgnore)
|
||||
local jobs = getListItems(keyName, max)
|
||||
if jobsToIgnore then
|
||||
jobs = filterOutJobsToIgnore(jobs, jobsToIgnore)
|
||||
end
|
||||
local count = removeJobs(jobs, hard, baseKey, max)
|
||||
rcall("LTRIM", keyName, #jobs, -1)
|
||||
return count
|
||||
end
|
||||
-- Includes
|
||||
--[[
|
||||
Function to loop in batches.
|
||||
Just a bit of warning, some commands as ZREM
|
||||
could receive a maximum of 7000 parameters per call.
|
||||
]]
|
||||
local function batches(n, batchSize)
|
||||
local i = 0
|
||||
return function()
|
||||
local from = i * batchSize + 1
|
||||
i = i + 1
|
||||
if (from <= n) then
|
||||
local to = math.min(from + batchSize - 1, n)
|
||||
return from, to
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to get ZSet items.
|
||||
]]
|
||||
local function getZSetItems(keyName, max)
|
||||
return rcall('ZRANGE', keyName, 0, max - 1)
|
||||
end
|
||||
local function removeZSetJobs(keyName, hard, baseKey, max, jobsToIgnore)
|
||||
local jobs = getZSetItems(keyName, max)
|
||||
if jobsToIgnore then
|
||||
jobs = filterOutJobsToIgnore(jobs, jobsToIgnore)
|
||||
end
|
||||
local count = removeJobs(jobs, hard, baseKey, max)
|
||||
if(#jobs > 0) then
|
||||
for from, to in batches(#jobs, 7000) do
|
||||
rcall("ZREM", keyName, unpack(jobs, from, to))
|
||||
end
|
||||
end
|
||||
return count
|
||||
end
|
||||
-- We must not remove delayed jobs if they are associated to a job scheduler.
|
||||
local scheduledJobs = {}
|
||||
local jobSchedulers = rcall("ZRANGE", KEYS[5], 0, -1, "WITHSCORES")
|
||||
-- For every job scheduler, get the current delayed job id.
|
||||
for i = 1, #jobSchedulers, 2 do
|
||||
local jobSchedulerId = jobSchedulers[i]
|
||||
local jobSchedulerMillis = jobSchedulers[i + 1]
|
||||
local delayedJobId = "repeat:" .. jobSchedulerId .. ":" .. jobSchedulerMillis
|
||||
scheduledJobs[delayedJobId] = true
|
||||
end
|
||||
removeListJobs(KEYS[1], true, queueBaseKey, 0, scheduledJobs) -- wait
|
||||
removeListJobs(KEYS[2], true, queueBaseKey, 0, scheduledJobs) -- paused
|
||||
if ARGV[2] == "1" then
|
||||
removeZSetJobs(KEYS[3], true, queueBaseKey, 0, scheduledJobs) -- delayed
|
||||
end
|
||||
removeZSetJobs(KEYS[4], true, queueBaseKey, 0, scheduledJobs) -- prioritized
|
||||
`;
|
||||
export const drain = {
|
||||
name: 'drain',
|
||||
content,
|
||||
keys: 5,
|
||||
};
|
||||
//# sourceMappingURL=drain-5.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/drain-5.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/drain-5.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"drain-5.js","sourceRoot":"","sources":["../../../src/scripts/drain-5.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyQf,CAAC;AACF,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,OAAO;IACb,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/extendLock-2.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/extendLock-2.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const extendLock: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
27
node_modules/bullmq/dist/esm/scripts/extendLock-2.js
generated
vendored
Normal file
27
node_modules/bullmq/dist/esm/scripts/extendLock-2.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
const content = `--[[
|
||||
Extend lock and removes the job from the stalled set.
|
||||
Input:
|
||||
KEYS[1] 'lock',
|
||||
KEYS[2] 'stalled'
|
||||
ARGV[1] token
|
||||
ARGV[2] lock duration in milliseconds
|
||||
ARGV[3] jobid
|
||||
Output:
|
||||
"1" if lock extented succesfully.
|
||||
]]
|
||||
local rcall = redis.call
|
||||
if rcall("GET", KEYS[1]) == ARGV[1] then
|
||||
-- if rcall("SET", KEYS[1], ARGV[1], "PX", ARGV[2], "XX") then
|
||||
if rcall("SET", KEYS[1], ARGV[1], "PX", ARGV[2]) then
|
||||
rcall("SREM", KEYS[2], ARGV[3])
|
||||
return 1
|
||||
end
|
||||
end
|
||||
return 0
|
||||
`;
|
||||
export const extendLock = {
|
||||
name: 'extendLock',
|
||||
content,
|
||||
keys: 2,
|
||||
};
|
||||
//# sourceMappingURL=extendLock-2.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/extendLock-2.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/extendLock-2.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"extendLock-2.js","sourceRoot":"","sources":["../../../src/scripts/extendLock-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;CAoBf,CAAC;AACF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,YAAY;IAClB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/extendLocks-1.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/extendLocks-1.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const extendLocks: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
47
node_modules/bullmq/dist/esm/scripts/extendLocks-1.js
generated
vendored
Normal file
47
node_modules/bullmq/dist/esm/scripts/extendLocks-1.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
const content = `--[[
|
||||
Extend locks for multiple jobs and remove them from the stalled set if successful.
|
||||
Return the list of job IDs for which the operation failed.
|
||||
KEYS[1] = stalled key
|
||||
ARGV[1] = baseKey
|
||||
ARGV[2] = tokens
|
||||
ARGV[3] = jobIds
|
||||
ARGV[4] = lockDuration (ms)
|
||||
Output:
|
||||
An array of failed job IDs. If empty, all succeeded.
|
||||
]]
|
||||
local rcall = redis.call
|
||||
local stalledKey = KEYS[1]
|
||||
local baseKey = ARGV[1]
|
||||
local tokens = cmsgpack.unpack(ARGV[2])
|
||||
local jobIds = cmsgpack.unpack(ARGV[3])
|
||||
local lockDuration = ARGV[4]
|
||||
local jobCount = #jobIds
|
||||
local failedJobs = {}
|
||||
for i = 1, jobCount, 1 do
|
||||
local lockKey = baseKey .. jobIds[i] .. ':lock'
|
||||
local jobId = jobIds[i]
|
||||
local token = tokens[i]
|
||||
local currentToken = rcall("GET", lockKey)
|
||||
if currentToken then
|
||||
if currentToken == token then
|
||||
local setResult = rcall("SET", lockKey, token, "PX", lockDuration)
|
||||
if setResult then
|
||||
rcall("SREM", stalledKey, jobId)
|
||||
else
|
||||
table.insert(failedJobs, jobId)
|
||||
end
|
||||
else
|
||||
table.insert(failedJobs, jobId)
|
||||
end
|
||||
else
|
||||
table.insert(failedJobs, jobId)
|
||||
end
|
||||
end
|
||||
return failedJobs
|
||||
`;
|
||||
export const extendLocks = {
|
||||
name: 'extendLocks',
|
||||
content,
|
||||
keys: 1,
|
||||
};
|
||||
//# sourceMappingURL=extendLocks-1.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/extendLocks-1.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/extendLocks-1.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"extendLocks-1.js","sourceRoot":"","sources":["../../../src/scripts/extendLocks-1.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCf,CAAC;AACF,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,aAAa;IACnB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/getCounts-1.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/getCounts-1.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const getCounts: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
39
node_modules/bullmq/dist/esm/scripts/getCounts-1.js
generated
vendored
Normal file
39
node_modules/bullmq/dist/esm/scripts/getCounts-1.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
const content = `--[[
|
||||
Get counts per provided states
|
||||
Input:
|
||||
KEYS[1] 'prefix'
|
||||
ARGV[1...] types
|
||||
]]
|
||||
local rcall = redis.call;
|
||||
local prefix = KEYS[1]
|
||||
local results = {}
|
||||
for i = 1, #ARGV do
|
||||
local stateKey = prefix .. ARGV[i]
|
||||
if ARGV[i] == "wait" or ARGV[i] == "paused" then
|
||||
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
||||
local marker = rcall("LINDEX", stateKey, -1)
|
||||
if marker and string.sub(marker, 1, 2) == "0:" then
|
||||
local count = rcall("LLEN", stateKey)
|
||||
if count > 1 then
|
||||
rcall("RPOP", stateKey)
|
||||
results[#results+1] = count-1
|
||||
else
|
||||
results[#results+1] = 0
|
||||
end
|
||||
else
|
||||
results[#results+1] = rcall("LLEN", stateKey)
|
||||
end
|
||||
elseif ARGV[i] == "active" then
|
||||
results[#results+1] = rcall("LLEN", stateKey)
|
||||
else
|
||||
results[#results+1] = rcall("ZCARD", stateKey)
|
||||
end
|
||||
end
|
||||
return results
|
||||
`;
|
||||
export const getCounts = {
|
||||
name: 'getCounts',
|
||||
content,
|
||||
keys: 1,
|
||||
};
|
||||
//# sourceMappingURL=getCounts-1.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/getCounts-1.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/getCounts-1.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getCounts-1.js","sourceRoot":"","sources":["../../../src/scripts/getCounts-1.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCf,CAAC;AACF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/getCountsPerPriority-4.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/getCountsPerPriority-4.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const getCountsPerPriority: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
43
node_modules/bullmq/dist/esm/scripts/getCountsPerPriority-4.js
generated
vendored
Normal file
43
node_modules/bullmq/dist/esm/scripts/getCountsPerPriority-4.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
const content = `--[[
|
||||
Get counts per provided states
|
||||
Input:
|
||||
KEYS[1] wait key
|
||||
KEYS[2] paused key
|
||||
KEYS[3] meta key
|
||||
KEYS[4] prioritized key
|
||||
ARGV[1...] priorities
|
||||
]]
|
||||
local rcall = redis.call
|
||||
local results = {}
|
||||
local waitKey = KEYS[1]
|
||||
local pausedKey = KEYS[2]
|
||||
local prioritizedKey = KEYS[4]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function isQueuePaused(queueMetaKey)
|
||||
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
||||
end
|
||||
for i = 1, #ARGV do
|
||||
local priority = tonumber(ARGV[i])
|
||||
if priority == 0 then
|
||||
if isQueuePaused(KEYS[3]) then
|
||||
results[#results+1] = rcall("LLEN", pausedKey)
|
||||
else
|
||||
results[#results+1] = rcall("LLEN", waitKey)
|
||||
end
|
||||
else
|
||||
results[#results+1] = rcall("ZCOUNT", prioritizedKey,
|
||||
priority * 0x100000000, (priority + 1) * 0x100000000 - 1)
|
||||
end
|
||||
end
|
||||
return results
|
||||
`;
|
||||
export const getCountsPerPriority = {
|
||||
name: 'getCountsPerPriority',
|
||||
content,
|
||||
keys: 4,
|
||||
};
|
||||
//# sourceMappingURL=getCountsPerPriority-4.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/getCountsPerPriority-4.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/getCountsPerPriority-4.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getCountsPerPriority-4.js","sourceRoot":"","sources":["../../../src/scripts/getCountsPerPriority-4.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCf,CAAC;AACF,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,IAAI,EAAE,sBAAsB;IAC5B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/getDependencyCounts-4.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/getDependencyCounts-4.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const getDependencyCounts: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
34
node_modules/bullmq/dist/esm/scripts/getDependencyCounts-4.js
generated
vendored
Normal file
34
node_modules/bullmq/dist/esm/scripts/getDependencyCounts-4.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
const content = `--[[
|
||||
Get counts per child states
|
||||
Input:
|
||||
KEYS[1] processed key
|
||||
KEYS[2] unprocessed key
|
||||
KEYS[3] ignored key
|
||||
KEYS[4] failed key
|
||||
ARGV[1...] types
|
||||
]]
|
||||
local rcall = redis.call;
|
||||
local processedKey = KEYS[1]
|
||||
local unprocessedKey = KEYS[2]
|
||||
local ignoredKey = KEYS[3]
|
||||
local failedKey = KEYS[4]
|
||||
local results = {}
|
||||
for i = 1, #ARGV do
|
||||
if ARGV[i] == "processed" then
|
||||
results[#results+1] = rcall("HLEN", processedKey)
|
||||
elseif ARGV[i] == "unprocessed" then
|
||||
results[#results+1] = rcall("SCARD", unprocessedKey)
|
||||
elseif ARGV[i] == "ignored" then
|
||||
results[#results+1] = rcall("HLEN", ignoredKey)
|
||||
else
|
||||
results[#results+1] = rcall("ZCARD", failedKey)
|
||||
end
|
||||
end
|
||||
return results
|
||||
`;
|
||||
export const getDependencyCounts = {
|
||||
name: 'getDependencyCounts',
|
||||
content,
|
||||
keys: 4,
|
||||
};
|
||||
//# sourceMappingURL=getDependencyCounts-4.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/getDependencyCounts-4.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/getDependencyCounts-4.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getDependencyCounts-4.js","sourceRoot":"","sources":["../../../src/scripts/getDependencyCounts-4.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2Bf,CAAC;AACF,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,qBAAqB;IAC3B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/getJobScheduler-1.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/getJobScheduler-1.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const getJobScheduler: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
20
node_modules/bullmq/dist/esm/scripts/getJobScheduler-1.js
generated
vendored
Normal file
20
node_modules/bullmq/dist/esm/scripts/getJobScheduler-1.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
const content = `--[[
|
||||
Get job scheduler record.
|
||||
Input:
|
||||
KEYS[1] 'repeat' key
|
||||
ARGV[1] id
|
||||
]]
|
||||
local rcall = redis.call
|
||||
local jobSchedulerKey = KEYS[1] .. ":" .. ARGV[1]
|
||||
local score = rcall("ZSCORE", KEYS[1], ARGV[1])
|
||||
if score then
|
||||
return {rcall("HGETALL", jobSchedulerKey), score} -- get job data
|
||||
end
|
||||
return {nil, nil}
|
||||
`;
|
||||
export const getJobScheduler = {
|
||||
name: 'getJobScheduler',
|
||||
content,
|
||||
keys: 1,
|
||||
};
|
||||
//# sourceMappingURL=getJobScheduler-1.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/getJobScheduler-1.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/getJobScheduler-1.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getJobScheduler-1.js","sourceRoot":"","sources":["../../../src/scripts/getJobScheduler-1.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;CAaf,CAAC;AACF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,iBAAiB;IACvB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/getMetrics-2.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/getMetrics-2.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const getMetrics: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
22
node_modules/bullmq/dist/esm/scripts/getMetrics-2.js
generated
vendored
Normal file
22
node_modules/bullmq/dist/esm/scripts/getMetrics-2.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
const content = `--[[
|
||||
Get metrics
|
||||
Input:
|
||||
KEYS[1] 'metrics' key
|
||||
KEYS[2] 'metrics data' key
|
||||
ARGV[1] start index
|
||||
ARGV[2] end index
|
||||
]]
|
||||
local rcall = redis.call;
|
||||
local metricsKey = KEYS[1]
|
||||
local dataKey = KEYS[2]
|
||||
local metrics = rcall("HMGET", metricsKey, "count", "prevTS", "prevCount")
|
||||
local data = rcall("LRANGE", dataKey, tonumber(ARGV[1]), tonumber(ARGV[2]))
|
||||
local numPoints = rcall("LLEN", dataKey)
|
||||
return {metrics, data, numPoints}
|
||||
`;
|
||||
export const getMetrics = {
|
||||
name: 'getMetrics',
|
||||
content,
|
||||
keys: 2,
|
||||
};
|
||||
//# sourceMappingURL=getMetrics-2.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/getMetrics-2.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/getMetrics-2.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getMetrics-2.js","sourceRoot":"","sources":["../../../src/scripts/getMetrics-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;CAef,CAAC;AACF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,YAAY;IAClB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/getRanges-1.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/getRanges-1.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const getRanges: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
70
node_modules/bullmq/dist/esm/scripts/getRanges-1.js
generated
vendored
Normal file
70
node_modules/bullmq/dist/esm/scripts/getRanges-1.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
const content = `--[[
|
||||
Get job ids per provided states
|
||||
Input:
|
||||
KEYS[1] 'prefix'
|
||||
ARGV[1] start
|
||||
ARGV[2] end
|
||||
ARGV[3] asc
|
||||
ARGV[4...] types
|
||||
]]
|
||||
local rcall = redis.call
|
||||
local prefix = KEYS[1]
|
||||
local rangeStart = tonumber(ARGV[1])
|
||||
local rangeEnd = tonumber(ARGV[2])
|
||||
local asc = ARGV[3]
|
||||
local results = {}
|
||||
local function getRangeInList(listKey, asc, rangeStart, rangeEnd, results)
|
||||
if asc == "1" then
|
||||
local modifiedRangeStart
|
||||
local modifiedRangeEnd
|
||||
if rangeStart == -1 then
|
||||
modifiedRangeStart = 0
|
||||
else
|
||||
modifiedRangeStart = -(rangeStart + 1)
|
||||
end
|
||||
if rangeEnd == -1 then
|
||||
modifiedRangeEnd = 0
|
||||
else
|
||||
modifiedRangeEnd = -(rangeEnd + 1)
|
||||
end
|
||||
results[#results+1] = rcall("LRANGE", listKey,
|
||||
modifiedRangeEnd,
|
||||
modifiedRangeStart)
|
||||
else
|
||||
results[#results+1] = rcall("LRANGE", listKey, rangeStart, rangeEnd)
|
||||
end
|
||||
end
|
||||
for i = 4, #ARGV do
|
||||
local stateKey = prefix .. ARGV[i]
|
||||
if ARGV[i] == "wait" or ARGV[i] == "paused" then
|
||||
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
||||
local marker = rcall("LINDEX", stateKey, -1)
|
||||
if marker and string.sub(marker, 1, 2) == "0:" then
|
||||
local count = rcall("LLEN", stateKey)
|
||||
if count > 1 then
|
||||
rcall("RPOP", stateKey)
|
||||
getRangeInList(stateKey, asc, rangeStart, rangeEnd, results)
|
||||
else
|
||||
results[#results+1] = {}
|
||||
end
|
||||
else
|
||||
getRangeInList(stateKey, asc, rangeStart, rangeEnd, results)
|
||||
end
|
||||
elseif ARGV[i] == "active" then
|
||||
getRangeInList(stateKey, asc, rangeStart, rangeEnd, results)
|
||||
else
|
||||
if asc == "1" then
|
||||
results[#results+1] = rcall("ZRANGE", stateKey, rangeStart, rangeEnd)
|
||||
else
|
||||
results[#results+1] = rcall("ZREVRANGE", stateKey, rangeStart, rangeEnd)
|
||||
end
|
||||
end
|
||||
end
|
||||
return results
|
||||
`;
|
||||
export const getRanges = {
|
||||
name: 'getRanges',
|
||||
content,
|
||||
keys: 1,
|
||||
};
|
||||
//# sourceMappingURL=getRanges-1.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/getRanges-1.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/getRanges-1.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getRanges-1.js","sourceRoot":"","sources":["../../../src/scripts/getRanges-1.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Df,CAAC;AACF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/getRateLimitTtl-2.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/getRateLimitTtl-2.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const getRateLimitTtl: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
41
node_modules/bullmq/dist/esm/scripts/getRateLimitTtl-2.js
generated
vendored
Normal file
41
node_modules/bullmq/dist/esm/scripts/getRateLimitTtl-2.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
const content = `--[[
|
||||
Get rate limit ttl
|
||||
Input:
|
||||
KEYS[1] 'limiter'
|
||||
KEYS[2] 'meta'
|
||||
ARGV[1] maxJobs
|
||||
]]
|
||||
local rcall = redis.call
|
||||
-- Includes
|
||||
--[[
|
||||
Function to get current rate limit ttl.
|
||||
]]
|
||||
local function getRateLimitTTL(maxJobs, rateLimiterKey)
|
||||
if maxJobs and maxJobs <= tonumber(rcall("GET", rateLimiterKey) or 0) then
|
||||
local pttl = rcall("PTTL", rateLimiterKey)
|
||||
if pttl == 0 then
|
||||
rcall("DEL", rateLimiterKey)
|
||||
end
|
||||
if pttl > 0 then
|
||||
return pttl
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
local rateLimiterKey = KEYS[1]
|
||||
if ARGV[1] ~= "0" then
|
||||
return getRateLimitTTL(tonumber(ARGV[1]), rateLimiterKey)
|
||||
else
|
||||
local rateLimitMax = rcall("HGET", KEYS[2], "max")
|
||||
if rateLimitMax then
|
||||
return getRateLimitTTL(tonumber(rateLimitMax), rateLimiterKey)
|
||||
end
|
||||
return rcall("PTTL", rateLimiterKey)
|
||||
end
|
||||
`;
|
||||
export const getRateLimitTtl = {
|
||||
name: 'getRateLimitTtl',
|
||||
content,
|
||||
keys: 2,
|
||||
};
|
||||
//# sourceMappingURL=getRateLimitTtl-2.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/getRateLimitTtl-2.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/getRateLimitTtl-2.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getRateLimitTtl-2.js","sourceRoot":"","sources":["../../../src/scripts/getRateLimitTtl-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCf,CAAC;AACF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,iBAAiB;IACvB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/getState-8.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/getState-8.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const getState: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
70
node_modules/bullmq/dist/esm/scripts/getState-8.js
generated
vendored
Normal file
70
node_modules/bullmq/dist/esm/scripts/getState-8.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
const content = `--[[
|
||||
Get a job state
|
||||
Input:
|
||||
KEYS[1] 'completed' key,
|
||||
KEYS[2] 'failed' key
|
||||
KEYS[3] 'delayed' key
|
||||
KEYS[4] 'active' key
|
||||
KEYS[5] 'wait' key
|
||||
KEYS[6] 'paused' key
|
||||
KEYS[7] 'waiting-children' key
|
||||
KEYS[8] 'prioritized' key
|
||||
ARGV[1] job id
|
||||
Output:
|
||||
'completed'
|
||||
'failed'
|
||||
'delayed'
|
||||
'active'
|
||||
'prioritized'
|
||||
'waiting'
|
||||
'waiting-children'
|
||||
'unknown'
|
||||
]]
|
||||
local rcall = redis.call
|
||||
if rcall("ZSCORE", KEYS[1], ARGV[1]) then
|
||||
return "completed"
|
||||
end
|
||||
if rcall("ZSCORE", KEYS[2], ARGV[1]) then
|
||||
return "failed"
|
||||
end
|
||||
if rcall("ZSCORE", KEYS[3], ARGV[1]) then
|
||||
return "delayed"
|
||||
end
|
||||
if rcall("ZSCORE", KEYS[8], ARGV[1]) then
|
||||
return "prioritized"
|
||||
end
|
||||
-- Includes
|
||||
--[[
|
||||
Function to check if an item belongs to a list.
|
||||
]]
|
||||
local function checkItemInList(list, item)
|
||||
for _, v in pairs(list) do
|
||||
if v == item then
|
||||
return 1
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
local active_items = rcall("LRANGE", KEYS[4] , 0, -1)
|
||||
if checkItemInList(active_items, ARGV[1]) ~= nil then
|
||||
return "active"
|
||||
end
|
||||
local wait_items = rcall("LRANGE", KEYS[5] , 0, -1)
|
||||
if checkItemInList(wait_items, ARGV[1]) ~= nil then
|
||||
return "waiting"
|
||||
end
|
||||
local paused_items = rcall("LRANGE", KEYS[6] , 0, -1)
|
||||
if checkItemInList(paused_items, ARGV[1]) ~= nil then
|
||||
return "waiting"
|
||||
end
|
||||
if rcall("ZSCORE", KEYS[7], ARGV[1]) then
|
||||
return "waiting-children"
|
||||
end
|
||||
return "unknown"
|
||||
`;
|
||||
export const getState = {
|
||||
name: 'getState',
|
||||
content,
|
||||
keys: 8,
|
||||
};
|
||||
//# sourceMappingURL=getState-8.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/getState-8.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/getState-8.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getState-8.js","sourceRoot":"","sources":["../../../src/scripts/getState-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Df,CAAC;AACF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,UAAU;IAChB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/getStateV2-8.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/getStateV2-8.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const getStateV2: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
54
node_modules/bullmq/dist/esm/scripts/getStateV2-8.js
generated
vendored
Normal file
54
node_modules/bullmq/dist/esm/scripts/getStateV2-8.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
const content = `--[[
|
||||
Get a job state
|
||||
Input:
|
||||
KEYS[1] 'completed' key,
|
||||
KEYS[2] 'failed' key
|
||||
KEYS[3] 'delayed' key
|
||||
KEYS[4] 'active' key
|
||||
KEYS[5] 'wait' key
|
||||
KEYS[6] 'paused' key
|
||||
KEYS[7] 'waiting-children' key
|
||||
KEYS[8] 'prioritized' key
|
||||
ARGV[1] job id
|
||||
Output:
|
||||
'completed'
|
||||
'failed'
|
||||
'delayed'
|
||||
'active'
|
||||
'waiting'
|
||||
'waiting-children'
|
||||
'unknown'
|
||||
]]
|
||||
local rcall = redis.call
|
||||
if rcall("ZSCORE", KEYS[1], ARGV[1]) then
|
||||
return "completed"
|
||||
end
|
||||
if rcall("ZSCORE", KEYS[2], ARGV[1]) then
|
||||
return "failed"
|
||||
end
|
||||
if rcall("ZSCORE", KEYS[3], ARGV[1]) then
|
||||
return "delayed"
|
||||
end
|
||||
if rcall("ZSCORE", KEYS[8], ARGV[1]) then
|
||||
return "prioritized"
|
||||
end
|
||||
if rcall("LPOS", KEYS[4] , ARGV[1]) then
|
||||
return "active"
|
||||
end
|
||||
if rcall("LPOS", KEYS[5] , ARGV[1]) then
|
||||
return "waiting"
|
||||
end
|
||||
if rcall("LPOS", KEYS[6] , ARGV[1]) then
|
||||
return "waiting"
|
||||
end
|
||||
if rcall("ZSCORE", KEYS[7] , ARGV[1]) then
|
||||
return "waiting-children"
|
||||
end
|
||||
return "unknown"
|
||||
`;
|
||||
export const getStateV2 = {
|
||||
name: 'getStateV2',
|
||||
content,
|
||||
keys: 8,
|
||||
};
|
||||
//# sourceMappingURL=getStateV2-8.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/getStateV2-8.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/getStateV2-8.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getStateV2-8.js","sourceRoot":"","sources":["../../../src/scripts/getStateV2-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Cf,CAAC;AACF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,YAAY;IAClB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
51
node_modules/bullmq/dist/esm/scripts/index.d.ts
generated
vendored
Normal file
51
node_modules/bullmq/dist/esm/scripts/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
export * from './addDelayedJob-6';
|
||||
export * from './addJobScheduler-11';
|
||||
export * from './addLog-2';
|
||||
export * from './addParentJob-6';
|
||||
export * from './addPrioritizedJob-9';
|
||||
export * from './addRepeatableJob-2';
|
||||
export * from './addStandardJob-9';
|
||||
export * from './changeDelay-4';
|
||||
export * from './changePriority-7';
|
||||
export * from './cleanJobsInSet-3';
|
||||
export * from './drain-5';
|
||||
export * from './extendLock-2';
|
||||
export * from './extendLocks-1';
|
||||
export * from './getCounts-1';
|
||||
export * from './getCountsPerPriority-4';
|
||||
export * from './getDependencyCounts-4';
|
||||
export * from './getJobScheduler-1';
|
||||
export * from './getMetrics-2';
|
||||
export * from './getRanges-1';
|
||||
export * from './getRateLimitTtl-2';
|
||||
export * from './getState-8';
|
||||
export * from './getStateV2-8';
|
||||
export * from './isFinished-3';
|
||||
export * from './isJobInList-1';
|
||||
export * from './isMaxed-2';
|
||||
export * from './moveJobFromActiveToWait-9';
|
||||
export * from './moveJobsToWait-8';
|
||||
export * from './moveStalledJobsToWait-8';
|
||||
export * from './moveToActive-11';
|
||||
export * from './moveToDelayed-12';
|
||||
export * from './moveToFinished-14';
|
||||
export * from './moveToWaitingChildren-7';
|
||||
export * from './obliterate-2';
|
||||
export * from './paginate-1';
|
||||
export * from './pause-7';
|
||||
export * from './promote-9';
|
||||
export * from './releaseLock-1';
|
||||
export * from './removeChildDependency-1';
|
||||
export * from './removeDeduplicationKey-1';
|
||||
export * from './removeJob-2';
|
||||
export * from './removeJobScheduler-3';
|
||||
export * from './removeOrphanedJobs-1';
|
||||
export * from './removeRepeatable-3';
|
||||
export * from './removeUnprocessedChildren-2';
|
||||
export * from './reprocessJob-8';
|
||||
export * from './retryJob-11';
|
||||
export * from './saveStacktrace-1';
|
||||
export * from './updateData-1';
|
||||
export * from './updateJobScheduler-12';
|
||||
export * from './updateProgress-3';
|
||||
export * from './updateRepeatableJobMillis-1';
|
||||
52
node_modules/bullmq/dist/esm/scripts/index.js
generated
vendored
Normal file
52
node_modules/bullmq/dist/esm/scripts/index.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
export * from './addDelayedJob-6';
|
||||
export * from './addJobScheduler-11';
|
||||
export * from './addLog-2';
|
||||
export * from './addParentJob-6';
|
||||
export * from './addPrioritizedJob-9';
|
||||
export * from './addRepeatableJob-2';
|
||||
export * from './addStandardJob-9';
|
||||
export * from './changeDelay-4';
|
||||
export * from './changePriority-7';
|
||||
export * from './cleanJobsInSet-3';
|
||||
export * from './drain-5';
|
||||
export * from './extendLock-2';
|
||||
export * from './extendLocks-1';
|
||||
export * from './getCounts-1';
|
||||
export * from './getCountsPerPriority-4';
|
||||
export * from './getDependencyCounts-4';
|
||||
export * from './getJobScheduler-1';
|
||||
export * from './getMetrics-2';
|
||||
export * from './getRanges-1';
|
||||
export * from './getRateLimitTtl-2';
|
||||
export * from './getState-8';
|
||||
export * from './getStateV2-8';
|
||||
export * from './isFinished-3';
|
||||
export * from './isJobInList-1';
|
||||
export * from './isMaxed-2';
|
||||
export * from './moveJobFromActiveToWait-9';
|
||||
export * from './moveJobsToWait-8';
|
||||
export * from './moveStalledJobsToWait-8';
|
||||
export * from './moveToActive-11';
|
||||
export * from './moveToDelayed-12';
|
||||
export * from './moveToFinished-14';
|
||||
export * from './moveToWaitingChildren-7';
|
||||
export * from './obliterate-2';
|
||||
export * from './paginate-1';
|
||||
export * from './pause-7';
|
||||
export * from './promote-9';
|
||||
export * from './releaseLock-1';
|
||||
export * from './removeChildDependency-1';
|
||||
export * from './removeDeduplicationKey-1';
|
||||
export * from './removeJob-2';
|
||||
export * from './removeJobScheduler-3';
|
||||
export * from './removeOrphanedJobs-1';
|
||||
export * from './removeRepeatable-3';
|
||||
export * from './removeUnprocessedChildren-2';
|
||||
export * from './reprocessJob-8';
|
||||
export * from './retryJob-11';
|
||||
export * from './saveStacktrace-1';
|
||||
export * from './updateData-1';
|
||||
export * from './updateJobScheduler-12';
|
||||
export * from './updateProgress-3';
|
||||
export * from './updateRepeatableJobMillis-1';
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/index.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/isFinished-3.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/isFinished-3.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const isFinished: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
46
node_modules/bullmq/dist/esm/scripts/isFinished-3.js
generated
vendored
Normal file
46
node_modules/bullmq/dist/esm/scripts/isFinished-3.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
const content = `--[[
|
||||
Checks if a job is finished (.i.e. is in the completed or failed set)
|
||||
Input:
|
||||
KEYS[1] completed key
|
||||
KEYS[2] failed key
|
||||
KEYS[3] job key
|
||||
ARGV[1] job id
|
||||
ARGV[2] return value?
|
||||
Output:
|
||||
0 - Not finished.
|
||||
1 - Completed.
|
||||
2 - Failed.
|
||||
-1 - Missing job.
|
||||
]]
|
||||
local rcall = redis.call
|
||||
if rcall("EXISTS", KEYS[3]) ~= 1 then
|
||||
if ARGV[2] == "1" then
|
||||
return {-1,"Missing key for job " .. KEYS[3] .. ". isFinished"}
|
||||
end
|
||||
return -1
|
||||
end
|
||||
if rcall("ZSCORE", KEYS[1], ARGV[1]) then
|
||||
if ARGV[2] == "1" then
|
||||
local returnValue = rcall("HGET", KEYS[3], "returnvalue")
|
||||
return {1,returnValue}
|
||||
end
|
||||
return 1
|
||||
end
|
||||
if rcall("ZSCORE", KEYS[2], ARGV[1]) then
|
||||
if ARGV[2] == "1" then
|
||||
local failedReason = rcall("HGET", KEYS[3], "failedReason")
|
||||
return {2,failedReason}
|
||||
end
|
||||
return 2
|
||||
end
|
||||
if ARGV[2] == "1" then
|
||||
return {0}
|
||||
end
|
||||
return 0
|
||||
`;
|
||||
export const isFinished = {
|
||||
name: 'isFinished',
|
||||
content,
|
||||
keys: 3,
|
||||
};
|
||||
//# sourceMappingURL=isFinished-3.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/isFinished-3.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/isFinished-3.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"isFinished-3.js","sourceRoot":"","sources":["../../../src/scripts/isFinished-3.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCf,CAAC;AACF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,YAAY;IAClB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/isJobInList-1.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/isJobInList-1.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const isJobInList: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
29
node_modules/bullmq/dist/esm/scripts/isJobInList-1.js
generated
vendored
Normal file
29
node_modules/bullmq/dist/esm/scripts/isJobInList-1.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
const content = `--[[
|
||||
Checks if job is in a given list.
|
||||
Input:
|
||||
KEYS[1]
|
||||
ARGV[1]
|
||||
Output:
|
||||
1 if element found in the list.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to check if an item belongs to a list.
|
||||
]]
|
||||
local function checkItemInList(list, item)
|
||||
for _, v in pairs(list) do
|
||||
if v == item then
|
||||
return 1
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
local items = redis.call("LRANGE", KEYS[1] , 0, -1)
|
||||
return checkItemInList(items, ARGV[1])
|
||||
`;
|
||||
export const isJobInList = {
|
||||
name: 'isJobInList',
|
||||
content,
|
||||
keys: 1,
|
||||
};
|
||||
//# sourceMappingURL=isJobInList-1.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/isJobInList-1.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/isJobInList-1.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"isJobInList-1.js","sourceRoot":"","sources":["../../../src/scripts/isJobInList-1.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;CAsBf,CAAC;AACF,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,aAAa;IACnB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/isMaxed-2.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/isMaxed-2.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const isMaxed: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
31
node_modules/bullmq/dist/esm/scripts/isMaxed-2.js
generated
vendored
Normal file
31
node_modules/bullmq/dist/esm/scripts/isMaxed-2.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
const content = `--[[
|
||||
Checks if queue is maxed.
|
||||
Input:
|
||||
KEYS[1] meta key
|
||||
KEYS[2] active key
|
||||
Output:
|
||||
1 if element found in the list.
|
||||
]]
|
||||
local rcall = redis.call
|
||||
-- Includes
|
||||
--[[
|
||||
Function to check if queue is maxed or not.
|
||||
]]
|
||||
local function isQueueMaxed(queueMetaKey, activeKey)
|
||||
local maxConcurrency = rcall("HGET", queueMetaKey, "concurrency")
|
||||
if maxConcurrency then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(maxConcurrency) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
return isQueueMaxed(KEYS[1], KEYS[2])
|
||||
`;
|
||||
export const isMaxed = {
|
||||
name: 'isMaxed',
|
||||
content,
|
||||
keys: 2,
|
||||
};
|
||||
//# sourceMappingURL=isMaxed-2.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/isMaxed-2.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/isMaxed-2.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"isMaxed-2.js","sourceRoot":"","sources":["../../../src/scripts/isMaxed-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;CAwBf,CAAC;AACF,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,IAAI,EAAE,SAAS;IACf,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/moveJobFromActiveToWait-9.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/moveJobFromActiveToWait-9.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const moveJobFromActiveToWait: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
131
node_modules/bullmq/dist/esm/scripts/moveJobFromActiveToWait-9.js
generated
vendored
Normal file
131
node_modules/bullmq/dist/esm/scripts/moveJobFromActiveToWait-9.js
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
const content = `--[[
|
||||
Function to move job from active state to wait.
|
||||
Input:
|
||||
KEYS[1] active key
|
||||
KEYS[2] wait key
|
||||
KEYS[3] stalled key
|
||||
KEYS[4] paused key
|
||||
KEYS[5] meta key
|
||||
KEYS[6] limiter key
|
||||
KEYS[7] prioritized key
|
||||
KEYS[8] marker key
|
||||
KEYS[9] event key
|
||||
ARGV[1] job id
|
||||
ARGV[2] lock token
|
||||
ARGV[3] job id key
|
||||
]]
|
||||
local rcall = redis.call
|
||||
-- Includes
|
||||
--[[
|
||||
Function to add job in target list and add marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall(pushCmd, targetKey, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to push back job considering priority in front of same prioritized jobs.
|
||||
]]
|
||||
local function pushBackJobWithPriority(prioritizedKey, priority, jobId)
|
||||
-- in order to put it at front of same prioritized jobs
|
||||
-- we consider prioritized counter as 0
|
||||
local score = priority * 0x100000000
|
||||
rcall("ZADD", prioritizedKey, score, jobId)
|
||||
end
|
||||
--[[
|
||||
Function to get max events value or set by default 10000.
|
||||
]]
|
||||
local function getOrSetMaxEvents(metaKey)
|
||||
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
||||
if not maxEvents then
|
||||
maxEvents = 10000
|
||||
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
||||
end
|
||||
return maxEvents
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
local function removeLock(jobKey, stalledKey, token, jobId)
|
||||
if token ~= "0" then
|
||||
local lockKey = jobKey .. ':lock'
|
||||
local lockToken = rcall("GET", lockKey)
|
||||
if lockToken == token then
|
||||
rcall("DEL", lockKey)
|
||||
rcall("SREM", stalledKey, jobId)
|
||||
else
|
||||
if lockToken then
|
||||
-- Lock exists but token does not match
|
||||
return -6
|
||||
else
|
||||
-- Lock is missing completely
|
||||
return -2
|
||||
end
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
local jobId = ARGV[1]
|
||||
local token = ARGV[2]
|
||||
local jobKey = ARGV[3]
|
||||
if rcall("EXISTS", jobKey) == 0 then
|
||||
return -1
|
||||
end
|
||||
local errorCode = removeLock(jobKey, KEYS[3], token, jobId)
|
||||
if errorCode < 0 then
|
||||
return errorCode
|
||||
end
|
||||
local metaKey = KEYS[5]
|
||||
local removed = rcall("LREM", KEYS[1], 1, jobId)
|
||||
if removed > 0 then
|
||||
local target, isPausedOrMaxed = getTargetQueueList(metaKey, KEYS[1], KEYS[2], KEYS[4])
|
||||
local priority = tonumber(rcall("HGET", ARGV[3], "priority")) or 0
|
||||
if priority > 0 then
|
||||
pushBackJobWithPriority(KEYS[7], priority, jobId)
|
||||
else
|
||||
addJobInTargetList(target, KEYS[8], "RPUSH", isPausedOrMaxed, jobId)
|
||||
end
|
||||
local maxEvents = getOrSetMaxEvents(metaKey)
|
||||
-- Emit waiting event
|
||||
rcall("XADD", KEYS[9], "MAXLEN", "~", maxEvents, "*", "event", "waiting",
|
||||
"jobId", jobId, "prev", "active")
|
||||
end
|
||||
local pttl = rcall("PTTL", KEYS[6])
|
||||
if pttl > 0 then
|
||||
return pttl
|
||||
else
|
||||
return 0
|
||||
end
|
||||
`;
|
||||
export const moveJobFromActiveToWait = {
|
||||
name: 'moveJobFromActiveToWait',
|
||||
content,
|
||||
keys: 9,
|
||||
};
|
||||
//# sourceMappingURL=moveJobFromActiveToWait-9.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/moveJobFromActiveToWait-9.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/moveJobFromActiveToWait-9.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"moveJobFromActiveToWait-9.js","sourceRoot":"","sources":["../../../src/scripts/moveJobFromActiveToWait-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Hf,CAAC;AACF,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,IAAI,EAAE,yBAAyB;IAC/B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/moveJobsToWait-8.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/moveJobsToWait-8.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const moveJobsToWait: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
115
node_modules/bullmq/dist/esm/scripts/moveJobsToWait-8.js
generated
vendored
Normal file
115
node_modules/bullmq/dist/esm/scripts/moveJobsToWait-8.js
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
const content = `--[[
|
||||
Move completed, failed or delayed jobs to wait.
|
||||
Note: Does not support jobs with priorities.
|
||||
Input:
|
||||
KEYS[1] base key
|
||||
KEYS[2] events stream
|
||||
KEYS[3] state key (failed, completed, delayed)
|
||||
KEYS[4] 'wait'
|
||||
KEYS[5] 'paused'
|
||||
KEYS[6] 'meta'
|
||||
KEYS[7] 'active'
|
||||
KEYS[8] 'marker'
|
||||
ARGV[1] count
|
||||
ARGV[2] timestamp
|
||||
ARGV[3] prev state
|
||||
Output:
|
||||
1 means the operation is not completed
|
||||
0 means the operation is completed
|
||||
]]
|
||||
local maxCount = tonumber(ARGV[1])
|
||||
local timestamp = tonumber(ARGV[2])
|
||||
local rcall = redis.call;
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to loop in batches.
|
||||
Just a bit of warning, some commands as ZREM
|
||||
could receive a maximum of 7000 parameters per call.
|
||||
]]
|
||||
local function batches(n, batchSize)
|
||||
local i = 0
|
||||
return function()
|
||||
local from = i * batchSize + 1
|
||||
i = i + 1
|
||||
if (from <= n) then
|
||||
local to = math.min(from + batchSize - 1, n)
|
||||
return from, to
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to get max events value or set by default 10000.
|
||||
]]
|
||||
local function getOrSetMaxEvents(metaKey)
|
||||
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
||||
if not maxEvents then
|
||||
maxEvents = 10000
|
||||
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
||||
end
|
||||
return maxEvents
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
local metaKey = KEYS[6]
|
||||
local target, isPausedOrMaxed = getTargetQueueList(metaKey, KEYS[7], KEYS[4], KEYS[5])
|
||||
local jobs = rcall('ZRANGEBYSCORE', KEYS[3], 0, timestamp, 'LIMIT', 0, maxCount)
|
||||
if (#jobs > 0) then
|
||||
if ARGV[3] == "failed" then
|
||||
for i, key in ipairs(jobs) do
|
||||
local jobKey = KEYS[1] .. key
|
||||
rcall("HDEL", jobKey, "finishedOn", "processedOn", "failedReason")
|
||||
end
|
||||
elseif ARGV[3] == "completed" then
|
||||
for i, key in ipairs(jobs) do
|
||||
local jobKey = KEYS[1] .. key
|
||||
rcall("HDEL", jobKey, "finishedOn", "processedOn", "returnvalue")
|
||||
end
|
||||
end
|
||||
local maxEvents = getOrSetMaxEvents(metaKey)
|
||||
for i, key in ipairs(jobs) do
|
||||
-- Emit waiting event
|
||||
rcall("XADD", KEYS[2], "MAXLEN", "~", maxEvents, "*", "event",
|
||||
"waiting", "jobId", key, "prev", ARGV[3]);
|
||||
end
|
||||
for from, to in batches(#jobs, 7000) do
|
||||
rcall("ZREM", KEYS[3], unpack(jobs, from, to))
|
||||
rcall("LPUSH", target, unpack(jobs, from, to))
|
||||
end
|
||||
addBaseMarkerIfNeeded(KEYS[8], isPausedOrMaxed)
|
||||
end
|
||||
maxCount = maxCount - #jobs
|
||||
if (maxCount <= 0) then return 1 end
|
||||
return 0
|
||||
`;
|
||||
export const moveJobsToWait = {
|
||||
name: 'moveJobsToWait',
|
||||
content,
|
||||
keys: 8,
|
||||
};
|
||||
//# sourceMappingURL=moveJobsToWait-8.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/moveJobsToWait-8.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/moveJobsToWait-8.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"moveJobsToWait-8.js","sourceRoot":"","sources":["../../../src/scripts/moveJobsToWait-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Gf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/moveStalledJobsToWait-8.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/moveStalledJobsToWait-8.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const moveStalledJobsToWait: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
182
node_modules/bullmq/dist/esm/scripts/moveStalledJobsToWait-8.js
generated
vendored
Normal file
182
node_modules/bullmq/dist/esm/scripts/moveStalledJobsToWait-8.js
generated
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
const content = `--[[
|
||||
Move stalled jobs to wait.
|
||||
Input:
|
||||
KEYS[1] 'stalled' (SET)
|
||||
KEYS[2] 'wait', (LIST)
|
||||
KEYS[3] 'active', (LIST)
|
||||
KEYS[4] 'stalled-check', (KEY)
|
||||
KEYS[5] 'meta', (KEY)
|
||||
KEYS[6] 'paused', (LIST)
|
||||
KEYS[7] 'marker'
|
||||
KEYS[8] 'event stream' (STREAM)
|
||||
ARGV[1] Max stalled job count
|
||||
ARGV[2] queue.toKey('')
|
||||
ARGV[3] timestamp
|
||||
ARGV[4] max check time
|
||||
Events:
|
||||
'stalled' with stalled job id.
|
||||
]]
|
||||
local rcall = redis.call
|
||||
-- Includes
|
||||
--[[
|
||||
Function to add job in target list and add marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall(pushCmd, targetKey, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to loop in batches.
|
||||
Just a bit of warning, some commands as ZREM
|
||||
could receive a maximum of 7000 parameters per call.
|
||||
]]
|
||||
local function batches(n, batchSize)
|
||||
local i = 0
|
||||
return function()
|
||||
local from = i * batchSize + 1
|
||||
i = i + 1
|
||||
if (from <= n) then
|
||||
local to = math.min(from + batchSize - 1, n)
|
||||
return from, to
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to move job to wait to be picked up by a waiting worker.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
local function moveJobToWait(metaKey, activeKey, waitKey, pausedKey, markerKey, eventStreamKey,
|
||||
jobId, pushCmd)
|
||||
local target, isPausedOrMaxed = getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
|
||||
addJobInTargetList(target, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId", jobId, 'prev', 'active')
|
||||
end
|
||||
--[[
|
||||
Function to trim events, default 10000.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to get max events value or set by default 10000.
|
||||
]]
|
||||
local function getOrSetMaxEvents(metaKey)
|
||||
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
||||
if not maxEvents then
|
||||
maxEvents = 10000
|
||||
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
||||
end
|
||||
return maxEvents
|
||||
end
|
||||
local function trimEvents(metaKey, eventStreamKey)
|
||||
local maxEvents = getOrSetMaxEvents(metaKey)
|
||||
if maxEvents then
|
||||
rcall("XTRIM", eventStreamKey, "MAXLEN", "~", maxEvents)
|
||||
else
|
||||
rcall("XTRIM", eventStreamKey, "MAXLEN", "~", 10000)
|
||||
end
|
||||
end
|
||||
local stalledKey = KEYS[1]
|
||||
local waitKey = KEYS[2]
|
||||
local activeKey = KEYS[3]
|
||||
local stalledCheckKey = KEYS[4]
|
||||
local metaKey = KEYS[5]
|
||||
local pausedKey = KEYS[6]
|
||||
local markerKey = KEYS[7]
|
||||
local eventStreamKey = KEYS[8]
|
||||
local maxStalledJobCount = tonumber(ARGV[1])
|
||||
local queueKeyPrefix = ARGV[2]
|
||||
local timestamp = ARGV[3]
|
||||
local maxCheckTime = ARGV[4]
|
||||
if rcall("EXISTS", stalledCheckKey) == 1 then
|
||||
return {}
|
||||
end
|
||||
rcall("SET", stalledCheckKey, timestamp, "PX", maxCheckTime)
|
||||
-- Trim events before emiting them to avoid trimming events emitted in this script
|
||||
trimEvents(metaKey, eventStreamKey)
|
||||
-- Move all stalled jobs to wait
|
||||
local stalling = rcall('SMEMBERS', stalledKey)
|
||||
local stalled = {}
|
||||
if (#stalling > 0) then
|
||||
rcall('DEL', stalledKey)
|
||||
-- Remove from active list
|
||||
for i, jobId in ipairs(stalling) do
|
||||
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
||||
if string.sub(jobId, 1, 2) == "0:" then
|
||||
-- If the jobId is a delay marker ID we just remove it.
|
||||
rcall("LREM", activeKey, 1, jobId)
|
||||
else
|
||||
local jobKey = queueKeyPrefix .. jobId
|
||||
-- Check that the lock is also missing, then we can handle this job as really stalled.
|
||||
if (rcall("EXISTS", jobKey .. ":lock") == 0) then
|
||||
-- Remove from the active queue.
|
||||
local removed = rcall("LREM", activeKey, 1, jobId)
|
||||
if (removed > 0) then
|
||||
-- If this job has been stalled too many times, such as if it crashes the worker, then fail it.
|
||||
local stalledCount = rcall("HINCRBY", jobKey, "stc", 1)
|
||||
-- Check if this is a repeatable job by looking at job options
|
||||
local jobOpts = rcall("HGET", jobKey, "opts")
|
||||
local isRepeatableJob = false
|
||||
if jobOpts then
|
||||
local opts = cjson.decode(jobOpts)
|
||||
if opts and opts["repeat"] then
|
||||
isRepeatableJob = true
|
||||
end
|
||||
end
|
||||
-- Only fail job if it exceeds stall limit AND is not a repeatable job
|
||||
if stalledCount > maxStalledJobCount and not isRepeatableJob then
|
||||
local failedReason = "job stalled more than allowable limit"
|
||||
rcall("HSET", jobKey, "defa", failedReason)
|
||||
end
|
||||
moveJobToWait(metaKey, activeKey, waitKey, pausedKey, markerKey, eventStreamKey, jobId,
|
||||
"RPUSH")
|
||||
-- Emit the stalled event
|
||||
rcall("XADD", eventStreamKey, "*", "event", "stalled", "jobId", jobId)
|
||||
table.insert(stalled, jobId)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Mark potentially stalled jobs
|
||||
local active = rcall('LRANGE', activeKey, 0, -1)
|
||||
if (#active > 0) then
|
||||
for from, to in batches(#active, 7000) do
|
||||
rcall('SADD', stalledKey, unpack(active, from, to))
|
||||
end
|
||||
end
|
||||
return stalled
|
||||
`;
|
||||
export const moveStalledJobsToWait = {
|
||||
name: 'moveStalledJobsToWait',
|
||||
content,
|
||||
keys: 8,
|
||||
};
|
||||
//# sourceMappingURL=moveStalledJobsToWait-8.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/moveStalledJobsToWait-8.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/moveStalledJobsToWait-8.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"moveStalledJobsToWait-8.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Kf,CAAC;AACF,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/moveToActive-11.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/moveToActive-11.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const moveToActive: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
241
node_modules/bullmq/dist/esm/scripts/moveToActive-11.js
generated
vendored
Normal file
241
node_modules/bullmq/dist/esm/scripts/moveToActive-11.js
generated
vendored
Normal file
@@ -0,0 +1,241 @@
|
||||
const content = `--[[
|
||||
Move next job to be processed to active, lock it and fetch its data. The job
|
||||
may be delayed, in that case we need to move it to the delayed set instead.
|
||||
This operation guarantees that the worker owns the job during the lock
|
||||
expiration time. The worker is responsible of keeping the lock fresh
|
||||
so that no other worker picks this job again.
|
||||
Input:
|
||||
KEYS[1] wait key
|
||||
KEYS[2] active key
|
||||
KEYS[3] prioritized key
|
||||
KEYS[4] stream events key
|
||||
KEYS[5] stalled key
|
||||
-- Rate limiting
|
||||
KEYS[6] rate limiter key
|
||||
KEYS[7] delayed key
|
||||
-- Delayed jobs
|
||||
KEYS[8] paused key
|
||||
KEYS[9] meta key
|
||||
KEYS[10] pc priority counter
|
||||
-- Marker
|
||||
KEYS[11] marker key
|
||||
-- Arguments
|
||||
ARGV[1] key prefix
|
||||
ARGV[2] timestamp
|
||||
ARGV[3] opts
|
||||
opts - token - lock token
|
||||
opts - lockDuration
|
||||
opts - limiter
|
||||
opts - name - worker name
|
||||
]]
|
||||
local rcall = redis.call
|
||||
local waitKey = KEYS[1]
|
||||
local activeKey = KEYS[2]
|
||||
local eventStreamKey = KEYS[4]
|
||||
local rateLimiterKey = KEYS[6]
|
||||
local delayedKey = KEYS[7]
|
||||
local opts = cmsgpack.unpack(ARGV[3])
|
||||
-- Includes
|
||||
--[[
|
||||
Function to return the next delayed job timestamp.
|
||||
]]
|
||||
local function getNextDelayedTimestamp(delayedKey)
|
||||
local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
|
||||
if #result then
|
||||
local nextTimestamp = tonumber(result[2])
|
||||
if nextTimestamp ~= nil then
|
||||
return nextTimestamp / 0x1000
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to get current rate limit ttl.
|
||||
]]
|
||||
local function getRateLimitTTL(maxJobs, rateLimiterKey)
|
||||
if maxJobs and maxJobs <= tonumber(rcall("GET", rateLimiterKey) or 0) then
|
||||
local pttl = rcall("PTTL", rateLimiterKey)
|
||||
if pttl == 0 then
|
||||
rcall("DEL", rateLimiterKey)
|
||||
end
|
||||
if pttl > 0 then
|
||||
return pttl
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
--[[
|
||||
Function to move job from prioritized state to active.
|
||||
]]
|
||||
local function moveJobFromPrioritizedToActive(priorityKey, activeKey, priorityCounterKey)
|
||||
local prioritizedJob = rcall("ZPOPMIN", priorityKey)
|
||||
if #prioritizedJob > 0 then
|
||||
rcall("LPUSH", activeKey, prioritizedJob[1])
|
||||
return prioritizedJob[1]
|
||||
else
|
||||
rcall("DEL", priorityCounterKey)
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to move job from wait state to active.
|
||||
Input:
|
||||
opts - token - lock token
|
||||
opts - lockDuration
|
||||
opts - limiter
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
local function prepareJobForProcessing(keyPrefix, rateLimiterKey, eventStreamKey,
|
||||
jobId, processedOn, maxJobs, limiterDuration, markerKey, opts)
|
||||
local jobKey = keyPrefix .. jobId
|
||||
-- Check if we need to perform rate limiting.
|
||||
if maxJobs then
|
||||
local jobCounter = tonumber(rcall("INCR", rateLimiterKey))
|
||||
if jobCounter == 1 then
|
||||
local integerDuration = math.floor(math.abs(limiterDuration))
|
||||
rcall("PEXPIRE", rateLimiterKey, integerDuration)
|
||||
end
|
||||
end
|
||||
-- get a lock
|
||||
if opts['token'] ~= "0" then
|
||||
local lockKey = jobKey .. ':lock'
|
||||
rcall("SET", lockKey, opts['token'], "PX", opts['lockDuration'])
|
||||
end
|
||||
local optionalValues = {}
|
||||
if opts['name'] then
|
||||
-- Set "processedBy" field to the worker name
|
||||
table.insert(optionalValues, "pb")
|
||||
table.insert(optionalValues, opts['name'])
|
||||
end
|
||||
rcall("XADD", eventStreamKey, "*", "event", "active", "jobId", jobId, "prev", "waiting")
|
||||
rcall("HMSET", jobKey, "processedOn", processedOn, unpack(optionalValues))
|
||||
rcall("HINCRBY", jobKey, "ats", 1)
|
||||
addBaseMarkerIfNeeded(markerKey, false)
|
||||
-- rate limit delay must be 0 in this case to prevent adding more delay
|
||||
-- when job that is moved to active needs to be processed
|
||||
return {rcall("HGETALL", jobKey), jobId, 0, 0} -- get job data
|
||||
end
|
||||
--[[
|
||||
Updates the delay set, by moving delayed jobs that should
|
||||
be processed now to "wait".
|
||||
Events:
|
||||
'waiting'
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to add job in target list and add marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall(pushCmd, targetKey, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to add job considering priority.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to get priority score.
|
||||
]]
|
||||
local function getPriorityScore(priority, priorityCounterKey)
|
||||
local prioCounter = rcall("INCR", priorityCounterKey)
|
||||
return priority * 0x100000000 + prioCounter % 0x100000000
|
||||
end
|
||||
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
|
||||
isPausedOrMaxed)
|
||||
local score = getPriorityScore(priority, priorityCounterKey)
|
||||
rcall("ZADD", prioritizedKey, score, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
-- Try to get as much as 1000 jobs at once
|
||||
local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedKey,
|
||||
eventStreamKey, prefix, timestamp, priorityCounterKey, isPaused)
|
||||
local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000 - 1, "LIMIT", 0, 1000)
|
||||
if (#jobs > 0) then
|
||||
rcall("ZREM", delayedKey, unpack(jobs))
|
||||
for _, jobId in ipairs(jobs) do
|
||||
local jobKey = prefix .. jobId
|
||||
local priority =
|
||||
tonumber(rcall("HGET", jobKey, "priority")) or 0
|
||||
if priority == 0 then
|
||||
-- LIFO or FIFO
|
||||
rcall("LPUSH", targetKey, jobId)
|
||||
else
|
||||
local score = getPriorityScore(priority, priorityCounterKey)
|
||||
rcall("ZADD", prioritizedKey, score, jobId)
|
||||
end
|
||||
-- Emit waiting event
|
||||
rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId",
|
||||
jobId, "prev", "delayed")
|
||||
rcall("HSET", jobKey, "delay", 0)
|
||||
end
|
||||
addBaseMarkerIfNeeded(markerKey, isPaused)
|
||||
end
|
||||
end
|
||||
local target, isPausedOrMaxed, rateLimitMax, rateLimitDuration = getTargetQueueList(KEYS[9],
|
||||
activeKey, waitKey, KEYS[8])
|
||||
-- Check if there are delayed jobs that we can move to wait.
|
||||
local markerKey = KEYS[11]
|
||||
promoteDelayedJobs(delayedKey, markerKey, target, KEYS[3], eventStreamKey, ARGV[1],
|
||||
ARGV[2], KEYS[10], isPausedOrMaxed)
|
||||
local maxJobs = tonumber(rateLimitMax or (opts['limiter'] and opts['limiter']['max']))
|
||||
local expireTime = getRateLimitTTL(maxJobs, rateLimiterKey)
|
||||
-- Check if we are rate limited first.
|
||||
if expireTime > 0 then return {0, 0, expireTime, 0} end
|
||||
-- paused or maxed queue
|
||||
if isPausedOrMaxed then return {0, 0, 0, 0} end
|
||||
local limiterDuration = (opts['limiter'] and opts['limiter']['duration']) or rateLimitDuration
|
||||
-- no job ID, try non-blocking move from wait to active
|
||||
local jobId = rcall("RPOPLPUSH", waitKey, activeKey)
|
||||
-- Markers in waitlist DEPRECATED in v5: Will be completely removed in v6.
|
||||
if jobId and string.sub(jobId, 1, 2) == "0:" then
|
||||
rcall("LREM", activeKey, 1, jobId)
|
||||
jobId = rcall("RPOPLPUSH", waitKey, activeKey)
|
||||
end
|
||||
if jobId then
|
||||
return prepareJobForProcessing(ARGV[1], rateLimiterKey, eventStreamKey, jobId, ARGV[2],
|
||||
maxJobs, limiterDuration, markerKey, opts)
|
||||
else
|
||||
jobId = moveJobFromPrioritizedToActive(KEYS[3], activeKey, KEYS[10])
|
||||
if jobId then
|
||||
return prepareJobForProcessing(ARGV[1], rateLimiterKey, eventStreamKey, jobId, ARGV[2],
|
||||
maxJobs, limiterDuration, markerKey, opts)
|
||||
end
|
||||
end
|
||||
-- Return the timestamp for the next delayed job if any.
|
||||
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
||||
if nextTimestamp ~= nil then return {0, 0, 0, nextTimestamp} end
|
||||
return {0, 0, 0, 0}
|
||||
`;
|
||||
export const moveToActive = {
|
||||
name: 'moveToActive',
|
||||
content,
|
||||
keys: 11,
|
||||
};
|
||||
//# sourceMappingURL=moveToActive-11.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/moveToActive-11.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/moveToActive-11.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"moveToActive-11.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-11.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Of,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/moveToDelayed-12.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/moveToDelayed-12.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const moveToDelayed: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
396
node_modules/bullmq/dist/esm/scripts/moveToDelayed-12.js
generated
vendored
Normal file
396
node_modules/bullmq/dist/esm/scripts/moveToDelayed-12.js
generated
vendored
Normal file
@@ -0,0 +1,396 @@
|
||||
const content = `--[[
|
||||
Moves job from active to delayed set.
|
||||
Input:
|
||||
KEYS[1] marker key
|
||||
KEYS[2] active key
|
||||
KEYS[3] prioritized key
|
||||
KEYS[4] delayed key
|
||||
KEYS[5] job key
|
||||
KEYS[6] events stream
|
||||
KEYS[7] meta key
|
||||
KEYS[8] stalled key
|
||||
KEYS[9] wait key
|
||||
KEYS[10] rate limiter key
|
||||
KEYS[11] paused key
|
||||
KEYS[12] pc priority counter
|
||||
ARGV[1] key prefix
|
||||
ARGV[2] timestamp
|
||||
ARGV[3] the id of the job
|
||||
ARGV[4] queue token
|
||||
ARGV[5] delay value
|
||||
ARGV[6] skip attempt
|
||||
ARGV[7] optional job fields to update
|
||||
ARGV[8] fetch next?
|
||||
ARGV[9] opts
|
||||
Output:
|
||||
0 - OK
|
||||
-1 - Missing job.
|
||||
-3 - Job not in active set.
|
||||
Events:
|
||||
- delayed key.
|
||||
]]
|
||||
local rcall = redis.call
|
||||
-- Includes
|
||||
--[[
|
||||
Add delay marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to return the next delayed job timestamp.
|
||||
]]
|
||||
local function getNextDelayedTimestamp(delayedKey)
|
||||
local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
|
||||
if #result then
|
||||
local nextTimestamp = tonumber(result[2])
|
||||
if nextTimestamp ~= nil then
|
||||
return nextTimestamp / 0x1000
|
||||
end
|
||||
end
|
||||
end
|
||||
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
||||
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
||||
if nextTimestamp ~= nil then
|
||||
-- Replace the score of the marker with the newest known
|
||||
-- next timestamp.
|
||||
rcall("ZADD", markerKey, nextTimestamp, "1")
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to fetch the next job to process.
|
||||
Tries to get the next job to avoid an extra roundtrip if the queue is
|
||||
not closing and not rate limited.
|
||||
Input:
|
||||
waitKey - wait list key
|
||||
activeKey - active list key
|
||||
prioritizedKey - prioritized sorted set key
|
||||
eventStreamKey - event stream key
|
||||
rateLimiterKey - rate limiter key
|
||||
delayedKey - delayed sorted set key
|
||||
pausedKey - paused list key
|
||||
metaKey - meta hash key
|
||||
pcKey - priority counter key
|
||||
markerKey - marker key
|
||||
prefix - keys prefix
|
||||
timestamp - current timestamp
|
||||
opts - options table:
|
||||
token (required) - lock token used when locking jobs
|
||||
lockDuration (required) - lock duration for acquired jobs
|
||||
limiter (optional) - rate limiter options table (e.g. { max = number })
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to get current rate limit ttl.
|
||||
]]
|
||||
local function getRateLimitTTL(maxJobs, rateLimiterKey)
|
||||
if maxJobs and maxJobs <= tonumber(rcall("GET", rateLimiterKey) or 0) then
|
||||
local pttl = rcall("PTTL", rateLimiterKey)
|
||||
if pttl == 0 then
|
||||
rcall("DEL", rateLimiterKey)
|
||||
end
|
||||
if pttl > 0 then
|
||||
return pttl
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
--[[
|
||||
Function to check for the meta.paused key to decide if we are paused or not
|
||||
(since an empty list and !EXISTS are not really the same).
|
||||
]]
|
||||
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
||||
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency", "max", "duration")
|
||||
if queueAttributes[1] then
|
||||
return pausedKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
if queueAttributes[2] then
|
||||
local activeCount = rcall("LLEN", activeKey)
|
||||
if activeCount >= tonumber(queueAttributes[2]) then
|
||||
return waitKey, true, queueAttributes[3], queueAttributes[4]
|
||||
else
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
end
|
||||
end
|
||||
return waitKey, false, queueAttributes[3], queueAttributes[4]
|
||||
end
|
||||
--[[
|
||||
Function to move job from prioritized state to active.
|
||||
]]
|
||||
local function moveJobFromPrioritizedToActive(priorityKey, activeKey, priorityCounterKey)
|
||||
local prioritizedJob = rcall("ZPOPMIN", priorityKey)
|
||||
if #prioritizedJob > 0 then
|
||||
rcall("LPUSH", activeKey, prioritizedJob[1])
|
||||
return prioritizedJob[1]
|
||||
else
|
||||
rcall("DEL", priorityCounterKey)
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Function to move job from wait state to active.
|
||||
Input:
|
||||
opts - token - lock token
|
||||
opts - lockDuration
|
||||
opts - limiter
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Add marker if needed when a job is available.
|
||||
]]
|
||||
local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
if not isPausedOrMaxed then
|
||||
rcall("ZADD", markerKey, 0, "0")
|
||||
end
|
||||
end
|
||||
local function prepareJobForProcessing(keyPrefix, rateLimiterKey, eventStreamKey,
|
||||
jobId, processedOn, maxJobs, limiterDuration, markerKey, opts)
|
||||
local jobKey = keyPrefix .. jobId
|
||||
-- Check if we need to perform rate limiting.
|
||||
if maxJobs then
|
||||
local jobCounter = tonumber(rcall("INCR", rateLimiterKey))
|
||||
if jobCounter == 1 then
|
||||
local integerDuration = math.floor(math.abs(limiterDuration))
|
||||
rcall("PEXPIRE", rateLimiterKey, integerDuration)
|
||||
end
|
||||
end
|
||||
-- get a lock
|
||||
if opts['token'] ~= "0" then
|
||||
local lockKey = jobKey .. ':lock'
|
||||
rcall("SET", lockKey, opts['token'], "PX", opts['lockDuration'])
|
||||
end
|
||||
local optionalValues = {}
|
||||
if opts['name'] then
|
||||
-- Set "processedBy" field to the worker name
|
||||
table.insert(optionalValues, "pb")
|
||||
table.insert(optionalValues, opts['name'])
|
||||
end
|
||||
rcall("XADD", eventStreamKey, "*", "event", "active", "jobId", jobId, "prev", "waiting")
|
||||
rcall("HMSET", jobKey, "processedOn", processedOn, unpack(optionalValues))
|
||||
rcall("HINCRBY", jobKey, "ats", 1)
|
||||
addBaseMarkerIfNeeded(markerKey, false)
|
||||
-- rate limit delay must be 0 in this case to prevent adding more delay
|
||||
-- when job that is moved to active needs to be processed
|
||||
return {rcall("HGETALL", jobKey), jobId, 0, 0} -- get job data
|
||||
end
|
||||
--[[
|
||||
Updates the delay set, by moving delayed jobs that should
|
||||
be processed now to "wait".
|
||||
Events:
|
||||
'waiting'
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to add job in target list and add marker if needed.
|
||||
]]
|
||||
-- Includes
|
||||
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
||||
rcall(pushCmd, targetKey, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
--[[
|
||||
Function to add job considering priority.
|
||||
]]
|
||||
-- Includes
|
||||
--[[
|
||||
Function to get priority score.
|
||||
]]
|
||||
local function getPriorityScore(priority, priorityCounterKey)
|
||||
local prioCounter = rcall("INCR", priorityCounterKey)
|
||||
return priority * 0x100000000 + prioCounter % 0x100000000
|
||||
end
|
||||
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
|
||||
isPausedOrMaxed)
|
||||
local score = getPriorityScore(priority, priorityCounterKey)
|
||||
rcall("ZADD", prioritizedKey, score, jobId)
|
||||
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
||||
end
|
||||
-- Try to get as much as 1000 jobs at once
|
||||
local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedKey,
|
||||
eventStreamKey, prefix, timestamp, priorityCounterKey, isPaused)
|
||||
local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000 - 1, "LIMIT", 0, 1000)
|
||||
if (#jobs > 0) then
|
||||
rcall("ZREM", delayedKey, unpack(jobs))
|
||||
for _, jobId in ipairs(jobs) do
|
||||
local jobKey = prefix .. jobId
|
||||
local priority =
|
||||
tonumber(rcall("HGET", jobKey, "priority")) or 0
|
||||
if priority == 0 then
|
||||
-- LIFO or FIFO
|
||||
rcall("LPUSH", targetKey, jobId)
|
||||
else
|
||||
local score = getPriorityScore(priority, priorityCounterKey)
|
||||
rcall("ZADD", prioritizedKey, score, jobId)
|
||||
end
|
||||
-- Emit waiting event
|
||||
rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId",
|
||||
jobId, "prev", "delayed")
|
||||
rcall("HSET", jobKey, "delay", 0)
|
||||
end
|
||||
addBaseMarkerIfNeeded(markerKey, isPaused)
|
||||
end
|
||||
end
|
||||
local function fetchNextJob(waitKey, activeKey, prioritizedKey, eventStreamKey,
|
||||
rateLimiterKey, delayedKey, pausedKey, metaKey, pcKey, markerKey, prefix,
|
||||
timestamp, opts)
|
||||
local target, isPausedOrMaxed, rateLimitMax, rateLimitDuration =
|
||||
getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
|
||||
-- Check if there are delayed jobs that can be promoted
|
||||
promoteDelayedJobs(delayedKey, markerKey, target, prioritizedKey,
|
||||
eventStreamKey, prefix, timestamp, pcKey, isPausedOrMaxed)
|
||||
local maxJobs = tonumber(rateLimitMax or (opts['limiter'] and opts['limiter']['max']))
|
||||
-- Check if we are rate limited first.
|
||||
local expireTime = getRateLimitTTL(maxJobs, rateLimiterKey)
|
||||
if expireTime > 0 then
|
||||
return {0, 0, expireTime, 0}
|
||||
end
|
||||
-- paused or maxed queue
|
||||
if isPausedOrMaxed then
|
||||
return {0, 0, 0, 0}
|
||||
end
|
||||
local limiterDuration = (opts['limiter'] and opts['limiter']['duration']) or rateLimitDuration
|
||||
local jobId = rcall("RPOPLPUSH", waitKey, activeKey)
|
||||
if jobId then
|
||||
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
||||
if string.sub(jobId, 1, 2) == "0:" then
|
||||
rcall("LREM", activeKey, 1, jobId)
|
||||
-- If jobId is special ID 0:delay (delay greater than 0), then there is no job to process
|
||||
-- but if ID is 0:0, then there is at least 1 prioritized job to process
|
||||
if jobId == "0:0" then
|
||||
jobId = moveJobFromPrioritizedToActive(prioritizedKey, activeKey, pcKey)
|
||||
return prepareJobForProcessing(prefix, rateLimiterKey,
|
||||
eventStreamKey, jobId, timestamp, maxJobs,
|
||||
limiterDuration, markerKey, opts)
|
||||
end
|
||||
else
|
||||
return prepareJobForProcessing(prefix, rateLimiterKey,
|
||||
eventStreamKey, jobId, timestamp, maxJobs,
|
||||
limiterDuration, markerKey, opts)
|
||||
end
|
||||
else
|
||||
jobId = moveJobFromPrioritizedToActive(prioritizedKey, activeKey, pcKey)
|
||||
if jobId then
|
||||
return prepareJobForProcessing(prefix, rateLimiterKey,
|
||||
eventStreamKey, jobId, timestamp, maxJobs,
|
||||
limiterDuration, markerKey, opts)
|
||||
end
|
||||
end
|
||||
-- Return the timestamp for the next delayed job if any.
|
||||
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
||||
if nextTimestamp ~= nil then
|
||||
-- The result is guaranteed to be positive, since the
|
||||
-- ZRANGEBYSCORE command would have return a job otherwise.
|
||||
return {0, 0, 0, nextTimestamp}
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Bake in the job id first 12 bits into the timestamp
|
||||
to guarantee correct execution order of delayed jobs
|
||||
(up to 4096 jobs per given timestamp or 4096 jobs apart per timestamp)
|
||||
WARNING: Jobs that are so far apart that they wrap around will cause FIFO to fail
|
||||
]]
|
||||
local function getDelayedScore(delayedKey, timestamp, delay)
|
||||
local delayedTimestamp = (delay > 0 and (tonumber(timestamp) + delay)) or tonumber(timestamp)
|
||||
local minScore = delayedTimestamp * 0x1000
|
||||
local maxScore = (delayedTimestamp + 1 ) * 0x1000 - 1
|
||||
local result = rcall("ZREVRANGEBYSCORE", delayedKey, maxScore,
|
||||
minScore, "WITHSCORES","LIMIT", 0, 1)
|
||||
if #result then
|
||||
local currentMaxScore = tonumber(result[2])
|
||||
if currentMaxScore ~= nil then
|
||||
if currentMaxScore >= maxScore then
|
||||
return maxScore, delayedTimestamp
|
||||
else
|
||||
return currentMaxScore + 1, delayedTimestamp
|
||||
end
|
||||
end
|
||||
end
|
||||
return minScore, delayedTimestamp
|
||||
end
|
||||
--[[
|
||||
Function to get max events value or set by default 10000.
|
||||
]]
|
||||
local function getOrSetMaxEvents(metaKey)
|
||||
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
||||
if not maxEvents then
|
||||
maxEvents = 10000
|
||||
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
||||
end
|
||||
return maxEvents
|
||||
end
|
||||
local function removeLock(jobKey, stalledKey, token, jobId)
|
||||
if token ~= "0" then
|
||||
local lockKey = jobKey .. ':lock'
|
||||
local lockToken = rcall("GET", lockKey)
|
||||
if lockToken == token then
|
||||
rcall("DEL", lockKey)
|
||||
rcall("SREM", stalledKey, jobId)
|
||||
else
|
||||
if lockToken then
|
||||
-- Lock exists but token does not match
|
||||
return -6
|
||||
else
|
||||
-- Lock is missing completely
|
||||
return -2
|
||||
end
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
--[[
|
||||
Function to update a bunch of fields in a job.
|
||||
]]
|
||||
local function updateJobFields(jobKey, msgpackedFields)
|
||||
if msgpackedFields and #msgpackedFields > 0 then
|
||||
local fieldsToUpdate = cmsgpack.unpack(msgpackedFields)
|
||||
if fieldsToUpdate then
|
||||
rcall("HMSET", jobKey, unpack(fieldsToUpdate))
|
||||
end
|
||||
end
|
||||
end
|
||||
local jobKey = KEYS[5]
|
||||
local markerKey = KEYS[1]
|
||||
local metaKey = KEYS[7]
|
||||
local token = ARGV[4]
|
||||
if rcall("EXISTS", jobKey) == 1 then
|
||||
local errorCode = removeLock(jobKey, KEYS[8], token, ARGV[3])
|
||||
if errorCode < 0 then
|
||||
return errorCode
|
||||
end
|
||||
updateJobFields(jobKey, ARGV[7])
|
||||
local delayedKey = KEYS[4]
|
||||
local jobId = ARGV[3]
|
||||
local delay = tonumber(ARGV[5])
|
||||
local numRemovedElements = rcall("LREM", KEYS[2], -1, jobId)
|
||||
if numRemovedElements < 1 then return -3 end
|
||||
local score, delayedTimestamp = getDelayedScore(delayedKey, ARGV[2], delay)
|
||||
if ARGV[6] == "0" then
|
||||
rcall("HINCRBY", jobKey, "atm", 1)
|
||||
end
|
||||
rcall("HSET", jobKey, "delay", ARGV[5])
|
||||
local maxEvents = getOrSetMaxEvents(metaKey)
|
||||
rcall("ZADD", delayedKey, score, jobId)
|
||||
rcall("XADD", KEYS[6], "MAXLEN", "~", maxEvents, "*", "event", "delayed",
|
||||
"jobId", jobId, "delay", delayedTimestamp)
|
||||
-- Try to get next job to avoid an extra roundtrip if the queue is not closing,
|
||||
-- and not rate limited.
|
||||
if (ARGV[8] == "1") then
|
||||
local opts = cmsgpack.unpack(ARGV[9])
|
||||
local result = fetchNextJob(KEYS[9], KEYS[2], KEYS[3], KEYS[6],
|
||||
KEYS[10], KEYS[4], KEYS[11], metaKey, KEYS[12], markerKey,
|
||||
ARGV[1], ARGV[2], opts)
|
||||
if result and type(result[1]) == "table" then
|
||||
return result
|
||||
end
|
||||
end
|
||||
-- Check if we need to push a marker job to wake up sleeping workers.
|
||||
addDelayMarkerIfNeeded(markerKey, delayedKey)
|
||||
return 0
|
||||
else
|
||||
return -1
|
||||
end
|
||||
`;
|
||||
export const moveToDelayed = {
|
||||
name: 'moveToDelayed',
|
||||
content,
|
||||
keys: 12,
|
||||
};
|
||||
//# sourceMappingURL=moveToDelayed-12.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/moveToDelayed-12.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/moveToDelayed-12.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"moveToDelayed-12.js","sourceRoot":"","sources":["../../../src/scripts/moveToDelayed-12.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqYf,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/moveToFinished-14.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/moveToFinished-14.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const moveToFinished: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
1034
node_modules/bullmq/dist/esm/scripts/moveToFinished-14.js
generated
vendored
Normal file
1034
node_modules/bullmq/dist/esm/scripts/moveToFinished-14.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/bullmq/dist/esm/scripts/moveToFinished-14.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/moveToFinished-14.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"moveToFinished-14.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-14.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmgCf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-7.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-7.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const moveToWaitingChildren: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
104
node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-7.js
generated
vendored
Normal file
104
node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-7.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
const content = `--[[
|
||||
Moves job from active to waiting children set.
|
||||
Input:
|
||||
KEYS[1] active key
|
||||
KEYS[2] wait-children key
|
||||
KEYS[3] job key
|
||||
KEYS[4] job dependencies key
|
||||
KEYS[5] job unsuccessful key
|
||||
KEYS[6] stalled key
|
||||
KEYS[7] events key
|
||||
ARGV[1] token
|
||||
ARGV[2] child key
|
||||
ARGV[3] timestamp
|
||||
ARGV[4] jobId
|
||||
ARGV[5] prefix
|
||||
Output:
|
||||
0 - OK
|
||||
1 - There are not pending dependencies.
|
||||
-1 - Missing job.
|
||||
-2 - Missing lock
|
||||
-3 - Job not in active set
|
||||
-9 - Job has failed children
|
||||
]]
|
||||
local rcall = redis.call
|
||||
local activeKey = KEYS[1]
|
||||
local waitingChildrenKey = KEYS[2]
|
||||
local jobKey = KEYS[3]
|
||||
local jobDependenciesKey = KEYS[4]
|
||||
local jobUnsuccessfulKey = KEYS[5]
|
||||
local stalledKey = KEYS[6]
|
||||
local eventStreamKey = KEYS[7]
|
||||
local token = ARGV[1]
|
||||
local timestamp = ARGV[3]
|
||||
local jobId = ARGV[4]
|
||||
--- Includes
|
||||
local function removeLock(jobKey, stalledKey, token, jobId)
|
||||
if token ~= "0" then
|
||||
local lockKey = jobKey .. ':lock'
|
||||
local lockToken = rcall("GET", lockKey)
|
||||
if lockToken == token then
|
||||
rcall("DEL", lockKey)
|
||||
rcall("SREM", stalledKey, jobId)
|
||||
else
|
||||
if lockToken then
|
||||
-- Lock exists but token does not match
|
||||
return -6
|
||||
else
|
||||
-- Lock is missing completely
|
||||
return -2
|
||||
end
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
local function removeJobFromActive(activeKey, stalledKey, jobKey, jobId,
|
||||
token)
|
||||
local errorCode = removeLock(jobKey, stalledKey, token, jobId)
|
||||
if errorCode < 0 then
|
||||
return errorCode
|
||||
end
|
||||
local numRemovedElements = rcall("LREM", activeKey, -1, jobId)
|
||||
if numRemovedElements < 1 then
|
||||
return -3
|
||||
end
|
||||
return 0
|
||||
end
|
||||
local function moveToWaitingChildren(activeKey, waitingChildrenKey, stalledKey, eventStreamKey,
|
||||
jobKey, jobId, timestamp, token)
|
||||
local errorCode = removeJobFromActive(activeKey, stalledKey, jobKey, jobId, token)
|
||||
if errorCode < 0 then
|
||||
return errorCode
|
||||
end
|
||||
local score = tonumber(timestamp)
|
||||
rcall("ZADD", waitingChildrenKey, score, jobId)
|
||||
rcall("XADD", eventStreamKey, "*", "event", "waiting-children", "jobId", jobId, 'prev', 'active')
|
||||
return 0
|
||||
end
|
||||
if rcall("EXISTS", jobKey) == 1 then
|
||||
if rcall("ZCARD", jobUnsuccessfulKey) ~= 0 then
|
||||
return -9
|
||||
else
|
||||
if ARGV[2] ~= "" then
|
||||
if rcall("SISMEMBER", jobDependenciesKey, ARGV[2]) ~= 0 then
|
||||
return moveToWaitingChildren(activeKey, waitingChildrenKey, stalledKey, eventStreamKey,
|
||||
jobKey, jobId, timestamp, token)
|
||||
end
|
||||
return 1
|
||||
else
|
||||
if rcall("SCARD", jobDependenciesKey) ~= 0 then
|
||||
return moveToWaitingChildren(activeKey, waitingChildrenKey, stalledKey, eventStreamKey,
|
||||
jobKey, jobId, timestamp, token)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
end
|
||||
end
|
||||
return -1
|
||||
`;
|
||||
export const moveToWaitingChildren = {
|
||||
name: 'moveToWaitingChildren',
|
||||
content,
|
||||
keys: 7,
|
||||
};
|
||||
//# sourceMappingURL=moveToWaitingChildren-7.js.map
|
||||
1
node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-7.js.map
generated
vendored
Normal file
1
node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-7.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"moveToWaitingChildren-7.js","sourceRoot":"","sources":["../../../src/scripts/moveToWaitingChildren-7.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiGf,CAAC;AACF,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
||||
5
node_modules/bullmq/dist/esm/scripts/obliterate-2.d.ts
generated
vendored
Normal file
5
node_modules/bullmq/dist/esm/scripts/obliterate-2.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const obliterate: {
|
||||
name: string;
|
||||
content: string;
|
||||
keys: number;
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user