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
@@ -32,13 +32,18 @@ local prefixKey = ARGV[5]
|
|
32
32
|
]]
|
33
33
|
-- Includes
|
34
34
|
--[[
|
35
|
-
Function to remove deduplication key
|
35
|
+
Function to remove deduplication key if needed
|
36
|
+
when a job is being removed.
|
36
37
|
]]
|
37
|
-
local function
|
38
|
+
local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
|
39
|
+
jobKey, jobId)
|
38
40
|
local deduplicationId = rcall("HGET", jobKey, "deid")
|
39
41
|
if deduplicationId then
|
40
42
|
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
41
|
-
rcall(
|
43
|
+
local currentJobId = rcall('GET', deduplicationKey)
|
44
|
+
if currentJobId and currentJobId == jobId then
|
45
|
+
return rcall("DEL", deduplicationKey)
|
46
|
+
end
|
42
47
|
end
|
43
48
|
end
|
44
49
|
--[[
|
@@ -176,7 +181,7 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
|
176
181
|
local jobKey = baseKey .. jobId
|
177
182
|
removeParentDependencyKey(jobKey, hard, nil, baseKey)
|
178
183
|
if shouldRemoveDeduplicationKey then
|
179
|
-
|
184
|
+
removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
|
180
185
|
end
|
181
186
|
removeJobKeys(jobKey)
|
182
187
|
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;AACW,QAAA,gBAAgB,GAAG;IAC9B,IAAI,EAAE,kBAAkB;IACxB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -139,12 +139,19 @@ end
|
|
139
139
|
Validate and move or add dependencies to parent.
|
140
140
|
]]
|
141
141
|
-- Includes
|
142
|
+
--[[
|
143
|
+
Validate and move parent to a wait status (waiting, delayed or prioritized)
|
144
|
+
if no pending dependencies.
|
145
|
+
]]
|
146
|
+
-- Includes
|
142
147
|
--[[
|
143
148
|
Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
|
144
149
|
]]
|
150
|
+
-- Includes
|
145
151
|
--[[
|
146
|
-
|
152
|
+
Move parent to a wait status (wait, prioritized or delayed)
|
147
153
|
]]
|
154
|
+
-- Includes
|
148
155
|
--[[
|
149
156
|
Add delay marker if needed.
|
150
157
|
]]
|
@@ -203,52 +210,59 @@ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
|
|
203
210
|
return false
|
204
211
|
end
|
205
212
|
local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
206
|
-
local
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
213
|
+
local parentWaitKey = parentQueueKey .. ":wait"
|
214
|
+
local parentPausedKey = parentQueueKey .. ":paused"
|
215
|
+
local parentActiveKey = parentQueueKey .. ":active"
|
216
|
+
local parentMetaKey = parentQueueKey .. ":meta"
|
217
|
+
local parentMarkerKey = parentQueueKey .. ":marker"
|
218
|
+
local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
|
219
|
+
local priority = tonumber(jobAttributes[1]) or 0
|
220
|
+
local delay = tonumber(jobAttributes[2]) or 0
|
221
|
+
-- ignore dependencies if any left
|
222
|
+
rcall("HSET", parentKey, "igdp", 1)
|
223
|
+
if delay > 0 then
|
224
|
+
local delayedTimestamp = tonumber(timestamp) + delay
|
225
|
+
local score = delayedTimestamp * 0x1000
|
226
|
+
local parentDelayedKey = parentQueueKey .. ":delayed"
|
227
|
+
rcall("ZADD", parentDelayedKey, score, parentId)
|
228
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
|
229
|
+
delayedTimestamp)
|
230
|
+
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
231
|
+
else
|
232
|
+
if priority == 0 then
|
233
|
+
local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
|
234
|
+
parentWaitKey, parentPausedKey)
|
235
|
+
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
226
236
|
else
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
231
|
-
else
|
232
|
-
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
233
|
-
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
234
|
-
parentQueueKey .. ":pc", isPausedOrMaxed)
|
235
|
-
end
|
236
|
-
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
237
|
-
"waiting-children")
|
237
|
+
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
238
|
+
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
239
|
+
parentQueueKey .. ":pc", isPausedOrMaxed)
|
238
240
|
end
|
241
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
242
|
+
"waiting-children")
|
239
243
|
end
|
240
244
|
end
|
241
|
-
local function moveParentToWaitIfNeeded(parentQueueKey,
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
+
local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
246
|
+
if rcall("EXISTS", parentKey) == 1 then
|
247
|
+
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
248
|
+
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
249
|
+
rcall("ZREM", parentWaitingChildrenKey, parentId)
|
250
|
+
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
245
251
|
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
|
255
|
+
parentId, timestamp)
|
256
|
+
local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
|
257
|
+
if doNotHavePendingDependencies then
|
258
|
+
moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
259
|
+
end
|
246
260
|
end
|
247
261
|
local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
|
248
262
|
parentId, jobIdKey, returnvalue, timestamp )
|
249
263
|
local processedSet = parentKey .. ":processed"
|
250
264
|
rcall("HSET", processedSet, jobIdKey, returnvalue)
|
251
|
-
|
265
|
+
moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
|
252
266
|
end
|
253
267
|
local function updateExistingJobsParent(parentKey, parent, parentData,
|
254
268
|
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;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -68,13 +68,18 @@ end
|
|
68
68
|
]]
|
69
69
|
-- Includes
|
70
70
|
--[[
|
71
|
-
Function to remove deduplication key
|
71
|
+
Function to remove deduplication key if needed
|
72
|
+
when a job is being removed.
|
72
73
|
]]
|
73
|
-
local function
|
74
|
+
local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
|
75
|
+
jobKey, jobId)
|
74
76
|
local deduplicationId = rcall("HGET", jobKey, "deid")
|
75
77
|
if deduplicationId then
|
76
78
|
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
77
|
-
rcall(
|
79
|
+
local currentJobId = rcall('GET', deduplicationKey)
|
80
|
+
if currentJobId and currentJobId == jobId then
|
81
|
+
return rcall("DEL", deduplicationKey)
|
82
|
+
end
|
78
83
|
end
|
79
84
|
end
|
80
85
|
--[[
|
@@ -212,7 +217,7 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
|
212
217
|
local jobKey = baseKey .. jobId
|
213
218
|
removeParentDependencyKey(jobKey, hard, nil, baseKey)
|
214
219
|
if shouldRemoveDeduplicationKey then
|
215
|
-
|
220
|
+
removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
|
216
221
|
end
|
217
222
|
removeJobKeys(jobKey)
|
218
223
|
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;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -40,13 +40,18 @@ end
|
|
40
40
|
]]
|
41
41
|
-- Includes
|
42
42
|
--[[
|
43
|
-
Function to remove deduplication key
|
43
|
+
Function to remove deduplication key if needed
|
44
|
+
when a job is being removed.
|
44
45
|
]]
|
45
|
-
local function
|
46
|
+
local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
|
47
|
+
jobKey, jobId)
|
46
48
|
local deduplicationId = rcall("HGET", jobKey, "deid")
|
47
49
|
if deduplicationId then
|
48
50
|
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
49
|
-
rcall(
|
51
|
+
local currentJobId = rcall('GET', deduplicationKey)
|
52
|
+
if currentJobId and currentJobId == jobId then
|
53
|
+
return rcall("DEL", deduplicationKey)
|
54
|
+
end
|
50
55
|
end
|
51
56
|
end
|
52
57
|
--[[
|
@@ -184,7 +189,7 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
|
184
189
|
local jobKey = baseKey .. jobId
|
185
190
|
removeParentDependencyKey(jobKey, hard, nil, baseKey)
|
186
191
|
if shouldRemoveDeduplicationKey then
|
187
|
-
|
192
|
+
removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
|
188
193
|
end
|
189
194
|
removeJobKeys(jobKey)
|
190
195
|
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;AACW,QAAA,KAAK,GAAG;IACnB,IAAI,EAAE,OAAO;IACb,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -78,12 +78,19 @@ end
|
|
78
78
|
Function to recursively move from waitingChildren to failed.
|
79
79
|
]]
|
80
80
|
-- Includes
|
81
|
+
--[[
|
82
|
+
Validate and move parent to a wait status (waiting, delayed or prioritized)
|
83
|
+
if no pending dependencies.
|
84
|
+
]]
|
85
|
+
-- Includes
|
81
86
|
--[[
|
82
87
|
Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
|
83
88
|
]]
|
89
|
+
-- Includes
|
84
90
|
--[[
|
85
|
-
|
91
|
+
Move parent to a wait status (wait, prioritized or delayed)
|
86
92
|
]]
|
93
|
+
-- Includes
|
87
94
|
--[[
|
88
95
|
Add delay marker if needed.
|
89
96
|
]]
|
@@ -142,57 +149,52 @@ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
|
|
142
149
|
return false
|
143
150
|
end
|
144
151
|
local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
145
|
-
local
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
152
|
+
local parentWaitKey = parentQueueKey .. ":wait"
|
153
|
+
local parentPausedKey = parentQueueKey .. ":paused"
|
154
|
+
local parentActiveKey = parentQueueKey .. ":active"
|
155
|
+
local parentMetaKey = parentQueueKey .. ":meta"
|
156
|
+
local parentMarkerKey = parentQueueKey .. ":marker"
|
157
|
+
local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
|
158
|
+
local priority = tonumber(jobAttributes[1]) or 0
|
159
|
+
local delay = tonumber(jobAttributes[2]) or 0
|
160
|
+
-- ignore dependencies if any left
|
161
|
+
rcall("HSET", parentKey, "igdp", 1)
|
162
|
+
if delay > 0 then
|
163
|
+
local delayedTimestamp = tonumber(timestamp) + delay
|
164
|
+
local score = delayedTimestamp * 0x1000
|
165
|
+
local parentDelayedKey = parentQueueKey .. ":delayed"
|
166
|
+
rcall("ZADD", parentDelayedKey, score, parentId)
|
167
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
|
168
|
+
delayedTimestamp)
|
169
|
+
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
170
|
+
else
|
171
|
+
if priority == 0 then
|
172
|
+
local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
|
173
|
+
parentWaitKey, parentPausedKey)
|
174
|
+
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
165
175
|
else
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
170
|
-
else
|
171
|
-
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
172
|
-
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
173
|
-
parentQueueKey .. ":pc", isPausedOrMaxed)
|
174
|
-
end
|
175
|
-
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
176
|
-
"waiting-children")
|
176
|
+
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
177
|
+
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
178
|
+
parentQueueKey .. ":pc", isPausedOrMaxed)
|
177
179
|
end
|
180
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
181
|
+
"waiting-children")
|
178
182
|
end
|
179
183
|
end
|
180
|
-
local function moveParentToWaitIfNeeded(parentQueueKey,
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
+
local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
185
|
+
if rcall("EXISTS", parentKey) == 1 then
|
186
|
+
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
187
|
+
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
188
|
+
rcall("ZREM", parentWaitingChildrenKey, parentId)
|
189
|
+
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
184
190
|
end
|
191
|
+
end
|
185
192
|
end
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
192
|
-
local pttl = rcall("PTTL", deduplicationKey)
|
193
|
-
if pttl == 0 or pttl == -1 then
|
194
|
-
rcall("DEL", deduplicationKey)
|
195
|
-
end
|
193
|
+
local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
|
194
|
+
parentId, timestamp)
|
195
|
+
local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
|
196
|
+
if doNotHavePendingDependencies then
|
197
|
+
moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
196
198
|
end
|
197
199
|
end
|
198
200
|
--[[
|
@@ -204,13 +206,18 @@ end
|
|
204
206
|
]]
|
205
207
|
-- Includes
|
206
208
|
--[[
|
207
|
-
Function to remove deduplication key
|
209
|
+
Function to remove deduplication key if needed
|
210
|
+
when a job is being removed.
|
208
211
|
]]
|
209
|
-
local function
|
212
|
+
local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
|
213
|
+
jobKey, jobId)
|
210
214
|
local deduplicationId = rcall("HGET", jobKey, "deid")
|
211
215
|
if deduplicationId then
|
212
216
|
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
213
|
-
rcall(
|
217
|
+
local currentJobId = rcall('GET', deduplicationKey)
|
218
|
+
if currentJobId and currentJobId == jobId then
|
219
|
+
return rcall("DEL", deduplicationKey)
|
220
|
+
end
|
214
221
|
end
|
215
222
|
end
|
216
223
|
--[[
|
@@ -312,7 +319,7 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
|
312
319
|
local jobKey = baseKey .. jobId
|
313
320
|
removeParentDependencyKey(jobKey, hard, nil, baseKey)
|
314
321
|
if shouldRemoveDeduplicationKey then
|
315
|
-
|
322
|
+
removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
|
316
323
|
end
|
317
324
|
removeJobKeys(jobKey)
|
318
325
|
end
|
@@ -372,38 +379,27 @@ moveParentToFailedIfNeeded = function (parentQueueKey, parentKey, parentId, jobI
|
|
372
379
|
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
373
380
|
local parentDelayedKey = parentQueueKey .. ":delayed"
|
374
381
|
local parentPrioritizedKey = parentQueueKey .. ":prioritized"
|
375
|
-
local
|
382
|
+
local parentWaitingChildrenOrDelayedKey
|
376
383
|
local prevState
|
377
384
|
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
378
|
-
|
385
|
+
parentWaitingChildrenOrDelayedKey = parentWaitingChildrenKey
|
379
386
|
prevState = "waiting-children"
|
380
387
|
elseif rcall("ZSCORE", parentDelayedKey, parentId) then
|
381
|
-
|
388
|
+
parentWaitingChildrenOrDelayedKey = parentDelayedKey
|
382
389
|
prevState = "delayed"
|
383
|
-
|
384
|
-
parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
|
385
|
-
prevState = "prioritized"
|
390
|
+
rcall("HSET", parentKey, "delay", 0)
|
386
391
|
end
|
387
|
-
if
|
388
|
-
rcall("ZREM",
|
392
|
+
if parentWaitingChildrenOrDelayedKey then
|
393
|
+
rcall("ZREM", parentWaitingChildrenOrDelayedKey, parentId)
|
389
394
|
local parentQueuePrefix = parentQueueKey .. ":"
|
390
395
|
local parentFailedKey = parentQueueKey .. ":failed"
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
|
395
|
-
failedReason, "prev", prevState)
|
396
|
-
local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
|
397
|
-
removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
|
398
|
-
moveChildFromDependenciesIfNeeded(jobAttributes[1], parentKey, failedReason, timestamp)
|
399
|
-
local parentRawOpts = jobAttributes[3]
|
400
|
-
local parentOpts = cjson.decode(parentRawOpts)
|
401
|
-
removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
|
396
|
+
local deferredFailure = "child " .. jobIdKey .. " failed"
|
397
|
+
rcall("HSET", parentKey, "defa", deferredFailure)
|
398
|
+
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
402
399
|
else
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
|
400
|
+
if not rcall("ZSCORE", parentQueueKey .. ":failed", parentId) then
|
401
|
+
local deferredFailure = "child " .. jobIdKey .. " failed"
|
402
|
+
rcall("HSET", parentKey, "defa", deferredFailure)
|
407
403
|
end
|
408
404
|
end
|
409
405
|
end
|
@@ -429,11 +425,11 @@ moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, failedRea
|
|
429
425
|
if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
|
430
426
|
local parentFailedChildrenKey = parentKey .. ":failed"
|
431
427
|
rcall("HSET", parentFailedChildrenKey, childKey, failedReason)
|
432
|
-
|
428
|
+
moveParentToWaitIfNeeded(parentData['queueKey'], parentKey, parentData['id'], timestamp)
|
433
429
|
end
|
434
430
|
elseif parentData['idof'] or parentData['rdof'] then
|
435
431
|
if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
|
436
|
-
|
432
|
+
moveParentToWaitIfNoPendingDependencies(parentData['queueKey'], parentDependenciesChildrenKey,
|
437
433
|
parentKey, parentData['id'], timestamp)
|
438
434
|
if parentData['idof'] then
|
439
435
|
local parentFailedChildrenKey = parentKey .. ":failed"
|
@@ -443,6 +439,26 @@ moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, failedRea
|
|
443
439
|
end
|
444
440
|
end
|
445
441
|
end
|
442
|
+
--[[
|
443
|
+
Function to remove deduplication key if needed
|
444
|
+
when a job is moved to completed or failed states.
|
445
|
+
]]
|
446
|
+
local function removeDeduplicationKeyIfNeededOnFinalization(prefixKey,
|
447
|
+
deduplicationId, jobId)
|
448
|
+
if deduplicationId then
|
449
|
+
local deduplicationKey = prefixKey .. "de:" .. deduplicationId
|
450
|
+
local pttl = rcall("PTTL", deduplicationKey)
|
451
|
+
if pttl == 0 then
|
452
|
+
return rcall("DEL", deduplicationKey)
|
453
|
+
end
|
454
|
+
if pttl == -1 then
|
455
|
+
local currentJobId = rcall('GET', deduplicationKey)
|
456
|
+
if currentJobId and currentJobId == jobId then
|
457
|
+
return rcall("DEL", deduplicationKey)
|
458
|
+
end
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
446
462
|
--[[
|
447
463
|
Function to trim events, default 10000.
|
448
464
|
]]
|
@@ -512,7 +528,7 @@ if (#stalling > 0) then
|
|
512
528
|
local rawParentData = jobAttributes[2]
|
513
529
|
local opts = cjson.decode(rawOpts)
|
514
530
|
rcall("ZADD", failedKey, timestamp, jobId)
|
515
|
-
|
531
|
+
removeDeduplicationKeyIfNeededOnFinalization(queueKeyPrefix, jobAttributes[3], jobId)
|
516
532
|
local failedReason = "job stalled more than allowable limit"
|
517
533
|
rcall("HMSET", jobKey, "failedReason", failedReason, "finishedOn", timestamp)
|
518
534
|
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;AACW,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|