bullmq 5.1.2 → 5.1.4
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/scripts.js +3 -1
- package/dist/cjs/classes/scripts.js.map +1 -1
- package/dist/cjs/commands/addStandardJob-7.lua +4 -8
- package/dist/cjs/commands/changeDelay-3.lua +1 -0
- package/dist/cjs/commands/changePriority-6.lua +0 -1
- package/dist/cjs/commands/includes/addBaseMarkerIfNeeded.lua +9 -0
- package/dist/cjs/commands/includes/addDelayMarkerIfNeeded.lua +3 -1
- package/dist/cjs/commands/includes/addJobInTargetList.lua +11 -0
- package/dist/cjs/commands/includes/addJobWithPriority.lua +5 -3
- package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +6 -4
- package/dist/cjs/commands/includes/promoteDelayedJobs.lua +2 -4
- package/dist/{esm/commands/moveJobsToWait-6.lua → cjs/commands/moveJobsToWait-7.lua} +5 -1
- package/dist/cjs/commands/moveStalledJobsToWait-9.lua +150 -0
- package/dist/cjs/commands/moveToFinished-14.lua +1 -0
- package/dist/cjs/commands/pause-7.lua +1 -0
- package/dist/cjs/commands/promote-8.lua +2 -2
- package/dist/cjs/commands/retryJob-10.lua +1 -0
- package/dist/cjs/scripts/addDelayedJob-6.js +21 -7
- package/dist/cjs/scripts/addDelayedJob-6.js.map +1 -1
- package/dist/cjs/scripts/addParentJob-4.js +25 -11
- package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
- package/dist/cjs/scripts/addPrioritizedJob-7.js +21 -7
- package/dist/cjs/scripts/addPrioritizedJob-7.js.map +1 -1
- package/dist/cjs/scripts/addStandardJob-7.js +46 -36
- package/dist/cjs/scripts/addStandardJob-7.js.map +1 -1
- package/dist/cjs/scripts/changeDelay-3.js +1 -0
- package/dist/cjs/scripts/changeDelay-3.js.map +1 -1
- package/dist/cjs/scripts/changePriority-6.js +10 -14
- package/dist/cjs/scripts/changePriority-6.js.map +1 -1
- package/dist/cjs/scripts/index.js +2 -2
- package/dist/cjs/scripts/{moveJobsToWait-6.js → moveJobsToWait-7.js} +13 -3
- package/dist/cjs/scripts/moveJobsToWait-7.js.map +1 -0
- package/dist/cjs/scripts/{moveStalledJobsToWait-8.js → moveStalledJobsToWait-9.js} +109 -106
- package/dist/cjs/scripts/{moveStalledJobsToWait-8.js.map → moveStalledJobsToWait-9.js.map} +1 -1
- package/dist/cjs/scripts/moveToActive-11.js +19 -7
- package/dist/cjs/scripts/moveToActive-11.js.map +1 -1
- package/dist/cjs/scripts/moveToDelayed-7.js +1 -1
- package/dist/cjs/scripts/moveToFinished-14.js +32 -21
- package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
- package/dist/cjs/scripts/pause-7.js +2 -1
- package/dist/cjs/scripts/pause-7.js.map +1 -1
- package/dist/cjs/scripts/promote-8.js +19 -5
- package/dist/cjs/scripts/promote-8.js.map +1 -1
- package/dist/cjs/scripts/retryJob-10.js +20 -7
- package/dist/cjs/scripts/retryJob-10.js.map +1 -1
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/esm/classes/scripts.js +3 -1
- package/dist/esm/classes/scripts.js.map +1 -1
- package/dist/esm/commands/addStandardJob-7.lua +4 -8
- package/dist/esm/commands/changeDelay-3.lua +1 -0
- package/dist/esm/commands/changePriority-6.lua +0 -1
- package/dist/esm/commands/includes/addBaseMarkerIfNeeded.lua +9 -0
- package/dist/esm/commands/includes/addDelayMarkerIfNeeded.lua +3 -1
- package/dist/esm/commands/includes/addJobInTargetList.lua +11 -0
- package/dist/esm/commands/includes/addJobWithPriority.lua +5 -3
- package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +6 -4
- package/dist/esm/commands/includes/promoteDelayedJobs.lua +2 -4
- package/dist/{cjs/commands/moveJobsToWait-6.lua → esm/commands/moveJobsToWait-7.lua} +5 -1
- package/dist/esm/commands/moveStalledJobsToWait-9.lua +150 -0
- package/dist/esm/commands/moveToFinished-14.lua +1 -0
- package/dist/esm/commands/pause-7.lua +1 -0
- package/dist/esm/commands/promote-8.lua +2 -2
- package/dist/esm/commands/retryJob-10.lua +1 -0
- package/dist/esm/scripts/addDelayedJob-6.js +21 -7
- package/dist/esm/scripts/addDelayedJob-6.js.map +1 -1
- package/dist/esm/scripts/addParentJob-4.js +25 -11
- package/dist/esm/scripts/addParentJob-4.js.map +1 -1
- package/dist/esm/scripts/addPrioritizedJob-7.js +21 -7
- package/dist/esm/scripts/addPrioritizedJob-7.js.map +1 -1
- package/dist/esm/scripts/addStandardJob-7.js +46 -36
- package/dist/esm/scripts/addStandardJob-7.js.map +1 -1
- package/dist/esm/scripts/changeDelay-3.js +1 -0
- package/dist/esm/scripts/changeDelay-3.js.map +1 -1
- package/dist/esm/scripts/changePriority-6.js +10 -14
- package/dist/esm/scripts/changePriority-6.js.map +1 -1
- package/dist/esm/scripts/index.d.ts +2 -2
- package/dist/esm/scripts/index.js +2 -2
- package/dist/esm/scripts/{moveJobsToWait-6.js → moveJobsToWait-7.js} +13 -3
- package/dist/esm/scripts/moveJobsToWait-7.js.map +1 -0
- package/dist/esm/scripts/{moveStalledJobsToWait-8.js → moveStalledJobsToWait-9.js} +109 -106
- package/dist/esm/scripts/{moveStalledJobsToWait-8.js.map → moveStalledJobsToWait-9.js.map} +1 -1
- package/dist/esm/scripts/moveToActive-11.js +19 -7
- package/dist/esm/scripts/moveToActive-11.js.map +1 -1
- package/dist/esm/scripts/moveToDelayed-7.js +1 -1
- package/dist/esm/scripts/moveToFinished-14.js +32 -21
- package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
- package/dist/esm/scripts/pause-7.js +2 -1
- package/dist/esm/scripts/pause-7.js.map +1 -1
- package/dist/esm/scripts/promote-8.js +19 -5
- package/dist/esm/scripts/promote-8.js.map +1 -1
- package/dist/esm/scripts/retryJob-10.js +20 -7
- package/dist/esm/scripts/retryJob-10.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/commands/includes/checkStalledJobs.lua +0 -139
- package/dist/cjs/commands/moveStalledJobsToWait-8.lua +0 -24
- package/dist/cjs/scripts/moveJobsToWait-6.js.map +0 -1
- package/dist/esm/commands/includes/checkStalledJobs.lua +0 -139
- package/dist/esm/commands/moveStalledJobsToWait-8.lua +0 -24
- package/dist/esm/scripts/moveJobsToWait-6.js.map +0 -1
- /package/dist/esm/scripts/{moveJobsToWait-6.d.ts → moveJobsToWait-7.d.ts} +0 -0
- /package/dist/esm/scripts/{moveStalledJobsToWait-8.d.ts → moveStalledJobsToWait-9.d.ts} +0 -0
@@ -14,8 +14,8 @@ export * from './getStateV2-8';
|
|
14
14
|
export * from './isFinished-3';
|
15
15
|
export * from './isJobInList-1';
|
16
16
|
export * from './moveJobFromActiveToWait-9';
|
17
|
-
export * from './moveJobsToWait-
|
18
|
-
export * from './moveStalledJobsToWait-
|
17
|
+
export * from './moveJobsToWait-7';
|
18
|
+
export * from './moveStalledJobsToWait-9';
|
19
19
|
export * from './moveToActive-11';
|
20
20
|
export * from './moveToDelayed-7';
|
21
21
|
export * from './moveToFinished-14';
|
@@ -8,6 +8,7 @@ const content = `--[[
|
|
8
8
|
KEYS[4] 'wait'
|
9
9
|
KEYS[5] 'paused'
|
10
10
|
KEYS[6] 'meta'
|
11
|
+
KEYS[7] 'marker'
|
11
12
|
ARGV[1] count
|
12
13
|
ARGV[2] timestamp
|
13
14
|
ARGV[3] prev state
|
@@ -19,6 +20,14 @@ local maxCount = tonumber(ARGV[1])
|
|
19
20
|
local timestamp = tonumber(ARGV[2])
|
20
21
|
local rcall = redis.call;
|
21
22
|
-- Includes
|
23
|
+
--[[
|
24
|
+
Add marker if needed when a job is available.
|
25
|
+
]]
|
26
|
+
local function addBaseMarkerIfNeeded(markerKey, isPaused)
|
27
|
+
if not isPaused then
|
28
|
+
rcall("ZADD", markerKey, 0, "0")
|
29
|
+
end
|
30
|
+
end
|
22
31
|
--[[
|
23
32
|
Function to loop in batches.
|
24
33
|
Just a bit of warning, some commands as ZREM
|
@@ -58,7 +67,7 @@ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
|
|
58
67
|
end
|
59
68
|
end
|
60
69
|
local metaKey = KEYS[6]
|
61
|
-
local target = getTargetQueueList(metaKey, KEYS[4], KEYS[5])
|
70
|
+
local target, paused = getTargetQueueList(metaKey, KEYS[4], KEYS[5])
|
62
71
|
local jobs = rcall('ZRANGEBYSCORE', KEYS[3], 0, timestamp, 'LIMIT', 0, maxCount)
|
63
72
|
if (#jobs > 0) then
|
64
73
|
if ARGV[3] == "failed" then
|
@@ -82,6 +91,7 @@ if (#jobs > 0) then
|
|
82
91
|
rcall("ZREM", KEYS[3], unpack(jobs, from, to))
|
83
92
|
rcall("LPUSH", target, unpack(jobs, from, to))
|
84
93
|
end
|
94
|
+
addBaseMarkerIfNeeded(KEYS[7], paused)
|
85
95
|
end
|
86
96
|
maxCount = maxCount - #jobs
|
87
97
|
if (maxCount <= 0) then return 1 end
|
@@ -90,6 +100,6 @@ return 0
|
|
90
100
|
export const moveJobsToWait = {
|
91
101
|
name: 'moveJobsToWait',
|
92
102
|
content,
|
93
|
-
keys:
|
103
|
+
keys: 7,
|
94
104
|
};
|
95
|
-
//# sourceMappingURL=moveJobsToWait-
|
105
|
+
//# sourceMappingURL=moveJobsToWait-7.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"moveJobsToWait-7.js","sourceRoot":"","sources":["../../../src/scripts/moveJobsToWait-7.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkGf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -8,34 +8,33 @@ const content = `--[[
|
|
8
8
|
KEYS[5] 'stalled-check', (KEY)
|
9
9
|
KEYS[6] 'meta', (KEY)
|
10
10
|
KEYS[7] 'paused', (LIST)
|
11
|
-
KEYS[8] '
|
11
|
+
KEYS[8] 'marker'
|
12
|
+
KEYS[9] 'event stream' (STREAM)
|
12
13
|
ARGV[1] Max stalled job count
|
13
14
|
ARGV[2] queue.toKey('')
|
14
15
|
ARGV[3] timestamp
|
15
16
|
ARGV[4] max check time
|
16
17
|
Events:
|
17
18
|
'stalled' with stalled job id.
|
18
|
-
]] -- Includes
|
19
|
-
--[[
|
20
|
-
Move stalled jobs to wait.
|
21
|
-
Input:
|
22
|
-
stalledKey 'stalled' (SET)
|
23
|
-
waitKey 'wait', (LIST)
|
24
|
-
activeKey 'active', (LIST)
|
25
|
-
failedKey 'failed', (ZSET)
|
26
|
-
stalledCheckKey 'stalled-check', (KEY)
|
27
|
-
metaKey 'meta', (KEY)
|
28
|
-
pausedKey 'paused', (LIST)
|
29
|
-
eventStreamKey 'event stream' (STREAM)
|
30
|
-
maxStalledJobCount Max stalled job count
|
31
|
-
queueKeyPrefix queue.toKey('')
|
32
|
-
timestamp timestamp
|
33
|
-
maxCheckTime max check time
|
34
|
-
Events:
|
35
|
-
'stalled' with stalled job id.
|
36
19
|
]]
|
37
20
|
local rcall = redis.call
|
38
21
|
-- Includes
|
22
|
+
--[[
|
23
|
+
Function to add job in target list and add marker if needed.
|
24
|
+
]]
|
25
|
+
-- Includes
|
26
|
+
--[[
|
27
|
+
Add marker if needed when a job is available.
|
28
|
+
]]
|
29
|
+
local function addBaseMarkerIfNeeded(markerKey, isPaused)
|
30
|
+
if not isPaused then
|
31
|
+
rcall("ZADD", markerKey, 0, "0")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
|
35
|
+
rcall(pushCmd, targetKey, jobId)
|
36
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
37
|
+
end
|
39
38
|
--[[
|
40
39
|
Function to loop in batches.
|
41
40
|
Just a bit of warning, some commands as ZREM
|
@@ -197,103 +196,107 @@ local function trimEvents(metaKey, eventStreamKey)
|
|
197
196
|
rcall("XTRIM", eventStreamKey, "MAXLEN", "~", 10000)
|
198
197
|
end
|
199
198
|
end
|
200
|
-
|
201
|
-
local
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
199
|
+
local stalledKey = KEYS[1]
|
200
|
+
local waitKey = KEYS[2]
|
201
|
+
local activeKey = KEYS[3]
|
202
|
+
local failedKey = KEYS[4]
|
203
|
+
local stalledCheckKey = KEYS[5]
|
204
|
+
local metaKey = KEYS[6]
|
205
|
+
local pausedKey = KEYS[7]
|
206
|
+
local markerKey = KEYS[8]
|
207
|
+
local eventStreamKey = KEYS[9]
|
208
|
+
local maxStalledJobCount = ARGV[1]
|
209
|
+
local queueKeyPrefix = ARGV[2]
|
210
|
+
local timestamp = ARGV[3]
|
211
|
+
local maxCheckTime = ARGV[4]
|
212
|
+
if rcall("EXISTS", stalledCheckKey) == 1 then return {{}, {}} end
|
213
|
+
rcall("SET", stalledCheckKey, timestamp, "PX", maxCheckTime)
|
214
|
+
-- Trim events before emiting them to avoid trimming events emitted in this script
|
215
|
+
trimEvents(metaKey, eventStreamKey)
|
216
|
+
-- Move all stalled jobs to wait
|
217
|
+
local stalling = rcall('SMEMBERS', stalledKey)
|
218
|
+
local stalled = {}
|
219
|
+
local failed = {}
|
220
|
+
if (#stalling > 0) then
|
221
|
+
rcall('DEL', stalledKey)
|
222
|
+
local MAX_STALLED_JOB_COUNT = tonumber(maxStalledJobCount)
|
223
|
+
-- Remove from active list
|
224
|
+
for i, jobId in ipairs(stalling) do
|
225
|
+
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
226
|
+
if string.sub(jobId, 1, 2) == "0:" then
|
227
|
+
-- If the jobId is a delay marker ID we just remove it.
|
228
|
+
rcall("LREM", activeKey, 1, jobId)
|
229
|
+
else
|
230
|
+
local jobKey = queueKeyPrefix .. jobId
|
231
|
+
-- Check that the lock is also missing, then we can handle this job as really stalled.
|
232
|
+
if (rcall("EXISTS", jobKey .. ":lock") == 0) then
|
233
|
+
-- Remove from the active queue.
|
234
|
+
local removed = rcall("LREM", activeKey, 1, jobId)
|
235
|
+
if (removed > 0) then
|
236
|
+
-- If this job has been stalled too many times, such as if it crashes the worker, then fail it.
|
237
|
+
local stalledCount =
|
238
|
+
rcall("HINCRBY", jobKey, "stalledCounter", 1)
|
239
|
+
if (stalledCount > MAX_STALLED_JOB_COUNT) then
|
240
|
+
local rawOpts = rcall("HGET", jobKey, "opts")
|
241
|
+
local opts = cjson.decode(rawOpts)
|
242
|
+
local removeOnFailType = type(opts["removeOnFail"])
|
243
|
+
rcall("ZADD", failedKey, timestamp, jobId)
|
244
|
+
local failedReason =
|
245
|
+
"job stalled more than allowable limit"
|
246
|
+
rcall("HMSET", jobKey, "failedReason", failedReason,
|
247
|
+
"finishedOn", timestamp)
|
248
|
+
rcall("XADD", eventStreamKey, "*", "event",
|
249
|
+
"failed", "jobId", jobId, 'prev', 'active',
|
250
|
+
'failedReason', failedReason)
|
251
|
+
if removeOnFailType == "number" then
|
252
|
+
removeJobsByMaxCount(opts["removeOnFail"],
|
253
|
+
failedKey, queueKeyPrefix)
|
254
|
+
elseif removeOnFailType == "boolean" then
|
255
|
+
if opts["removeOnFail"] then
|
256
|
+
removeJob(jobId, false, queueKeyPrefix)
|
257
|
+
rcall("ZREM", failedKey, jobId)
|
258
|
+
end
|
259
|
+
elseif removeOnFailType ~= "nil" then
|
260
|
+
local maxAge = opts["removeOnFail"]["age"]
|
261
|
+
local maxCount = opts["removeOnFail"]["count"]
|
262
|
+
if maxAge ~= nil then
|
263
|
+
removeJobsByMaxAge(timestamp, maxAge,
|
264
|
+
failedKey, queueKeyPrefix)
|
265
|
+
end
|
266
|
+
if maxCount ~= nil and maxCount > 0 then
|
267
|
+
removeJobsByMaxCount(maxCount, failedKey,
|
268
|
+
queueKeyPrefix)
|
263
269
|
end
|
264
|
-
table.insert(failed, jobId)
|
265
|
-
else
|
266
|
-
local target =
|
267
|
-
getTargetQueueList(metaKey, waitKey, pausedKey)
|
268
|
-
-- Move the job back to the wait queue, to immediately be picked up by a waiting worker.
|
269
|
-
rcall("RPUSH", target, jobId)
|
270
|
-
rcall("XADD", eventStreamKey, "*", "event",
|
271
|
-
"waiting", "jobId", jobId, 'prev', 'active')
|
272
|
-
-- Emit the stalled event
|
273
|
-
rcall("XADD", eventStreamKey, "*", "event",
|
274
|
-
"stalled", "jobId", jobId)
|
275
|
-
table.insert(stalled, jobId)
|
276
270
|
end
|
271
|
+
table.insert(failed, jobId)
|
272
|
+
else
|
273
|
+
local target, isPaused=
|
274
|
+
getTargetQueueList(metaKey, waitKey, pausedKey)
|
275
|
+
-- Move the job back to the wait queue, to immediately be picked up by a waiting worker.
|
276
|
+
addJobInTargetList(target, markerKey, "RPUSH", isPaused, jobId)
|
277
|
+
rcall("XADD", eventStreamKey, "*", "event",
|
278
|
+
"waiting", "jobId", jobId, 'prev', 'active')
|
279
|
+
-- Emit the stalled event
|
280
|
+
rcall("XADD", eventStreamKey, "*", "event",
|
281
|
+
"stalled", "jobId", jobId)
|
282
|
+
table.insert(stalled, jobId)
|
277
283
|
end
|
278
284
|
end
|
279
285
|
end
|
280
286
|
end
|
281
287
|
end
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
+
end
|
289
|
+
-- Mark potentially stalled jobs
|
290
|
+
local active = rcall('LRANGE', activeKey, 0, -1)
|
291
|
+
if (#active > 0) then
|
292
|
+
for from, to in batches(#active, 7000) do
|
293
|
+
rcall('SADD', stalledKey, unpack(active, from, to))
|
288
294
|
end
|
289
|
-
return {failed, stalled}
|
290
295
|
end
|
291
|
-
return
|
292
|
-
KEYS[7], KEYS[8], ARGV[1], ARGV[2], ARGV[3], ARGV[4])
|
293
|
-
`;
|
296
|
+
return {failed, stalled}`;
|
294
297
|
export const moveStalledJobsToWait = {
|
295
298
|
name: 'moveStalledJobsToWait',
|
296
299
|
content,
|
297
|
-
keys:
|
300
|
+
keys: 9,
|
298
301
|
};
|
299
|
-
//# sourceMappingURL=moveStalledJobsToWait-
|
302
|
+
//# sourceMappingURL=moveStalledJobsToWait-9.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"moveStalledJobsToWait-
|
1
|
+
{"version":3,"file":"moveStalledJobsToWait-9.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAuSS,CAAC;AAC1B,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -156,16 +156,31 @@ end
|
|
156
156
|
'waiting'
|
157
157
|
]]
|
158
158
|
-- Includes
|
159
|
+
--[[
|
160
|
+
Function to add job in target list and add marker if needed.
|
161
|
+
]]
|
162
|
+
-- Includes
|
163
|
+
--[[
|
164
|
+
Add marker if needed when a job is available.
|
165
|
+
]]
|
166
|
+
local function addBaseMarkerIfNeeded(markerKey, isPaused)
|
167
|
+
if not isPaused then
|
168
|
+
rcall("ZADD", markerKey, 0, "0")
|
169
|
+
end
|
170
|
+
end
|
171
|
+
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
|
172
|
+
rcall(pushCmd, targetKey, jobId)
|
173
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
174
|
+
end
|
159
175
|
--[[
|
160
176
|
Function to add job considering priority.
|
161
177
|
]]
|
178
|
+
-- Includes
|
162
179
|
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
163
180
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
164
181
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
165
182
|
rcall("ZADD", prioritizedKey, score, jobId)
|
166
|
-
|
167
|
-
rcall("ZADD", markerKey, 0, "0")
|
168
|
-
end
|
183
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
169
184
|
end
|
170
185
|
-- Try to get as much as 1000 jobs at once
|
171
186
|
local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedKey,
|
@@ -179,10 +194,7 @@ local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedK
|
|
179
194
|
tonumber(rcall("HGET", jobKey, "priority")) or 0
|
180
195
|
if priority == 0 then
|
181
196
|
-- LIFO or FIFO
|
182
|
-
|
183
|
-
if not isPaused then
|
184
|
-
rcall("ZADD", markerKey, 0, "0")
|
185
|
-
end
|
197
|
+
addJobInTargetList(targetKey, markerKey, "LPUSH", isPaused, jobId)
|
186
198
|
else
|
187
199
|
addJobWithPriority(markerKey, prioritizedKey, priority,
|
188
200
|
jobId, priorityCounterKey, isPaused)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"moveToActive-11.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-11.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"moveToActive-11.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-11.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgPf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
|
@@ -113,6 +113,17 @@ local function getNextDelayedTimestamp(delayedKey)
|
|
113
113
|
return nextTimestamp
|
114
114
|
end
|
115
115
|
end
|
116
|
+
--[[
|
117
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
118
|
+
(since an empty list and !EXISTS are not really the same).
|
119
|
+
]]
|
120
|
+
local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
|
121
|
+
if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
|
122
|
+
return waitKey, false
|
123
|
+
else
|
124
|
+
return pausedKey, true
|
125
|
+
end
|
126
|
+
end
|
116
127
|
--[[
|
117
128
|
Function to move job from prioritized state to active.
|
118
129
|
]]
|
@@ -199,7 +210,7 @@ end
|
|
199
210
|
-- Includes
|
200
211
|
--[[
|
201
212
|
Add delay marker if needed.
|
202
|
-
]]
|
213
|
+
]]
|
203
214
|
-- Includes
|
204
215
|
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
205
216
|
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
@@ -210,33 +221,37 @@ local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
|
210
221
|
end
|
211
222
|
end
|
212
223
|
--[[
|
213
|
-
Function to
|
214
|
-
(since an empty list and !EXISTS are not really the same).
|
224
|
+
Function to add job in target list and add marker if needed.
|
215
225
|
]]
|
216
|
-
|
217
|
-
|
226
|
+
-- Includes
|
227
|
+
--[[
|
228
|
+
Add marker if needed when a job is available.
|
229
|
+
]]
|
230
|
+
local function addBaseMarkerIfNeeded(markerKey, isPaused)
|
231
|
+
if not isPaused then
|
232
|
+
rcall("ZADD", markerKey, 0, "0")
|
233
|
+
end
|
234
|
+
end
|
235
|
+
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
|
236
|
+
rcall(pushCmd, targetKey, jobId)
|
237
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
218
238
|
end
|
219
239
|
--[[
|
220
240
|
Function to add job considering priority.
|
221
241
|
]]
|
242
|
+
-- Includes
|
222
243
|
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
223
244
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
224
245
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
225
246
|
rcall("ZADD", prioritizedKey, score, jobId)
|
226
|
-
|
227
|
-
rcall("ZADD", markerKey, 0, "0")
|
228
|
-
end
|
247
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
229
248
|
end
|
230
249
|
--[[
|
231
250
|
Function to check for the meta.paused key to decide if we are paused or not
|
232
251
|
(since an empty list and !EXISTS are not really the same).
|
233
252
|
]]
|
234
|
-
local function
|
235
|
-
|
236
|
-
return waitKey, false
|
237
|
-
else
|
238
|
-
return pausedKey, true
|
239
|
-
end
|
253
|
+
local function isQueuePaused(queueMetaKey)
|
254
|
+
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
240
255
|
end
|
241
256
|
local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
242
257
|
parentKey, parentId, timestamp)
|
@@ -261,11 +276,10 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
|
261
276
|
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
262
277
|
else
|
263
278
|
if priority == 0 then
|
264
|
-
local parentTarget,
|
279
|
+
local parentTarget, isParentPaused =
|
265
280
|
getTargetQueueList(parentMetaKey, parentWaitKey,
|
266
281
|
parentPausedKey)
|
267
|
-
|
268
|
-
rcall("ZADD", parentMarkerKey, 0, "0")
|
282
|
+
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
|
269
283
|
else
|
270
284
|
local isPaused = isQueuePaused(parentMetaKey)
|
271
285
|
addJobWithPriority(parentMarkerKey,
|
@@ -325,10 +339,7 @@ local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedK
|
|
325
339
|
tonumber(rcall("HGET", jobKey, "priority")) or 0
|
326
340
|
if priority == 0 then
|
327
341
|
-- LIFO or FIFO
|
328
|
-
|
329
|
-
if not isPaused then
|
330
|
-
rcall("ZADD", markerKey, 0, "0")
|
331
|
-
end
|
342
|
+
addJobInTargetList(targetKey, markerKey, "LPUSH", isPaused, jobId)
|
332
343
|
else
|
333
344
|
addJobWithPriority(markerKey, prioritizedKey, priority,
|
334
345
|
jobId, priorityCounterKey, isPaused)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"moveToFinished-14.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-14.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"moveToFinished-14.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-14.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2qBf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
|
@@ -16,7 +16,7 @@ local rcall = redis.call
|
|
16
16
|
-- Includes
|
17
17
|
--[[
|
18
18
|
Add delay marker if needed.
|
19
|
-
]]
|
19
|
+
]]
|
20
20
|
-- Includes
|
21
21
|
--[[
|
22
22
|
Function to return the next delayed job timestamp.
|
@@ -41,6 +41,7 @@ local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
|
41
41
|
end
|
42
42
|
local markerKey = KEYS[7]
|
43
43
|
local hasJobs = rcall("EXISTS", KEYS[1]) == 1
|
44
|
+
--TODO: check this logic to be reused when changing a delay
|
44
45
|
if hasJobs then rcall("RENAME", KEYS[1], KEYS[2]) end
|
45
46
|
if ARGV[1] == "paused" then
|
46
47
|
rcall("HSET", KEYS[3], "paused", 1)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pause-7.js","sourceRoot":"","sources":["../../../src/scripts/pause-7.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"pause-7.js","sourceRoot":"","sources":["../../../src/scripts/pause-7.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Df,CAAC;AACF,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,OAAO;IACb,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -20,16 +20,31 @@ const content = `--[[
|
|
20
20
|
local rcall = redis.call
|
21
21
|
local jobId = ARGV[2]
|
22
22
|
-- Includes
|
23
|
+
--[[
|
24
|
+
Function to add job in target list and add marker if needed.
|
25
|
+
]]
|
26
|
+
-- Includes
|
27
|
+
--[[
|
28
|
+
Add marker if needed when a job is available.
|
29
|
+
]]
|
30
|
+
local function addBaseMarkerIfNeeded(markerKey, isPaused)
|
31
|
+
if not isPaused then
|
32
|
+
rcall("ZADD", markerKey, 0, "0")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
|
36
|
+
rcall(pushCmd, targetKey, jobId)
|
37
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
38
|
+
end
|
23
39
|
--[[
|
24
40
|
Function to add job considering priority.
|
25
41
|
]]
|
42
|
+
-- Includes
|
26
43
|
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
27
44
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
28
45
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
29
46
|
rcall("ZADD", prioritizedKey, score, jobId)
|
30
|
-
|
31
|
-
rcall("ZADD", markerKey, 0, "0")
|
32
|
-
end
|
47
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
33
48
|
end
|
34
49
|
--[[
|
35
50
|
Function to check for the meta.paused key to decide if we are paused or not
|
@@ -54,8 +69,7 @@ if rcall("ZREM", KEYS[1], jobId) == 1 then
|
|
54
69
|
if marker and string.sub(marker, 1, 2) == "0:" then rcall("LPOP", target) end
|
55
70
|
if priority == 0 then
|
56
71
|
-- LIFO or FIFO
|
57
|
-
|
58
|
-
if not paused then rcall("ZADD", KEYS[8], 0, "0") end
|
72
|
+
addJobInTargetList(target, KEYS[8], "LPUSH", paused, jobId)
|
59
73
|
else
|
60
74
|
addJobWithPriority(KEYS[8], KEYS[5], priority, jobId, KEYS[6], paused)
|
61
75
|
end
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"promote-8.js","sourceRoot":"","sources":["../../../src/scripts/promote-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"promote-8.js","sourceRoot":"","sources":["../../../src/scripts/promote-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmFf,CAAC;AACF,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,IAAI,EAAE,SAAS;IACf,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -28,13 +28,20 @@ local rcall = redis.call
|
|
28
28
|
--[[
|
29
29
|
Function to add job considering priority.
|
30
30
|
]]
|
31
|
+
-- Includes
|
32
|
+
--[[
|
33
|
+
Add marker if needed when a job is available.
|
34
|
+
]]
|
35
|
+
local function addBaseMarkerIfNeeded(markerKey, isPaused)
|
36
|
+
if not isPaused then
|
37
|
+
rcall("ZADD", markerKey, 0, "0")
|
38
|
+
end
|
39
|
+
end
|
31
40
|
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
32
41
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
33
42
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
34
43
|
rcall("ZADD", prioritizedKey, score, jobId)
|
35
|
-
|
36
|
-
rcall("ZADD", markerKey, 0, "0")
|
37
|
-
end
|
44
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
38
45
|
end
|
39
46
|
--[[
|
40
47
|
Function to get max events value or set by default 10000.
|
@@ -65,6 +72,14 @@ end
|
|
65
72
|
'waiting'
|
66
73
|
]]
|
67
74
|
-- Includes
|
75
|
+
--[[
|
76
|
+
Function to add job in target list and add marker if needed.
|
77
|
+
]]
|
78
|
+
-- Includes
|
79
|
+
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
|
80
|
+
rcall(pushCmd, targetKey, jobId)
|
81
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
82
|
+
end
|
68
83
|
-- Try to get as much as 1000 jobs at once
|
69
84
|
local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedKey,
|
70
85
|
eventStreamKey, prefix, timestamp, priorityCounterKey, isPaused)
|
@@ -77,10 +92,7 @@ local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedK
|
|
77
92
|
tonumber(rcall("HGET", jobKey, "priority")) or 0
|
78
93
|
if priority == 0 then
|
79
94
|
-- LIFO or FIFO
|
80
|
-
|
81
|
-
if not isPaused then
|
82
|
-
rcall("ZADD", markerKey, 0, "0")
|
83
|
-
end
|
95
|
+
addJobInTargetList(targetKey, markerKey, "LPUSH", isPaused, jobId)
|
84
96
|
else
|
85
97
|
addJobWithPriority(markerKey, prioritizedKey, priority,
|
86
98
|
jobId, priorityCounterKey, isPaused)
|
@@ -111,6 +123,7 @@ if rcall("EXISTS", KEYS[4]) == 1 then
|
|
111
123
|
-- Standard or priority add
|
112
124
|
if priority == 0 then
|
113
125
|
rcall(ARGV[3], target, ARGV[4])
|
126
|
+
-- TODO: check if we need to add marker in this case too
|
114
127
|
else
|
115
128
|
addJobWithPriority(markerKey, KEYS[8], priority, ARGV[4], KEYS[9], paused)
|
116
129
|
end
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"retryJob-10.js","sourceRoot":"","sources":["../../../src/scripts/retryJob-10.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"retryJob-10.js","sourceRoot":"","sources":["../../../src/scripts/retryJob-10.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0If,CAAC;AACF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,UAAU;IAChB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
|