bullmq 4.17.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/classes/flow-producer.js +3 -10
- package/dist/cjs/classes/flow-producer.js.map +1 -1
- package/dist/cjs/classes/job.js +21 -11
- package/dist/cjs/classes/job.js.map +1 -1
- package/dist/cjs/classes/queue-base.js +2 -9
- package/dist/cjs/classes/queue-base.js.map +1 -1
- package/dist/cjs/classes/queue-events.js +3 -1
- package/dist/cjs/classes/queue-events.js.map +1 -1
- package/dist/cjs/classes/queue-keys.js +1 -0
- package/dist/cjs/classes/queue-keys.js.map +1 -1
- package/dist/cjs/classes/redis-connection.js +9 -7
- package/dist/cjs/classes/redis-connection.js.map +1 -1
- package/dist/cjs/classes/scripts.js +34 -34
- package/dist/cjs/classes/scripts.js.map +1 -1
- package/dist/cjs/classes/worker.js +27 -32
- package/dist/cjs/classes/worker.js.map +1 -1
- package/dist/cjs/commands/{addDelayedJob-7.lua → addDelayedJob-6.lua} +18 -22
- package/dist/cjs/commands/addParentJob-4.lua +0 -2
- package/dist/{esm/commands/addPrioritizedJob-8.lua → cjs/commands/addPrioritizedJob-7.lua} +18 -24
- package/dist/cjs/commands/{addStandardJob-6.lua → addStandardJob-7.lua} +6 -2
- package/dist/cjs/commands/changePriority-6.lua +57 -0
- package/dist/cjs/commands/getCounts-1.lua +1 -0
- package/dist/cjs/commands/getRanges-1.lua +1 -0
- package/dist/cjs/commands/includes/addDelayMarkerIfNeeded.lua +5 -19
- package/dist/cjs/commands/includes/addJobWithPriority.lua +3 -7
- package/dist/cjs/commands/includes/checkStalledJobs.lua +1 -1
- package/dist/cjs/commands/includes/isQueuePaused.lua +7 -0
- package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +39 -30
- package/dist/cjs/commands/includes/prepareJobForProcessing.lua +1 -1
- package/dist/cjs/commands/includes/promoteDelayedJobs.lua +7 -4
- package/dist/{esm/commands/moveToActive-10.lua → cjs/commands/moveToActive-11.lua} +18 -29
- package/dist/cjs/commands/moveToDelayed-7.lua +77 -0
- package/dist/cjs/commands/{moveToFinished-13.lua → moveToFinished-14.lua} +29 -22
- package/dist/cjs/commands/moveToWaitingChildren-4.lua +7 -4
- package/dist/cjs/commands/pause-7.lua +41 -0
- package/dist/cjs/commands/promote-8.lua +60 -0
- package/dist/cjs/commands/{retryJob-9.lua → retryJob-10.lua} +16 -11
- package/dist/cjs/scripts/{addDelayedJob-7.js → addDelayedJob-6.js} +77 -88
- package/dist/cjs/scripts/{moveToActive-10.js.map → addDelayedJob-6.js.map} +1 -1
- package/dist/cjs/scripts/addParentJob-4.js +51 -61
- package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
- package/dist/cjs/scripts/{addPrioritizedJob-8.js → addPrioritizedJob-7.js} +80 -93
- package/dist/cjs/scripts/addPrioritizedJob-7.js.map +1 -0
- package/dist/cjs/scripts/{addStandardJob-6.js → addStandardJob-7.js} +58 -63
- package/dist/cjs/scripts/addStandardJob-7.js.map +1 -0
- package/dist/cjs/scripts/changePriority-6.js +85 -0
- package/dist/cjs/scripts/changePriority-6.js.map +1 -0
- package/dist/cjs/scripts/getCounts-1.js +1 -0
- package/dist/cjs/scripts/getCounts-1.js.map +1 -1
- package/dist/cjs/scripts/getRanges-1.js +1 -0
- package/dist/cjs/scripts/getRanges-1.js.map +1 -1
- package/dist/cjs/scripts/index.js +10 -10
- package/dist/cjs/scripts/index.js.map +1 -1
- package/dist/cjs/scripts/moveStalledJobsToWait-8.js +1 -0
- package/dist/cjs/scripts/moveStalledJobsToWait-8.js.map +1 -1
- package/dist/cjs/scripts/{moveToActive-10.js → moveToActive-11.js} +30 -48
- package/dist/cjs/scripts/moveToActive-11.js.map +1 -0
- package/dist/cjs/scripts/moveToDelayed-7.js +103 -0
- package/dist/cjs/scripts/moveToDelayed-7.js.map +1 -0
- package/dist/cjs/scripts/{moveToFinished-13.js → moveToFinished-14.js} +89 -88
- package/dist/cjs/scripts/{moveToFinished-13.js.map → moveToFinished-14.js.map} +1 -1
- package/dist/cjs/scripts/moveToWaitingChildren-4.js +6 -3
- package/dist/cjs/scripts/moveToWaitingChildren-4.js.map +1 -1
- package/dist/cjs/scripts/pause-7.js +67 -0
- package/dist/cjs/scripts/pause-7.js.map +1 -0
- package/dist/cjs/scripts/promote-8.js +79 -0
- package/dist/cjs/scripts/promote-8.js.map +1 -0
- package/dist/cjs/scripts/{retryJob-9.js → retryJob-10.js} +26 -32
- package/dist/cjs/scripts/retryJob-10.js.map +1 -0
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/esm/classes/flow-producer.js +3 -10
- package/dist/esm/classes/flow-producer.js.map +1 -1
- package/dist/esm/classes/job.d.ts +5 -0
- package/dist/esm/classes/job.js +21 -11
- package/dist/esm/classes/job.js.map +1 -1
- package/dist/esm/classes/queue-base.js +2 -9
- package/dist/esm/classes/queue-base.js.map +1 -1
- package/dist/esm/classes/queue-events.js +3 -1
- package/dist/esm/classes/queue-events.js.map +1 -1
- package/dist/esm/classes/queue-keys.js +1 -0
- package/dist/esm/classes/queue-keys.js.map +1 -1
- package/dist/esm/classes/redis-connection.js +9 -7
- package/dist/esm/classes/redis-connection.js.map +1 -1
- package/dist/esm/classes/scripts.d.ts +4 -4
- package/dist/esm/classes/scripts.js +34 -34
- package/dist/esm/classes/scripts.js.map +1 -1
- package/dist/esm/classes/worker.d.ts +1 -1
- package/dist/esm/classes/worker.js +27 -32
- package/dist/esm/classes/worker.js.map +1 -1
- package/dist/esm/commands/{addDelayedJob-7.lua → addDelayedJob-6.lua} +18 -22
- package/dist/esm/commands/addParentJob-4.lua +0 -2
- package/dist/{cjs/commands/addPrioritizedJob-8.lua → esm/commands/addPrioritizedJob-7.lua} +18 -24
- package/dist/esm/commands/{addStandardJob-6.lua → addStandardJob-7.lua} +6 -2
- package/dist/esm/commands/changePriority-6.lua +57 -0
- package/dist/esm/commands/getCounts-1.lua +1 -0
- package/dist/esm/commands/getRanges-1.lua +1 -0
- package/dist/esm/commands/includes/addDelayMarkerIfNeeded.lua +5 -19
- package/dist/esm/commands/includes/addJobWithPriority.lua +3 -7
- package/dist/esm/commands/includes/checkStalledJobs.lua +1 -1
- package/dist/esm/commands/includes/isQueuePaused.lua +7 -0
- package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +39 -30
- package/dist/esm/commands/includes/prepareJobForProcessing.lua +1 -1
- package/dist/esm/commands/includes/promoteDelayedJobs.lua +7 -4
- package/dist/{cjs/commands/moveToActive-10.lua → esm/commands/moveToActive-11.lua} +18 -29
- package/dist/esm/commands/moveToDelayed-7.lua +77 -0
- package/dist/esm/commands/{moveToFinished-13.lua → moveToFinished-14.lua} +29 -22
- package/dist/esm/commands/moveToWaitingChildren-4.lua +7 -4
- package/dist/esm/commands/pause-7.lua +41 -0
- package/dist/esm/commands/promote-8.lua +60 -0
- package/dist/esm/commands/{retryJob-9.lua → retryJob-10.lua} +16 -11
- package/dist/esm/interfaces/job-json.d.ts +4 -1
- package/dist/esm/interfaces/minimal-job.d.ts +3 -0
- package/dist/esm/interfaces/queue-options.d.ts +1 -1
- package/dist/esm/scripts/{addDelayedJob-7.js → addDelayedJob-6.js} +77 -88
- package/dist/esm/scripts/{moveToActive-10.js.map → addDelayedJob-6.js.map} +1 -1
- package/dist/esm/scripts/addParentJob-4.js +51 -61
- package/dist/esm/scripts/addParentJob-4.js.map +1 -1
- package/dist/esm/scripts/{addPrioritizedJob-8.js → addPrioritizedJob-7.js} +80 -93
- package/dist/esm/scripts/addPrioritizedJob-7.js.map +1 -0
- package/dist/esm/scripts/{addStandardJob-6.js → addStandardJob-7.js} +58 -63
- package/dist/esm/scripts/addStandardJob-7.js.map +1 -0
- package/dist/esm/scripts/changePriority-6.js +82 -0
- package/dist/esm/scripts/changePriority-6.js.map +1 -0
- package/dist/esm/scripts/getCounts-1.js +1 -0
- package/dist/esm/scripts/getCounts-1.js.map +1 -1
- package/dist/esm/scripts/getRanges-1.js +1 -0
- package/dist/esm/scripts/getRanges-1.js.map +1 -1
- package/dist/esm/scripts/index.d.ts +10 -10
- package/dist/esm/scripts/index.js +10 -10
- package/dist/esm/scripts/index.js.map +1 -1
- package/dist/esm/scripts/moveStalledJobsToWait-8.js +1 -0
- package/dist/esm/scripts/moveStalledJobsToWait-8.js.map +1 -1
- package/dist/esm/scripts/{moveToActive-10.js → moveToActive-11.js} +30 -48
- package/dist/esm/scripts/moveToActive-11.js.map +1 -0
- package/dist/esm/scripts/moveToDelayed-7.js +100 -0
- package/dist/esm/scripts/moveToDelayed-7.js.map +1 -0
- package/dist/esm/scripts/{moveToFinished-13.js → moveToFinished-14.js} +89 -88
- package/dist/esm/scripts/{moveToFinished-13.js.map → moveToFinished-14.js.map} +1 -1
- package/dist/esm/scripts/moveToWaitingChildren-4.js +6 -3
- package/dist/esm/scripts/moveToWaitingChildren-4.js.map +1 -1
- package/dist/esm/scripts/pause-7.js +64 -0
- package/dist/esm/scripts/pause-7.js.map +1 -0
- package/dist/esm/scripts/promote-8.js +76 -0
- package/dist/esm/scripts/promote-8.js.map +1 -0
- package/dist/esm/scripts/{retryJob-9.js → retryJob-10.js} +26 -32
- package/dist/esm/scripts/retryJob-10.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/commands/changePriority-5.lua +0 -52
- package/dist/cjs/commands/includes/addPriorityMarkerIfNeeded.lua +0 -12
- package/dist/cjs/commands/moveToDelayed-8.lua +0 -72
- package/dist/cjs/commands/pause-5.lua +0 -36
- package/dist/cjs/commands/promote-7.lua +0 -57
- package/dist/cjs/scripts/addDelayedJob-7.js.map +0 -1
- package/dist/cjs/scripts/addPrioritizedJob-8.js.map +0 -1
- package/dist/cjs/scripts/addStandardJob-6.js.map +0 -1
- package/dist/cjs/scripts/changePriority-5.js +0 -87
- package/dist/cjs/scripts/changePriority-5.js.map +0 -1
- package/dist/cjs/scripts/moveToDelayed-8.js +0 -168
- package/dist/cjs/scripts/moveToDelayed-8.js.map +0 -1
- package/dist/cjs/scripts/pause-5.js +0 -48
- package/dist/cjs/scripts/pause-5.js.map +0 -1
- package/dist/cjs/scripts/promote-7.js +0 -87
- package/dist/cjs/scripts/promote-7.js.map +0 -1
- package/dist/cjs/scripts/retryJob-9.js.map +0 -1
- package/dist/esm/commands/changePriority-5.lua +0 -52
- package/dist/esm/commands/includes/addPriorityMarkerIfNeeded.lua +0 -12
- package/dist/esm/commands/moveToDelayed-8.lua +0 -72
- package/dist/esm/commands/pause-5.lua +0 -36
- package/dist/esm/commands/promote-7.lua +0 -57
- package/dist/esm/scripts/addDelayedJob-7.js.map +0 -1
- package/dist/esm/scripts/addPrioritizedJob-8.js.map +0 -1
- package/dist/esm/scripts/addStandardJob-6.js.map +0 -1
- package/dist/esm/scripts/changePriority-5.js +0 -84
- package/dist/esm/scripts/changePriority-5.js.map +0 -1
- package/dist/esm/scripts/moveToDelayed-8.js +0 -165
- package/dist/esm/scripts/moveToDelayed-8.js.map +0 -1
- package/dist/esm/scripts/pause-5.js +0 -45
- package/dist/esm/scripts/pause-5.js.map +0 -1
- package/dist/esm/scripts/promote-7.js +0 -84
- package/dist/esm/scripts/promote-7.js.map +0 -1
- package/dist/esm/scripts/retryJob-9.js.map +0 -1
- /package/dist/esm/scripts/{addDelayedJob-7.d.ts → addDelayedJob-6.d.ts} +0 -0
- /package/dist/esm/scripts/{addPrioritizedJob-8.d.ts → addPrioritizedJob-7.d.ts} +0 -0
- /package/dist/esm/scripts/{addStandardJob-6.d.ts → addStandardJob-7.d.ts} +0 -0
- /package/dist/esm/scripts/{changePriority-5.d.ts → changePriority-6.d.ts} +0 -0
- /package/dist/esm/scripts/{moveToActive-10.d.ts → moveToActive-11.d.ts} +0 -0
- /package/dist/esm/scripts/{moveToDelayed-8.d.ts → moveToDelayed-7.d.ts} +0 -0
- /package/dist/esm/scripts/{moveToFinished-13.d.ts → moveToFinished-14.d.ts} +0 -0
- /package/dist/esm/scripts/{pause-5.d.ts → pause-7.d.ts} +0 -0
- /package/dist/esm/scripts/{promote-7.d.ts → promote-8.d.ts} +0 -0
- /package/dist/esm/scripts/{retryJob-9.d.ts → retryJob-10.d.ts} +0 -0
@@ -22,6 +22,7 @@ const content = `--[[
|
|
22
22
|
KEYS[4] 'id'
|
23
23
|
KEYS[5] 'completed'
|
24
24
|
KEYS[6] events stream key
|
25
|
+
KEYS[7] marker key
|
25
26
|
ARGV[1] msgpacked arguments array
|
26
27
|
[1] key prefix,
|
27
28
|
[2] custom id (will not generate one automatically)
|
@@ -85,7 +86,7 @@ end
|
|
85
86
|
-- Includes
|
86
87
|
--[[
|
87
88
|
Add delay marker if needed.
|
88
|
-
]]
|
89
|
+
]]
|
89
90
|
-- Includes
|
90
91
|
--[[
|
91
92
|
Function to return the next delayed job timestamp.
|
@@ -100,47 +101,30 @@ local function getNextDelayedTimestamp(delayedKey)
|
|
100
101
|
return nextTimestamp
|
101
102
|
end
|
102
103
|
end
|
103
|
-
local function addDelayMarkerIfNeeded(
|
104
|
-
local waitLen = rcall("LLEN", targetKey)
|
105
|
-
if waitLen <= 1 then
|
104
|
+
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
106
105
|
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
107
106
|
if nextTimestamp ~= nil then
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
local marker = rcall("LINDEX", targetKey, 0)
|
112
|
-
local oldTimestamp = tonumber(marker:sub(3))
|
113
|
-
if oldTimestamp and oldTimestamp > nextTimestamp then
|
114
|
-
rcall("LSET", targetKey, 0, "0:" .. nextTimestamp)
|
115
|
-
end
|
116
|
-
else
|
117
|
-
-- if there is no marker, then we need to add one
|
118
|
-
rcall("LPUSH", targetKey, "0:" .. nextTimestamp)
|
119
|
-
end
|
107
|
+
-- Replace the score of the marker with the newest known
|
108
|
+
-- next timestamp.
|
109
|
+
rcall("ZADD", markerKey, nextTimestamp, "0")
|
120
110
|
end
|
121
|
-
end
|
122
111
|
end
|
123
112
|
--[[
|
124
|
-
Function to
|
113
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
114
|
+
(since an empty list and !EXISTS are not really the same).
|
125
115
|
]]
|
126
|
-
|
116
|
+
local function isQueuePaused(queueMetaKey)
|
117
|
+
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
118
|
+
end
|
127
119
|
--[[
|
128
|
-
Function
|
129
|
-
in order to wake up our workers and to respect priority
|
130
|
-
order as much as possible
|
120
|
+
Function to add job considering priority.
|
131
121
|
]]
|
132
|
-
local function
|
133
|
-
local waitLen = rcall("LLEN", waitKey)
|
134
|
-
if waitLen == 0 then
|
135
|
-
rcall("LPUSH", waitKey, "0:0")
|
136
|
-
end
|
137
|
-
end
|
138
|
-
local function addJobWithPriority(waitKey, prioritizedKey, priority, paused, jobId, priorityCounterKey)
|
122
|
+
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
139
123
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
140
124
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
141
125
|
rcall("ZADD", prioritizedKey, score, jobId)
|
142
|
-
if not
|
143
|
-
|
126
|
+
if not isPaused then
|
127
|
+
rcall("ZADD", markerKey, 0, "0")
|
144
128
|
end
|
145
129
|
end
|
146
130
|
--[[
|
@@ -154,35 +138,44 @@ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
|
|
154
138
|
return pausedKey, true
|
155
139
|
end
|
156
140
|
end
|
157
|
-
local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
141
|
+
local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
142
|
+
parentKey, parentId, timestamp)
|
143
|
+
local isParentActive = rcall("ZSCORE",
|
144
|
+
parentQueueKey .. ":waiting-children", parentId)
|
145
|
+
if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
|
146
|
+
rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
|
147
|
+
local parentWaitKey = parentQueueKey .. ":wait"
|
148
|
+
local parentPausedKey = parentQueueKey .. ":paused"
|
149
|
+
local parentMetaKey = parentQueueKey .. ":meta"
|
150
|
+
local parentMarkerKey = parentQueueKey .. ":marker"
|
151
|
+
local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
|
152
|
+
local priority = tonumber(jobAttributes[1]) or 0
|
153
|
+
local delay = tonumber(jobAttributes[2]) or 0
|
154
|
+
if delay > 0 then
|
155
|
+
local delayedTimestamp = tonumber(timestamp) + delay
|
156
|
+
local score = delayedTimestamp * 0x1000
|
157
|
+
local parentDelayedKey = parentQueueKey .. ":delayed"
|
158
|
+
rcall("ZADD", parentDelayedKey, score, parentId)
|
159
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed",
|
160
|
+
"jobId", parentId, "delay", delayedTimestamp)
|
161
|
+
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
162
|
+
else
|
163
|
+
if priority == 0 then
|
164
|
+
local parentTarget, _paused =
|
165
|
+
getTargetQueueList(parentMetaKey, parentWaitKey,
|
166
|
+
parentPausedKey)
|
167
|
+
rcall("RPUSH", parentTarget, parentId)
|
168
|
+
rcall("ZADD", parentMarkerKey, 0, "0")
|
169
|
+
else
|
170
|
+
local isPaused = isQueuePaused(parentMetaKey)
|
171
|
+
addJobWithPriority(parentMarkerKey,
|
172
|
+
parentQueueKey .. ":prioritized", priority,
|
173
|
+
parentId, parentQueueKey .. ":pc", isPaused)
|
174
|
+
end
|
175
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
|
176
|
+
"jobId", parentId, "prev", "waiting-children")
|
177
|
+
end
|
184
178
|
end
|
185
|
-
end
|
186
179
|
end
|
187
180
|
local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
|
188
181
|
parentId, jobIdKey, returnvalue, timestamp )
|
@@ -249,6 +242,10 @@ end
|
|
249
242
|
storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2], opts, timestamp,
|
250
243
|
parentKey, parentData, repeatJobKey)
|
251
244
|
local target, paused = getTargetQueueList(metaKey, KEYS[1], KEYS[2])
|
245
|
+
if not paused then
|
246
|
+
-- mark that a job is available
|
247
|
+
rcall("ZADD", KEYS[7], 0, "0")
|
248
|
+
end
|
252
249
|
-- LIFO or FIFO
|
253
250
|
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
254
251
|
rcall(pushCmd, target, jobId)
|
@@ -256,8 +253,6 @@ rcall(pushCmd, target, jobId)
|
|
256
253
|
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
|
257
254
|
"jobId", jobId)
|
258
255
|
-- Check if this job is a child of another job, if so add it to the parents dependencies
|
259
|
-
-- TODO: Should not be possible to add a child job to a parent that is not in the "waiting-children" status.
|
260
|
-
-- fail in this case.
|
261
256
|
if parentDependenciesKey ~= nil then
|
262
257
|
rcall("SADD", parentDependenciesKey, jobIdKey)
|
263
258
|
end
|
@@ -266,6 +261,6 @@ return jobId .. "" -- convert to string
|
|
266
261
|
exports.addStandardJob = {
|
267
262
|
name: 'addStandardJob',
|
268
263
|
content,
|
269
|
-
keys:
|
264
|
+
keys: 7,
|
270
265
|
};
|
271
|
-
//# sourceMappingURL=addStandardJob-
|
266
|
+
//# sourceMappingURL=addStandardJob-7.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"addStandardJob-7.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-7.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgQf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -0,0 +1,85 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.changePriority = void 0;
|
4
|
+
const content = `--[[
|
5
|
+
Change job priority
|
6
|
+
Input:
|
7
|
+
KEYS[1] 'wait',
|
8
|
+
KEYS[2] 'paused'
|
9
|
+
KEYS[3] 'meta'
|
10
|
+
KEYS[4] 'prioritized'
|
11
|
+
KEYS[5] 'pc' priority counter
|
12
|
+
KEYS[6] 'marker'
|
13
|
+
ARGV[1] priority value
|
14
|
+
ARGV[2] job key
|
15
|
+
ARGV[3] job id
|
16
|
+
ARGV[4] lifo
|
17
|
+
Output:
|
18
|
+
0 - OK
|
19
|
+
-1 - Missing job
|
20
|
+
]]
|
21
|
+
local jobKey = ARGV[2]
|
22
|
+
local jobId = ARGV[3]
|
23
|
+
local priority = tonumber(ARGV[1])
|
24
|
+
local rcall = redis.call
|
25
|
+
-- Includes
|
26
|
+
--[[
|
27
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
28
|
+
(since an empty list and !EXISTS are not really the same).
|
29
|
+
]]
|
30
|
+
local function isQueuePaused(queueMetaKey)
|
31
|
+
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
32
|
+
end
|
33
|
+
--[[
|
34
|
+
Function to add job considering priority.
|
35
|
+
]]
|
36
|
+
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
37
|
+
local prioCounter = rcall("INCR", priorityCounterKey)
|
38
|
+
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
39
|
+
rcall("ZADD", prioritizedKey, score, jobId)
|
40
|
+
if not isPaused then
|
41
|
+
rcall("ZADD", markerKey, 0, "0")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
--[[
|
45
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
46
|
+
(since an empty list and !EXISTS are not really the same).
|
47
|
+
]]
|
48
|
+
local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
|
49
|
+
if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
|
50
|
+
return waitKey, false
|
51
|
+
else
|
52
|
+
return pausedKey, true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
if rcall("EXISTS", jobKey) == 1 then
|
56
|
+
local metaKey = KEYS[3]
|
57
|
+
local isPaused = isQueuePaused(metaKey)
|
58
|
+
local markerKey = KEYS[6]
|
59
|
+
local prioritizedKey = KEYS[4]
|
60
|
+
-- Re-add with the new priority
|
61
|
+
if rcall("ZREM", KEYS[4], jobId) > 0 then
|
62
|
+
addJobWithPriority(markerKey, prioritizedKey, priority, jobId, KEYS[5],
|
63
|
+
isPaused)
|
64
|
+
-- If the new priority is 0, then just leave the job where it is in the wait list.
|
65
|
+
elseif priority > 0 then
|
66
|
+
-- Job is already in the wait list, we need to re-add it with the new priority.
|
67
|
+
local target = isPaused and KEYS[2] or KEYS[1]
|
68
|
+
local numRemovedElements = rcall("LREM", target, -1, jobId)
|
69
|
+
if numRemovedElements > 0 then
|
70
|
+
addJobWithPriority(markerKey, prioritizedKey, priority, jobId,
|
71
|
+
KEYS[5], isPaused)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
rcall("HSET", jobKey, "priority", priority)
|
75
|
+
return 0
|
76
|
+
else
|
77
|
+
return -1
|
78
|
+
end
|
79
|
+
`;
|
80
|
+
exports.changePriority = {
|
81
|
+
name: 'changePriority',
|
82
|
+
content,
|
83
|
+
keys: 6,
|
84
|
+
};
|
85
|
+
//# sourceMappingURL=changePriority-6.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"changePriority-6.js","sourceRoot":"","sources":["../../../src/scripts/changePriority-6.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2Ef,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -13,6 +13,7 @@ local results = {}
|
|
13
13
|
for i = 1, #ARGV do
|
14
14
|
local stateKey = prefix .. ARGV[i]
|
15
15
|
if ARGV[i] == "wait" or ARGV[i] == "paused" then
|
16
|
+
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
16
17
|
local marker = rcall("LINDEX", stateKey, -1)
|
17
18
|
if marker and string.sub(marker, 1, 2) == "0:" then
|
18
19
|
local count = rcall("LLEN", stateKey)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getCounts-1.js","sourceRoot":"","sources":["../../../src/scripts/getCounts-1.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"getCounts-1.js","sourceRoot":"","sources":["../../../src/scripts/getCounts-1.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCf,CAAC;AACW,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -40,6 +40,7 @@ end
|
|
40
40
|
for i = 4, #ARGV do
|
41
41
|
local stateKey = prefix .. ARGV[i]
|
42
42
|
if ARGV[i] == "wait" or ARGV[i] == "paused" then
|
43
|
+
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
43
44
|
local marker = rcall("LINDEX", stateKey, -1)
|
44
45
|
if marker and string.sub(marker, 1, 2) == "0:" then
|
45
46
|
local count = rcall("LLEN", stateKey)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getRanges-1.js","sourceRoot":"","sources":["../../../src/scripts/getRanges-1.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"getRanges-1.js","sourceRoot":"","sources":["../../../src/scripts/getRanges-1.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Df,CAAC;AACW,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -1,12 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
const tslib_1 = require("tslib");
|
4
|
-
tslib_1.__exportStar(require("./addDelayedJob-
|
4
|
+
tslib_1.__exportStar(require("./addDelayedJob-6"), exports);
|
5
5
|
tslib_1.__exportStar(require("./addParentJob-4"), exports);
|
6
|
-
tslib_1.__exportStar(require("./addPrioritizedJob-
|
7
|
-
tslib_1.__exportStar(require("./addStandardJob-
|
6
|
+
tslib_1.__exportStar(require("./addPrioritizedJob-7"), exports);
|
7
|
+
tslib_1.__exportStar(require("./addStandardJob-7"), exports);
|
8
8
|
tslib_1.__exportStar(require("./changeDelay-3"), exports);
|
9
|
-
tslib_1.__exportStar(require("./changePriority-
|
9
|
+
tslib_1.__exportStar(require("./changePriority-6"), exports);
|
10
10
|
tslib_1.__exportStar(require("./cleanJobsInSet-2"), exports);
|
11
11
|
tslib_1.__exportStar(require("./drain-4"), exports);
|
12
12
|
tslib_1.__exportStar(require("./extendLock-2"), exports);
|
@@ -19,19 +19,19 @@ tslib_1.__exportStar(require("./isJobInList-1"), exports);
|
|
19
19
|
tslib_1.__exportStar(require("./moveJobFromActiveToWait-9"), exports);
|
20
20
|
tslib_1.__exportStar(require("./moveJobsToWait-6"), exports);
|
21
21
|
tslib_1.__exportStar(require("./moveStalledJobsToWait-8"), exports);
|
22
|
-
tslib_1.__exportStar(require("./moveToActive-
|
23
|
-
tslib_1.__exportStar(require("./moveToDelayed-
|
24
|
-
tslib_1.__exportStar(require("./moveToFinished-
|
22
|
+
tslib_1.__exportStar(require("./moveToActive-11"), exports);
|
23
|
+
tslib_1.__exportStar(require("./moveToDelayed-7"), exports);
|
24
|
+
tslib_1.__exportStar(require("./moveToFinished-14"), exports);
|
25
25
|
tslib_1.__exportStar(require("./moveToWaitingChildren-4"), exports);
|
26
26
|
tslib_1.__exportStar(require("./obliterate-2"), exports);
|
27
27
|
tslib_1.__exportStar(require("./paginate-1"), exports);
|
28
|
-
tslib_1.__exportStar(require("./pause-
|
29
|
-
tslib_1.__exportStar(require("./promote-
|
28
|
+
tslib_1.__exportStar(require("./pause-7"), exports);
|
29
|
+
tslib_1.__exportStar(require("./promote-8"), exports);
|
30
30
|
tslib_1.__exportStar(require("./releaseLock-1"), exports);
|
31
31
|
tslib_1.__exportStar(require("./removeJob-1"), exports);
|
32
32
|
tslib_1.__exportStar(require("./removeRepeatable-2"), exports);
|
33
33
|
tslib_1.__exportStar(require("./reprocessJob-6"), exports);
|
34
|
-
tslib_1.__exportStar(require("./retryJob-
|
34
|
+
tslib_1.__exportStar(require("./retryJob-10"), exports);
|
35
35
|
tslib_1.__exportStar(require("./saveStacktrace-1"), exports);
|
36
36
|
tslib_1.__exportStar(require("./updateData-1"), exports);
|
37
37
|
tslib_1.__exportStar(require("./updateProgress-3"), exports);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC;AAClC,2DAAiC;AACjC,gEAAsC;AACtC,6DAAmC;AACnC,0DAAgC;AAChC,6DAAmC;AACnC,6DAAmC;AACnC,oDAA0B;AAC1B,yDAA+B;AAC/B,wDAA8B;AAC9B,wDAA8B;AAC9B,uDAA6B;AAC7B,yDAA+B;AAC/B,yDAA+B;AAC/B,0DAAgC;AAChC,sEAA4C;AAC5C,6DAAmC;AACnC,oEAA0C;AAC1C,4DAAkC;AAClC,4DAAkC;AAClC,8DAAoC;AACpC,oEAA0C;AAC1C,yDAA+B;AAC/B,uDAA6B;AAC7B,oDAA0B;AAC1B,sDAA4B;AAC5B,0DAAgC;AAChC,wDAA8B;AAC9B,+DAAqC;AACrC,2DAAiC;AACjC,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC;AAClC,2DAAiC;AACjC,gEAAsC;AACtC,6DAAmC;AACnC,0DAAgC;AAChC,6DAAmC;AACnC,6DAAmC;AACnC,oDAA0B;AAC1B,yDAA+B;AAC/B,wDAA8B;AAC9B,wDAA8B;AAC9B,uDAA6B;AAC7B,yDAA+B;AAC/B,yDAA+B;AAC/B,0DAAgC;AAChC,sEAA4C;AAC5C,6DAAmC;AACnC,oEAA0C;AAC1C,4DAAkC;AAClC,4DAAkC;AAClC,8DAAoC;AACpC,oEAA0C;AAC1C,yDAA+B;AAC/B,uDAA6B;AAC7B,oDAA0B;AAC1B,sDAA4B;AAC5B,0DAAgC;AAChC,wDAA8B;AAC9B,+DAAqC;AACrC,2DAAiC;AACjC,wDAA8B;AAC9B,6DAAmC;AACnC,yDAA+B;AAC/B,6DAAmC"}
|
@@ -206,6 +206,7 @@ local function checkStalledJobs(stalledKey, waitKey, activeKey, failedKey,
|
|
206
206
|
local MAX_STALLED_JOB_COUNT = tonumber(maxStalledJobCount)
|
207
207
|
-- Remove from active list
|
208
208
|
for i, jobId in ipairs(stalling) do
|
209
|
+
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
209
210
|
if string.sub(jobId, 1, 2) == "0:" then
|
210
211
|
-- If the jobId is a delay marker ID we just remove it.
|
211
212
|
rcall("LREM", activeKey, 1, jobId)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"moveStalledJobsToWait-8.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"moveStalledJobsToWait-8.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwRf,CAAC;AACW,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -16,15 +16,16 @@ const content = `--[[
|
|
16
16
|
-- Rate limiting
|
17
17
|
KEYS[6] rate limiter key
|
18
18
|
KEYS[7] delayed key
|
19
|
-
--
|
19
|
+
-- Delayed jobs
|
20
20
|
KEYS[8] paused key
|
21
21
|
KEYS[9] meta key
|
22
22
|
KEYS[10] pc priority counter
|
23
|
+
-- Marker
|
24
|
+
KEYS[11] marker key
|
23
25
|
-- Arguments
|
24
26
|
ARGV[1] key prefix
|
25
27
|
ARGV[2] timestamp
|
26
|
-
ARGV[3]
|
27
|
-
ARGV[4] opts
|
28
|
+
ARGV[3] opts
|
28
29
|
opts - token - lock token
|
29
30
|
opts - lockDuration
|
30
31
|
opts - limiter
|
@@ -34,7 +35,7 @@ local waitKey = KEYS[1]
|
|
34
35
|
local activeKey = KEYS[2]
|
35
36
|
local rateLimiterKey = KEYS[6]
|
36
37
|
local delayedKey = KEYS[7]
|
37
|
-
local opts = cmsgpack.unpack(ARGV[
|
38
|
+
local opts = cmsgpack.unpack(ARGV[3])
|
38
39
|
-- Includes
|
39
40
|
--[[
|
40
41
|
Function to return the next delayed job timestamp.
|
@@ -145,7 +146,7 @@ local function prepareJobForProcessing(keys, keyPrefix, targetKey, jobId, proces
|
|
145
146
|
end
|
146
147
|
rcall("XADD", keys[4], "*", "event", "active", "jobId", jobId, "prev", "waiting")
|
147
148
|
rcall("HSET", jobKey, "processedOn", processedOn)
|
148
|
-
rcall("HINCRBY", jobKey, "
|
149
|
+
rcall("HINCRBY", jobKey, "ats", 1)
|
149
150
|
return {rcall("HGETALL", jobKey), jobId, 0, 0} -- get job data
|
150
151
|
end
|
151
152
|
--[[
|
@@ -158,29 +159,17 @@ end
|
|
158
159
|
--[[
|
159
160
|
Function to add job considering priority.
|
160
161
|
]]
|
161
|
-
|
162
|
-
--[[
|
163
|
-
Function priority marker to wait if needed
|
164
|
-
in order to wake up our workers and to respect priority
|
165
|
-
order as much as possible
|
166
|
-
]]
|
167
|
-
local function addPriorityMarkerIfNeeded(waitKey)
|
168
|
-
local waitLen = rcall("LLEN", waitKey)
|
169
|
-
if waitLen == 0 then
|
170
|
-
rcall("LPUSH", waitKey, "0:0")
|
171
|
-
end
|
172
|
-
end
|
173
|
-
local function addJobWithPriority(waitKey, prioritizedKey, priority, paused, jobId, priorityCounterKey)
|
162
|
+
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
174
163
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
175
164
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
176
165
|
rcall("ZADD", prioritizedKey, score, jobId)
|
177
|
-
if not
|
178
|
-
|
166
|
+
if not isPaused then
|
167
|
+
rcall("ZADD", markerKey, 0, "0")
|
179
168
|
end
|
180
169
|
end
|
181
170
|
-- Try to get as much as 1000 jobs at once
|
182
|
-
local function promoteDelayedJobs(delayedKey,
|
183
|
-
eventStreamKey, prefix, timestamp,
|
171
|
+
local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedKey,
|
172
|
+
eventStreamKey, prefix, timestamp, priorityCounterKey, isPaused)
|
184
173
|
local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000, "LIMIT", 0, 1000)
|
185
174
|
if (#jobs > 0) then
|
186
175
|
rcall("ZREM", delayedKey, unpack(jobs))
|
@@ -191,9 +180,12 @@ local function promoteDelayedJobs(delayedKey, waitKey, targetKey, prioritizedKey
|
|
191
180
|
if priority == 0 then
|
192
181
|
-- LIFO or FIFO
|
193
182
|
rcall("LPUSH", targetKey, jobId)
|
183
|
+
if not isPaused then
|
184
|
+
rcall("ZADD", markerKey, 0, "0")
|
185
|
+
end
|
194
186
|
else
|
195
|
-
addJobWithPriority(
|
196
|
-
jobId, priorityCounterKey)
|
187
|
+
addJobWithPriority(markerKey, prioritizedKey, priority,
|
188
|
+
jobId, priorityCounterKey, isPaused)
|
197
189
|
end
|
198
190
|
-- Emit waiting event
|
199
191
|
rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId",
|
@@ -204,31 +196,21 @@ local function promoteDelayedJobs(delayedKey, waitKey, targetKey, prioritizedKey
|
|
204
196
|
end
|
205
197
|
local target, paused = getTargetQueueList(KEYS[9], waitKey, KEYS[8])
|
206
198
|
-- Check if there are delayed jobs that we can move to wait.
|
207
|
-
|
208
|
-
|
199
|
+
local markerKey = KEYS[11]
|
200
|
+
promoteDelayedJobs(delayedKey, markerKey, target, KEYS[3], KEYS[4], ARGV[1],
|
201
|
+
ARGV[2], KEYS[10], paused)
|
209
202
|
local maxJobs = tonumber(opts['limiter'] and opts['limiter']['max'])
|
210
203
|
local expireTime = getRateLimitTTL(maxJobs, rateLimiterKey)
|
211
|
-
|
212
|
-
if
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
-- Check if we are rate limited first.
|
221
|
-
if expireTime > 0 then return {0, 0, expireTime, 0} end
|
222
|
-
-- paused queue
|
223
|
-
if paused then return {0, 0, 0, 0} end
|
224
|
-
-- no job ID, try non-blocking move from wait to active
|
204
|
+
-- Check if we are rate limited first.
|
205
|
+
if expireTime > 0 then return {0, 0, expireTime, 0} end
|
206
|
+
-- paused queue
|
207
|
+
if paused then return {0, 0, 0, 0} end
|
208
|
+
-- no job ID, try non-blocking move from wait to active
|
209
|
+
local jobId = rcall("RPOPLPUSH", waitKey, activeKey)
|
210
|
+
-- Markers in waitlist DEPRECATED in v5: Will be completely removed in v6.
|
211
|
+
if jobId and string.sub(jobId, 1, 2) == "0:" then
|
212
|
+
rcall("LREM", activeKey, 1, jobId)
|
225
213
|
jobId = rcall("RPOPLPUSH", waitKey, activeKey)
|
226
|
-
-- Since it is possible that between a call to BRPOPLPUSH and moveToActive
|
227
|
-
-- another script puts a new maker in wait, we need to check again.
|
228
|
-
if jobId and string.sub(jobId, 1, 2) == "0:" then
|
229
|
-
rcall("LREM", activeKey, 1, jobId)
|
230
|
-
jobId = rcall("RPOPLPUSH", waitKey, activeKey)
|
231
|
-
end
|
232
214
|
end
|
233
215
|
if jobId then
|
234
216
|
return prepareJobForProcessing(KEYS, ARGV[1], target, jobId, ARGV[2],
|
@@ -248,6 +230,6 @@ return {0, 0, 0, 0}
|
|
248
230
|
exports.moveToActive = {
|
249
231
|
name: 'moveToActive',
|
250
232
|
content,
|
251
|
-
keys:
|
233
|
+
keys: 11,
|
252
234
|
};
|
253
|
-
//# sourceMappingURL=moveToActive-
|
235
|
+
//# sourceMappingURL=moveToActive-11.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"moveToActive-11.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-11.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiOf,CAAC;AACW,QAAA,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.moveToDelayed = void 0;
|
4
|
+
const content = `--[[
|
5
|
+
Moves job from active to delayed set.
|
6
|
+
Input:
|
7
|
+
KEYS[1] marker key
|
8
|
+
KEYS[2] active key
|
9
|
+
KEYS[3] prioritized key
|
10
|
+
KEYS[4] delayed key
|
11
|
+
KEYS[5] job key
|
12
|
+
KEYS[6] events stream
|
13
|
+
KEYS[7] meta key
|
14
|
+
ARGV[1] key prefix
|
15
|
+
ARGV[2] timestamp
|
16
|
+
ARGV[3] delayedTimestamp
|
17
|
+
ARGV[4] the id of the job
|
18
|
+
ARGV[5] queue token
|
19
|
+
ARGV[6] delay value
|
20
|
+
ARGV[7] skip attempt
|
21
|
+
Output:
|
22
|
+
0 - OK
|
23
|
+
-1 - Missing job.
|
24
|
+
-3 - Job not in active set.
|
25
|
+
Events:
|
26
|
+
- delayed key.
|
27
|
+
]]
|
28
|
+
local rcall = redis.call
|
29
|
+
-- Includes
|
30
|
+
--[[
|
31
|
+
Add delay marker if needed.
|
32
|
+
]]
|
33
|
+
-- Includes
|
34
|
+
--[[
|
35
|
+
Function to return the next delayed job timestamp.
|
36
|
+
]]
|
37
|
+
local function getNextDelayedTimestamp(delayedKey)
|
38
|
+
local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
|
39
|
+
if #result then
|
40
|
+
local nextTimestamp = tonumber(result[2])
|
41
|
+
if (nextTimestamp ~= nil) then
|
42
|
+
nextTimestamp = nextTimestamp / 0x1000
|
43
|
+
end
|
44
|
+
return nextTimestamp
|
45
|
+
end
|
46
|
+
end
|
47
|
+
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
48
|
+
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
49
|
+
if nextTimestamp ~= nil then
|
50
|
+
-- Replace the score of the marker with the newest known
|
51
|
+
-- next timestamp.
|
52
|
+
rcall("ZADD", markerKey, nextTimestamp, "0")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
--[[
|
56
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
57
|
+
(since an empty list and !EXISTS are not really the same).
|
58
|
+
]]
|
59
|
+
local function isQueuePaused(queueMetaKey)
|
60
|
+
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
61
|
+
end
|
62
|
+
local jobKey = KEYS[5]
|
63
|
+
local metaKey = KEYS[7]
|
64
|
+
if rcall("EXISTS", jobKey) == 1 then
|
65
|
+
local delayedKey = KEYS[4]
|
66
|
+
if ARGV[5] ~= "0" then
|
67
|
+
local lockKey = jobKey .. ':lock'
|
68
|
+
if rcall("GET", lockKey) == ARGV[5] then
|
69
|
+
rcall("DEL", lockKey)
|
70
|
+
else
|
71
|
+
return -2
|
72
|
+
end
|
73
|
+
end
|
74
|
+
local jobId = ARGV[4]
|
75
|
+
local score = tonumber(ARGV[3])
|
76
|
+
local delayedTimestamp = (score / 0x1000)
|
77
|
+
local numRemovedElements = rcall("LREM", KEYS[2], -1, jobId)
|
78
|
+
if numRemovedElements < 1 then return -3 end
|
79
|
+
if ARGV[7] == "0" then
|
80
|
+
rcall("HINCRBY", jobKey, "atm", 1)
|
81
|
+
end
|
82
|
+
rcall("HSET", jobKey, "delay", ARGV[6])
|
83
|
+
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents") or 10000
|
84
|
+
rcall("ZADD", delayedKey, score, jobId)
|
85
|
+
rcall("XADD", KEYS[6], "MAXLEN", "~", maxEvents, "*", "event", "delayed",
|
86
|
+
"jobId", jobId, "delay", delayedTimestamp)
|
87
|
+
-- Check if we need to push a marker job to wake up sleeping workers.
|
88
|
+
local isPaused = isQueuePaused(metaKey)
|
89
|
+
if not isPaused then
|
90
|
+
local markerKey = KEYS[1]
|
91
|
+
addDelayMarkerIfNeeded(markerKey, delayedKey)
|
92
|
+
end
|
93
|
+
return 0
|
94
|
+
else
|
95
|
+
return -1
|
96
|
+
end
|
97
|
+
`;
|
98
|
+
exports.moveToDelayed = {
|
99
|
+
name: 'moveToDelayed',
|
100
|
+
content,
|
101
|
+
keys: 7,
|
102
|
+
};
|
103
|
+
//# sourceMappingURL=moveToDelayed-7.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"moveToDelayed-7.js","sourceRoot":"","sources":["../../../src/scripts/moveToDelayed-7.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6Ff,CAAC;AACW,QAAA,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|