bullmq 5.49.1 → 5.50.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/job.js +23 -18
- package/dist/cjs/classes/job.js.map +1 -1
- package/dist/cjs/classes/queue.js +0 -1
- package/dist/cjs/classes/queue.js.map +1 -1
- package/dist/cjs/classes/worker.js +4 -0
- package/dist/cjs/classes/worker.js.map +1 -1
- package/dist/cjs/commands/includes/moveChildFromDependenciesIfNeeded.lua +15 -32
- package/dist/cjs/commands/includes/moveParentToWait.lua +32 -33
- package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +8 -4
- package/dist/cjs/commands/includes/moveParentToWaitIfNoPendingDependencies.lua +13 -0
- package/dist/cjs/commands/includes/removeDeduplicationKeyIfNeededOnFinalization.lua +23 -0
- package/dist/cjs/commands/includes/removeDeduplicationKeyIfNeededOnRemoval.lua +16 -0
- package/dist/cjs/commands/includes/removeJob.lua +2 -2
- package/dist/cjs/commands/includes/removeJobWithChildren.lua +2 -2
- package/dist/cjs/commands/includes/updateParentDepsIfNeeded.lua +2 -2
- package/dist/cjs/commands/moveStalledJobsToWait-9.lua +2 -4
- package/dist/cjs/commands/moveToFinished-14.lua +7 -5
- package/dist/cjs/commands/moveToWaitingChildren-8.lua +2 -4
- package/dist/cjs/scripts/addDelayedJob-6.js +51 -37
- package/dist/cjs/scripts/addDelayedJob-6.js.map +1 -1
- package/dist/cjs/scripts/addJobScheduler-11.js +9 -4
- package/dist/cjs/scripts/addJobScheduler-11.js.map +1 -1
- package/dist/cjs/scripts/addParentJob-4.js +51 -37
- package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
- package/dist/cjs/scripts/addPrioritizedJob-8.js +51 -37
- package/dist/cjs/scripts/addPrioritizedJob-8.js.map +1 -1
- package/dist/cjs/scripts/addRepeatableJob-2.js +9 -4
- package/dist/cjs/scripts/addRepeatableJob-2.js.map +1 -1
- package/dist/cjs/scripts/addStandardJob-8.js +51 -37
- package/dist/cjs/scripts/addStandardJob-8.js.map +1 -1
- package/dist/cjs/scripts/cleanJobsInSet-3.js +9 -4
- package/dist/cjs/scripts/cleanJobsInSet-3.js.map +1 -1
- package/dist/cjs/scripts/drain-5.js +9 -4
- package/dist/cjs/scripts/drain-5.js.map +1 -1
- package/dist/cjs/scripts/moveStalledJobsToWait-9.js +92 -76
- package/dist/cjs/scripts/moveStalledJobsToWait-9.js.map +1 -1
- package/dist/cjs/scripts/moveToFinished-14.js +97 -78
- package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
- package/dist/cjs/scripts/moveToWaitingChildren-8.js +92 -76
- package/dist/cjs/scripts/moveToWaitingChildren-8.js.map +1 -1
- package/dist/cjs/scripts/obliterate-2.js +9 -4
- package/dist/cjs/scripts/obliterate-2.js.map +1 -1
- package/dist/cjs/scripts/removeJob-3.js +9 -4
- package/dist/cjs/scripts/removeJob-3.js.map +1 -1
- package/dist/cjs/scripts/removeUnprocessedChildren-2.js +9 -4
- package/dist/cjs/scripts/removeUnprocessedChildren-2.js.map +1 -1
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/cjs/utils.js +11 -1
- package/dist/cjs/utils.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/classes/job.d.ts +21 -4
- package/dist/esm/classes/job.js +24 -19
- package/dist/esm/classes/job.js.map +1 -1
- package/dist/esm/classes/queue.d.ts +0 -1
- package/dist/esm/classes/queue.js +0 -1
- package/dist/esm/classes/queue.js.map +1 -1
- package/dist/esm/classes/worker.js +5 -1
- package/dist/esm/classes/worker.js.map +1 -1
- package/dist/esm/commands/includes/moveChildFromDependenciesIfNeeded.lua +15 -32
- package/dist/esm/commands/includes/moveParentToWait.lua +32 -33
- package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +8 -4
- package/dist/esm/commands/includes/moveParentToWaitIfNoPendingDependencies.lua +13 -0
- package/dist/esm/commands/includes/removeDeduplicationKeyIfNeededOnFinalization.lua +23 -0
- package/dist/esm/commands/includes/removeDeduplicationKeyIfNeededOnRemoval.lua +16 -0
- package/dist/esm/commands/includes/removeJob.lua +2 -2
- package/dist/esm/commands/includes/removeJobWithChildren.lua +2 -2
- package/dist/esm/commands/includes/updateParentDepsIfNeeded.lua +2 -2
- package/dist/esm/commands/moveStalledJobsToWait-9.lua +2 -4
- package/dist/esm/commands/moveToFinished-14.lua +7 -5
- package/dist/esm/commands/moveToWaitingChildren-8.lua +2 -4
- package/dist/esm/interfaces/job-json.d.ts +1 -0
- package/dist/esm/scripts/addDelayedJob-6.js +51 -37
- package/dist/esm/scripts/addDelayedJob-6.js.map +1 -1
- package/dist/esm/scripts/addJobScheduler-11.js +9 -4
- package/dist/esm/scripts/addJobScheduler-11.js.map +1 -1
- package/dist/esm/scripts/addParentJob-4.js +51 -37
- package/dist/esm/scripts/addParentJob-4.js.map +1 -1
- package/dist/esm/scripts/addPrioritizedJob-8.js +51 -37
- package/dist/esm/scripts/addPrioritizedJob-8.js.map +1 -1
- package/dist/esm/scripts/addRepeatableJob-2.js +9 -4
- package/dist/esm/scripts/addRepeatableJob-2.js.map +1 -1
- package/dist/esm/scripts/addStandardJob-8.js +51 -37
- package/dist/esm/scripts/addStandardJob-8.js.map +1 -1
- package/dist/esm/scripts/cleanJobsInSet-3.js +9 -4
- package/dist/esm/scripts/cleanJobsInSet-3.js.map +1 -1
- package/dist/esm/scripts/drain-5.js +9 -4
- package/dist/esm/scripts/drain-5.js.map +1 -1
- package/dist/esm/scripts/moveStalledJobsToWait-9.js +92 -76
- package/dist/esm/scripts/moveStalledJobsToWait-9.js.map +1 -1
- package/dist/esm/scripts/moveToFinished-14.js +97 -78
- package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
- package/dist/esm/scripts/moveToWaitingChildren-8.js +92 -76
- package/dist/esm/scripts/moveToWaitingChildren-8.js.map +1 -1
- package/dist/esm/scripts/obliterate-2.js +9 -4
- package/dist/esm/scripts/obliterate-2.js.map +1 -1
- package/dist/esm/scripts/removeJob-3.js +9 -4
- package/dist/esm/scripts/removeJob-3.js.map +1 -1
- package/dist/esm/scripts/removeUnprocessedChildren-2.js +9 -4
- package/dist/esm/scripts/removeUnprocessedChildren-2.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/utils.d.ts +17 -0
- package/dist/esm/utils.js +10 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/commands/includes/removeDeduplicationKey.lua +0 -11
- package/dist/cjs/commands/includes/removeDeduplicationKeyIfNeeded.lua +0 -14
- package/dist/esm/commands/includes/removeDeduplicationKey.lua +0 -11
- package/dist/esm/commands/includes/removeDeduplicationKeyIfNeeded.lua +0 -14
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"addPrioritizedJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addPrioritizedJob-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"addPrioritizedJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addPrioritizedJob-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Wf,CAAC;AACF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,mBAAmB;IACzB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -29,13 +29,18 @@ local prefixKey = ARGV[5]
|
|
29
29
|
]]
|
30
30
|
-- Includes
|
31
31
|
--[[
|
32
|
-
Function to remove deduplication key
|
32
|
+
Function to remove deduplication key if needed
|
33
|
+
when a job is being removed.
|
33
34
|
]]
|
34
|
-
local function
|
35
|
+
local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
|
36
|
+
jobKey, jobId)
|
35
37
|
local deduplicationId = rcall("HGET", jobKey, "deid")
|
36
38
|
if deduplicationId then
|
37
39
|
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
38
|
-
rcall(
|
40
|
+
local currentJobId = rcall('GET', deduplicationKey)
|
41
|
+
if currentJobId and currentJobId == jobId then
|
42
|
+
return rcall("DEL", deduplicationKey)
|
43
|
+
end
|
39
44
|
end
|
40
45
|
end
|
41
46
|
--[[
|
@@ -173,7 +178,7 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
|
173
178
|
local jobKey = baseKey .. jobId
|
174
179
|
removeParentDependencyKey(jobKey, hard, nil, baseKey)
|
175
180
|
if shouldRemoveDeduplicationKey then
|
176
|
-
|
181
|
+
removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
|
177
182
|
end
|
178
183
|
removeJobKeys(jobKey)
|
179
184
|
end
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"addRepeatableJob-2.js","sourceRoot":"","sources":["../../../src/scripts/addRepeatableJob-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"addRepeatableJob-2.js","sourceRoot":"","sources":["../../../src/scripts/addRepeatableJob-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiOf,CAAC;AACF,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,kBAAkB;IACxB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -136,12 +136,19 @@ end
|
|
136
136
|
Validate and move or add dependencies to parent.
|
137
137
|
]]
|
138
138
|
-- Includes
|
139
|
+
--[[
|
140
|
+
Validate and move parent to a wait status (waiting, delayed or prioritized)
|
141
|
+
if no pending dependencies.
|
142
|
+
]]
|
143
|
+
-- Includes
|
139
144
|
--[[
|
140
145
|
Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
|
141
146
|
]]
|
147
|
+
-- Includes
|
142
148
|
--[[
|
143
|
-
|
149
|
+
Move parent to a wait status (wait, prioritized or delayed)
|
144
150
|
]]
|
151
|
+
-- Includes
|
145
152
|
--[[
|
146
153
|
Add delay marker if needed.
|
147
154
|
]]
|
@@ -200,52 +207,59 @@ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
|
|
200
207
|
return false
|
201
208
|
end
|
202
209
|
local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
203
|
-
local
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
210
|
+
local parentWaitKey = parentQueueKey .. ":wait"
|
211
|
+
local parentPausedKey = parentQueueKey .. ":paused"
|
212
|
+
local parentActiveKey = parentQueueKey .. ":active"
|
213
|
+
local parentMetaKey = parentQueueKey .. ":meta"
|
214
|
+
local parentMarkerKey = parentQueueKey .. ":marker"
|
215
|
+
local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
|
216
|
+
local priority = tonumber(jobAttributes[1]) or 0
|
217
|
+
local delay = tonumber(jobAttributes[2]) or 0
|
218
|
+
-- ignore dependencies if any left
|
219
|
+
rcall("HSET", parentKey, "igdp", 1)
|
220
|
+
if delay > 0 then
|
221
|
+
local delayedTimestamp = tonumber(timestamp) + delay
|
222
|
+
local score = delayedTimestamp * 0x1000
|
223
|
+
local parentDelayedKey = parentQueueKey .. ":delayed"
|
224
|
+
rcall("ZADD", parentDelayedKey, score, parentId)
|
225
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
|
226
|
+
delayedTimestamp)
|
227
|
+
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
228
|
+
else
|
229
|
+
if priority == 0 then
|
230
|
+
local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
|
231
|
+
parentWaitKey, parentPausedKey)
|
232
|
+
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
223
233
|
else
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
228
|
-
else
|
229
|
-
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
230
|
-
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
231
|
-
parentQueueKey .. ":pc", isPausedOrMaxed)
|
232
|
-
end
|
233
|
-
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
234
|
-
"waiting-children")
|
234
|
+
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
235
|
+
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
236
|
+
parentQueueKey .. ":pc", isPausedOrMaxed)
|
235
237
|
end
|
238
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
239
|
+
"waiting-children")
|
236
240
|
end
|
237
241
|
end
|
238
|
-
local function moveParentToWaitIfNeeded(parentQueueKey,
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
+
local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
243
|
+
if rcall("EXISTS", parentKey) == 1 then
|
244
|
+
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
245
|
+
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
246
|
+
rcall("ZREM", parentWaitingChildrenKey, parentId)
|
247
|
+
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
242
248
|
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
|
252
|
+
parentId, timestamp)
|
253
|
+
local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
|
254
|
+
if doNotHavePendingDependencies then
|
255
|
+
moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
256
|
+
end
|
243
257
|
end
|
244
258
|
local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
|
245
259
|
parentId, jobIdKey, returnvalue, timestamp )
|
246
260
|
local processedSet = parentKey .. ":processed"
|
247
261
|
rcall("HSET", processedSet, jobIdKey, returnvalue)
|
248
|
-
|
262
|
+
moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
|
249
263
|
end
|
250
264
|
local function updateExistingJobsParent(parentKey, parent, parentData,
|
251
265
|
parentDependenciesKey, completedKey,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"addStandardJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"addStandardJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgXf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -65,13 +65,18 @@ end
|
|
65
65
|
]]
|
66
66
|
-- Includes
|
67
67
|
--[[
|
68
|
-
Function to remove deduplication key
|
68
|
+
Function to remove deduplication key if needed
|
69
|
+
when a job is being removed.
|
69
70
|
]]
|
70
|
-
local function
|
71
|
+
local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
|
72
|
+
jobKey, jobId)
|
71
73
|
local deduplicationId = rcall("HGET", jobKey, "deid")
|
72
74
|
if deduplicationId then
|
73
75
|
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
74
|
-
rcall(
|
76
|
+
local currentJobId = rcall('GET', deduplicationKey)
|
77
|
+
if currentJobId and currentJobId == jobId then
|
78
|
+
return rcall("DEL", deduplicationKey)
|
79
|
+
end
|
75
80
|
end
|
76
81
|
end
|
77
82
|
--[[
|
@@ -209,7 +214,7 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
|
209
214
|
local jobKey = baseKey .. jobId
|
210
215
|
removeParentDependencyKey(jobKey, hard, nil, baseKey)
|
211
216
|
if shouldRemoveDeduplicationKey then
|
212
|
-
|
217
|
+
removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
|
213
218
|
end
|
214
219
|
removeJobKeys(jobKey)
|
215
220
|
end
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"cleanJobsInSet-3.js","sourceRoot":"","sources":["../../../src/scripts/cleanJobsInSet-3.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"cleanJobsInSet-3.js","sourceRoot":"","sources":["../../../src/scripts/cleanJobsInSet-3.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoWf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -37,13 +37,18 @@ end
|
|
37
37
|
]]
|
38
38
|
-- Includes
|
39
39
|
--[[
|
40
|
-
Function to remove deduplication key
|
40
|
+
Function to remove deduplication key if needed
|
41
|
+
when a job is being removed.
|
41
42
|
]]
|
42
|
-
local function
|
43
|
+
local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
|
44
|
+
jobKey, jobId)
|
43
45
|
local deduplicationId = rcall("HGET", jobKey, "deid")
|
44
46
|
if deduplicationId then
|
45
47
|
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
46
|
-
rcall(
|
48
|
+
local currentJobId = rcall('GET', deduplicationKey)
|
49
|
+
if currentJobId and currentJobId == jobId then
|
50
|
+
return rcall("DEL", deduplicationKey)
|
51
|
+
end
|
47
52
|
end
|
48
53
|
end
|
49
54
|
--[[
|
@@ -181,7 +186,7 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
|
181
186
|
local jobKey = baseKey .. jobId
|
182
187
|
removeParentDependencyKey(jobKey, hard, nil, baseKey)
|
183
188
|
if shouldRemoveDeduplicationKey then
|
184
|
-
|
189
|
+
removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
|
185
190
|
end
|
186
191
|
removeJobKeys(jobKey)
|
187
192
|
end
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"drain-5.js","sourceRoot":"","sources":["../../../src/scripts/drain-5.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"drain-5.js","sourceRoot":"","sources":["../../../src/scripts/drain-5.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsQf,CAAC;AACF,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,OAAO;IACb,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -75,12 +75,19 @@ end
|
|
75
75
|
Function to recursively move from waitingChildren to failed.
|
76
76
|
]]
|
77
77
|
-- Includes
|
78
|
+
--[[
|
79
|
+
Validate and move parent to a wait status (waiting, delayed or prioritized)
|
80
|
+
if no pending dependencies.
|
81
|
+
]]
|
82
|
+
-- Includes
|
78
83
|
--[[
|
79
84
|
Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
|
80
85
|
]]
|
86
|
+
-- Includes
|
81
87
|
--[[
|
82
|
-
|
88
|
+
Move parent to a wait status (wait, prioritized or delayed)
|
83
89
|
]]
|
90
|
+
-- Includes
|
84
91
|
--[[
|
85
92
|
Add delay marker if needed.
|
86
93
|
]]
|
@@ -139,57 +146,52 @@ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
|
|
139
146
|
return false
|
140
147
|
end
|
141
148
|
local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
142
|
-
local
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
149
|
+
local parentWaitKey = parentQueueKey .. ":wait"
|
150
|
+
local parentPausedKey = parentQueueKey .. ":paused"
|
151
|
+
local parentActiveKey = parentQueueKey .. ":active"
|
152
|
+
local parentMetaKey = parentQueueKey .. ":meta"
|
153
|
+
local parentMarkerKey = parentQueueKey .. ":marker"
|
154
|
+
local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
|
155
|
+
local priority = tonumber(jobAttributes[1]) or 0
|
156
|
+
local delay = tonumber(jobAttributes[2]) or 0
|
157
|
+
-- ignore dependencies if any left
|
158
|
+
rcall("HSET", parentKey, "igdp", 1)
|
159
|
+
if delay > 0 then
|
160
|
+
local delayedTimestamp = tonumber(timestamp) + delay
|
161
|
+
local score = delayedTimestamp * 0x1000
|
162
|
+
local parentDelayedKey = parentQueueKey .. ":delayed"
|
163
|
+
rcall("ZADD", parentDelayedKey, score, parentId)
|
164
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
|
165
|
+
delayedTimestamp)
|
166
|
+
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
167
|
+
else
|
168
|
+
if priority == 0 then
|
169
|
+
local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
|
170
|
+
parentWaitKey, parentPausedKey)
|
171
|
+
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
162
172
|
else
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
167
|
-
else
|
168
|
-
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
169
|
-
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
170
|
-
parentQueueKey .. ":pc", isPausedOrMaxed)
|
171
|
-
end
|
172
|
-
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
173
|
-
"waiting-children")
|
173
|
+
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
174
|
+
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
175
|
+
parentQueueKey .. ":pc", isPausedOrMaxed)
|
174
176
|
end
|
177
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
178
|
+
"waiting-children")
|
175
179
|
end
|
176
180
|
end
|
177
|
-
local function moveParentToWaitIfNeeded(parentQueueKey,
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
+
local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
182
|
+
if rcall("EXISTS", parentKey) == 1 then
|
183
|
+
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
184
|
+
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
185
|
+
rcall("ZREM", parentWaitingChildrenKey, parentId)
|
186
|
+
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
181
187
|
end
|
188
|
+
end
|
182
189
|
end
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
189
|
-
local pttl = rcall("PTTL", deduplicationKey)
|
190
|
-
if pttl == 0 or pttl == -1 then
|
191
|
-
rcall("DEL", deduplicationKey)
|
192
|
-
end
|
190
|
+
local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
|
191
|
+
parentId, timestamp)
|
192
|
+
local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
|
193
|
+
if doNotHavePendingDependencies then
|
194
|
+
moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
193
195
|
end
|
194
196
|
end
|
195
197
|
--[[
|
@@ -201,13 +203,18 @@ end
|
|
201
203
|
]]
|
202
204
|
-- Includes
|
203
205
|
--[[
|
204
|
-
Function to remove deduplication key
|
206
|
+
Function to remove deduplication key if needed
|
207
|
+
when a job is being removed.
|
205
208
|
]]
|
206
|
-
local function
|
209
|
+
local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
|
210
|
+
jobKey, jobId)
|
207
211
|
local deduplicationId = rcall("HGET", jobKey, "deid")
|
208
212
|
if deduplicationId then
|
209
213
|
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
210
|
-
rcall(
|
214
|
+
local currentJobId = rcall('GET', deduplicationKey)
|
215
|
+
if currentJobId and currentJobId == jobId then
|
216
|
+
return rcall("DEL", deduplicationKey)
|
217
|
+
end
|
211
218
|
end
|
212
219
|
end
|
213
220
|
--[[
|
@@ -309,7 +316,7 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
|
309
316
|
local jobKey = baseKey .. jobId
|
310
317
|
removeParentDependencyKey(jobKey, hard, nil, baseKey)
|
311
318
|
if shouldRemoveDeduplicationKey then
|
312
|
-
|
319
|
+
removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
|
313
320
|
end
|
314
321
|
removeJobKeys(jobKey)
|
315
322
|
end
|
@@ -369,38 +376,27 @@ moveParentToFailedIfNeeded = function (parentQueueKey, parentKey, parentId, jobI
|
|
369
376
|
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
370
377
|
local parentDelayedKey = parentQueueKey .. ":delayed"
|
371
378
|
local parentPrioritizedKey = parentQueueKey .. ":prioritized"
|
372
|
-
local
|
379
|
+
local parentWaitingChildrenOrDelayedKey
|
373
380
|
local prevState
|
374
381
|
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
375
|
-
|
382
|
+
parentWaitingChildrenOrDelayedKey = parentWaitingChildrenKey
|
376
383
|
prevState = "waiting-children"
|
377
384
|
elseif rcall("ZSCORE", parentDelayedKey, parentId) then
|
378
|
-
|
385
|
+
parentWaitingChildrenOrDelayedKey = parentDelayedKey
|
379
386
|
prevState = "delayed"
|
380
|
-
|
381
|
-
parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
|
382
|
-
prevState = "prioritized"
|
387
|
+
rcall("HSET", parentKey, "delay", 0)
|
383
388
|
end
|
384
|
-
if
|
385
|
-
rcall("ZREM",
|
389
|
+
if parentWaitingChildrenOrDelayedKey then
|
390
|
+
rcall("ZREM", parentWaitingChildrenOrDelayedKey, parentId)
|
386
391
|
local parentQueuePrefix = parentQueueKey .. ":"
|
387
392
|
local parentFailedKey = parentQueueKey .. ":failed"
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
|
392
|
-
failedReason, "prev", prevState)
|
393
|
-
local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
|
394
|
-
removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
|
395
|
-
moveChildFromDependenciesIfNeeded(jobAttributes[1], parentKey, failedReason, timestamp)
|
396
|
-
local parentRawOpts = jobAttributes[3]
|
397
|
-
local parentOpts = cjson.decode(parentRawOpts)
|
398
|
-
removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
|
393
|
+
local deferredFailure = "child " .. jobIdKey .. " failed"
|
394
|
+
rcall("HSET", parentKey, "defa", deferredFailure)
|
395
|
+
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
399
396
|
else
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
|
397
|
+
if not rcall("ZSCORE", parentQueueKey .. ":failed", parentId) then
|
398
|
+
local deferredFailure = "child " .. jobIdKey .. " failed"
|
399
|
+
rcall("HSET", parentKey, "defa", deferredFailure)
|
404
400
|
end
|
405
401
|
end
|
406
402
|
end
|
@@ -426,11 +422,11 @@ moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, failedRea
|
|
426
422
|
if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
|
427
423
|
local parentFailedChildrenKey = parentKey .. ":failed"
|
428
424
|
rcall("HSET", parentFailedChildrenKey, childKey, failedReason)
|
429
|
-
|
425
|
+
moveParentToWaitIfNeeded(parentData['queueKey'], parentKey, parentData['id'], timestamp)
|
430
426
|
end
|
431
427
|
elseif parentData['idof'] or parentData['rdof'] then
|
432
428
|
if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
|
433
|
-
|
429
|
+
moveParentToWaitIfNoPendingDependencies(parentData['queueKey'], parentDependenciesChildrenKey,
|
434
430
|
parentKey, parentData['id'], timestamp)
|
435
431
|
if parentData['idof'] then
|
436
432
|
local parentFailedChildrenKey = parentKey .. ":failed"
|
@@ -440,6 +436,26 @@ moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, failedRea
|
|
440
436
|
end
|
441
437
|
end
|
442
438
|
end
|
439
|
+
--[[
|
440
|
+
Function to remove deduplication key if needed
|
441
|
+
when a job is moved to completed or failed states.
|
442
|
+
]]
|
443
|
+
local function removeDeduplicationKeyIfNeededOnFinalization(prefixKey,
|
444
|
+
deduplicationId, jobId)
|
445
|
+
if deduplicationId then
|
446
|
+
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
447
|
+
local pttl = rcall("PTTL", deduplicationKey)
|
448
|
+
if pttl == 0 then
|
449
|
+
return rcall("DEL", deduplicationKey)
|
450
|
+
end
|
451
|
+
if pttl == -1 then
|
452
|
+
local currentJobId = rcall('GET', deduplicationKey)
|
453
|
+
if currentJobId and currentJobId == jobId then
|
454
|
+
return rcall("DEL", deduplicationKey)
|
455
|
+
end
|
456
|
+
end
|
457
|
+
end
|
458
|
+
end
|
443
459
|
--[[
|
444
460
|
Function to trim events, default 10000.
|
445
461
|
]]
|
@@ -509,7 +525,7 @@ if (#stalling > 0) then
|
|
509
525
|
local rawParentData = jobAttributes[2]
|
510
526
|
local opts = cjson.decode(rawOpts)
|
511
527
|
rcall("ZADD", failedKey, timestamp, jobId)
|
512
|
-
|
528
|
+
removeDeduplicationKeyIfNeededOnFinalization(queueKeyPrefix, jobAttributes[3], jobId)
|
513
529
|
local failedReason = "job stalled more than allowable limit"
|
514
530
|
rcall("HMSET", jobKey, "failedReason", failedReason, "finishedOn", timestamp)
|
515
531
|
rcall("XADD", eventStreamKey, "*", "event", "failed", "jobId", jobId, 'prev', 'active',
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"moveStalledJobsToWait-9.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"moveStalledJobsToWait-9.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6iBf,CAAC;AACF,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|