bullmq 5.49.0 → 5.49.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/classes/flow-producer.js +1 -0
- package/dist/cjs/classes/flow-producer.js.map +1 -1
- package/dist/cjs/classes/job.js +3 -0
- package/dist/cjs/classes/job.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 -31
- 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/updateParentDepsIfNeeded.lua +2 -2
- package/dist/cjs/commands/moveStalledJobsToWait-9.lua +0 -2
- package/dist/cjs/commands/moveToFinished-14.lua +5 -3
- package/dist/cjs/commands/moveToWaitingChildren-8.lua +0 -2
- package/dist/cjs/scripts/addDelayedJob-6.js +51 -37
- package/dist/cjs/scripts/addDelayedJob-6.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/addStandardJob-8.js +51 -37
- package/dist/cjs/scripts/addStandardJob-8.js.map +1 -1
- package/dist/cjs/scripts/moveStalledJobsToWait-9.js +64 -61
- package/dist/cjs/scripts/moveStalledJobsToWait-9.js.map +1 -1
- package/dist/cjs/scripts/moveToFinished-14.js +69 -63
- package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
- package/dist/cjs/scripts/moveToWaitingChildren-8.js +64 -61
- package/dist/cjs/scripts/moveToWaitingChildren-8.js.map +1 -1
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/classes/flow-producer.js +1 -0
- package/dist/esm/classes/flow-producer.js.map +1 -1
- package/dist/esm/classes/job.d.ts +5 -0
- package/dist/esm/classes/job.js +3 -0
- package/dist/esm/classes/job.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 -31
- 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/updateParentDepsIfNeeded.lua +2 -2
- package/dist/esm/commands/moveStalledJobsToWait-9.lua +0 -2
- package/dist/esm/commands/moveToFinished-14.lua +5 -3
- package/dist/esm/commands/moveToWaitingChildren-8.lua +0 -2
- 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/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/addStandardJob-8.js +51 -37
- package/dist/esm/scripts/addStandardJob-8.js.map +1 -1
- package/dist/esm/scripts/moveStalledJobsToWait-9.js +64 -61
- package/dist/esm/scripts/moveStalledJobsToWait-9.js.map +1 -1
- package/dist/esm/scripts/moveToFinished-14.js +69 -63
- package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
- package/dist/esm/scripts/moveToWaitingChildren-8.js +64 -61
- package/dist/esm/scripts/moveToWaitingChildren-8.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
@@ -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,46 +149,53 @@ 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
|
192
|
+
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)
|
198
|
+
end
|
185
199
|
end
|
186
200
|
--[[
|
187
201
|
Function to remove deduplication key if needed.
|
@@ -372,38 +386,27 @@ moveParentToFailedIfNeeded = function (parentQueueKey, parentKey, parentId, jobI
|
|
372
386
|
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
373
387
|
local parentDelayedKey = parentQueueKey .. ":delayed"
|
374
388
|
local parentPrioritizedKey = parentQueueKey .. ":prioritized"
|
375
|
-
local
|
389
|
+
local parentWaitingChildrenOrDelayedKey
|
376
390
|
local prevState
|
377
391
|
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
378
|
-
|
392
|
+
parentWaitingChildrenOrDelayedKey = parentWaitingChildrenKey
|
379
393
|
prevState = "waiting-children"
|
380
394
|
elseif rcall("ZSCORE", parentDelayedKey, parentId) then
|
381
|
-
|
395
|
+
parentWaitingChildrenOrDelayedKey = parentDelayedKey
|
382
396
|
prevState = "delayed"
|
383
|
-
|
384
|
-
parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
|
385
|
-
prevState = "prioritized"
|
397
|
+
rcall("HSET", parentKey, "delay", 0)
|
386
398
|
end
|
387
|
-
if
|
388
|
-
rcall("ZREM",
|
399
|
+
if parentWaitingChildrenOrDelayedKey then
|
400
|
+
rcall("ZREM", parentWaitingChildrenOrDelayedKey, parentId)
|
389
401
|
local parentQueuePrefix = parentQueueKey .. ":"
|
390
402
|
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)
|
403
|
+
local deferredFailure = "child " .. jobIdKey .. " failed"
|
404
|
+
rcall("HSET", parentKey, "defa", deferredFailure)
|
405
|
+
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
402
406
|
else
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
|
407
|
+
if not rcall("ZSCORE", parentQueueKey .. ":failed", parentId) then
|
408
|
+
local deferredFailure = "child " .. jobIdKey .. " failed"
|
409
|
+
rcall("HSET", parentKey, "defa", deferredFailure)
|
407
410
|
end
|
408
411
|
end
|
409
412
|
end
|
@@ -429,11 +432,11 @@ moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, failedRea
|
|
429
432
|
if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
|
430
433
|
local parentFailedChildrenKey = parentKey .. ":failed"
|
431
434
|
rcall("HSET", parentFailedChildrenKey, childKey, failedReason)
|
432
|
-
|
435
|
+
moveParentToWaitIfNeeded(parentData['queueKey'], parentKey, parentData['id'], timestamp)
|
433
436
|
end
|
434
437
|
elseif parentData['idof'] or parentData['rdof'] then
|
435
438
|
if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
|
436
|
-
|
439
|
+
moveParentToWaitIfNoPendingDependencies(parentData['queueKey'], parentDependenciesChildrenKey,
|
437
440
|
parentKey, parentData['id'], timestamp)
|
438
441
|
if parentData['idof'] then
|
439
442
|
local parentFailedChildrenKey = parentKey .. ":failed"
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgiBf,CAAC;AACW,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -170,12 +170,19 @@ end
|
|
170
170
|
Function to recursively move from waitingChildren to failed.
|
171
171
|
]]
|
172
172
|
-- Includes
|
173
|
+
--[[
|
174
|
+
Validate and move parent to a wait status (waiting, delayed or prioritized)
|
175
|
+
if no pending dependencies.
|
176
|
+
]]
|
177
|
+
-- Includes
|
173
178
|
--[[
|
174
179
|
Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
|
175
180
|
]]
|
181
|
+
-- Includes
|
176
182
|
--[[
|
177
|
-
|
183
|
+
Move parent to a wait status (wait, prioritized or delayed)
|
178
184
|
]]
|
185
|
+
-- Includes
|
179
186
|
--[[
|
180
187
|
Add delay marker if needed.
|
181
188
|
]]
|
@@ -238,46 +245,53 @@ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
|
|
238
245
|
return false
|
239
246
|
end
|
240
247
|
local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
241
|
-
local
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
248
|
+
local parentWaitKey = parentQueueKey .. ":wait"
|
249
|
+
local parentPausedKey = parentQueueKey .. ":paused"
|
250
|
+
local parentActiveKey = parentQueueKey .. ":active"
|
251
|
+
local parentMetaKey = parentQueueKey .. ":meta"
|
252
|
+
local parentMarkerKey = parentQueueKey .. ":marker"
|
253
|
+
local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
|
254
|
+
local priority = tonumber(jobAttributes[1]) or 0
|
255
|
+
local delay = tonumber(jobAttributes[2]) or 0
|
256
|
+
-- ignore dependencies if any left
|
257
|
+
rcall("HSET", parentKey, "igdp", 1)
|
258
|
+
if delay > 0 then
|
259
|
+
local delayedTimestamp = tonumber(timestamp) + delay
|
260
|
+
local score = delayedTimestamp * 0x1000
|
261
|
+
local parentDelayedKey = parentQueueKey .. ":delayed"
|
262
|
+
rcall("ZADD", parentDelayedKey, score, parentId)
|
263
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
|
264
|
+
delayedTimestamp)
|
265
|
+
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
266
|
+
else
|
267
|
+
if priority == 0 then
|
268
|
+
local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
|
269
|
+
parentWaitKey, parentPausedKey)
|
270
|
+
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
261
271
|
else
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
|
266
|
-
else
|
267
|
-
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
268
|
-
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
269
|
-
parentQueueKey .. ":pc", isPausedOrMaxed)
|
270
|
-
end
|
271
|
-
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
272
|
-
"waiting-children")
|
272
|
+
local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
|
273
|
+
addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
|
274
|
+
parentQueueKey .. ":pc", isPausedOrMaxed)
|
273
275
|
end
|
276
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
|
277
|
+
"waiting-children")
|
274
278
|
end
|
275
279
|
end
|
276
|
-
local function moveParentToWaitIfNeeded(parentQueueKey,
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
+
local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
281
|
+
if rcall("EXISTS", parentKey) == 1 then
|
282
|
+
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
283
|
+
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
284
|
+
rcall("ZREM", parentWaitingChildrenKey, parentId)
|
285
|
+
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
280
286
|
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
|
290
|
+
parentId, timestamp)
|
291
|
+
local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
|
292
|
+
if doNotHavePendingDependencies then
|
293
|
+
moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
|
294
|
+
end
|
281
295
|
end
|
282
296
|
--[[
|
283
297
|
Function to remove deduplication key if needed.
|
@@ -468,38 +482,27 @@ moveParentToFailedIfNeeded = function (parentQueueKey, parentKey, parentId, jobI
|
|
468
482
|
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
469
483
|
local parentDelayedKey = parentQueueKey .. ":delayed"
|
470
484
|
local parentPrioritizedKey = parentQueueKey .. ":prioritized"
|
471
|
-
local
|
485
|
+
local parentWaitingChildrenOrDelayedKey
|
472
486
|
local prevState
|
473
487
|
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
474
|
-
|
488
|
+
parentWaitingChildrenOrDelayedKey = parentWaitingChildrenKey
|
475
489
|
prevState = "waiting-children"
|
476
490
|
elseif rcall("ZSCORE", parentDelayedKey, parentId) then
|
477
|
-
|
491
|
+
parentWaitingChildrenOrDelayedKey = parentDelayedKey
|
478
492
|
prevState = "delayed"
|
479
|
-
|
480
|
-
parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
|
481
|
-
prevState = "prioritized"
|
493
|
+
rcall("HSET", parentKey, "delay", 0)
|
482
494
|
end
|
483
|
-
if
|
484
|
-
rcall("ZREM",
|
495
|
+
if parentWaitingChildrenOrDelayedKey then
|
496
|
+
rcall("ZREM", parentWaitingChildrenOrDelayedKey, parentId)
|
485
497
|
local parentQueuePrefix = parentQueueKey .. ":"
|
486
498
|
local parentFailedKey = parentQueueKey .. ":failed"
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
|
491
|
-
failedReason, "prev", prevState)
|
492
|
-
local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
|
493
|
-
removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
|
494
|
-
moveChildFromDependenciesIfNeeded(jobAttributes[1], parentKey, failedReason, timestamp)
|
495
|
-
local parentRawOpts = jobAttributes[3]
|
496
|
-
local parentOpts = cjson.decode(parentRawOpts)
|
497
|
-
removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
|
499
|
+
local deferredFailure = "child " .. jobIdKey .. " failed"
|
500
|
+
rcall("HSET", parentKey, "defa", deferredFailure)
|
501
|
+
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
498
502
|
else
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
|
503
|
+
if not rcall("ZSCORE", parentQueueKey .. ":failed", parentId) then
|
504
|
+
local deferredFailure = "child " .. jobIdKey .. " failed"
|
505
|
+
rcall("HSET", parentKey, "defa", deferredFailure)
|
503
506
|
end
|
504
507
|
end
|
505
508
|
end
|
@@ -525,11 +528,11 @@ moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, failedRea
|
|
525
528
|
if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
|
526
529
|
local parentFailedChildrenKey = parentKey .. ":failed"
|
527
530
|
rcall("HSET", parentFailedChildrenKey, childKey, failedReason)
|
528
|
-
|
531
|
+
moveParentToWaitIfNeeded(parentData['queueKey'], parentKey, parentData['id'], timestamp)
|
529
532
|
end
|
530
533
|
elseif parentData['idof'] or parentData['rdof'] then
|
531
534
|
if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
|
532
|
-
|
535
|
+
moveParentToWaitIfNoPendingDependencies(parentData['queueKey'], parentDependenciesChildrenKey,
|
533
536
|
parentKey, parentData['id'], timestamp)
|
534
537
|
if parentData['idof'] then
|
535
538
|
local parentFailedChildrenKey = parentKey .. ":failed"
|
@@ -658,7 +661,7 @@ local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDepende
|
|
658
661
|
parentId, jobIdKey, returnvalue, timestamp )
|
659
662
|
local processedSet = parentKey .. ":processed"
|
660
663
|
rcall("HSET", processedSet, jobIdKey, returnvalue)
|
661
|
-
|
664
|
+
moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
|
662
665
|
end
|
663
666
|
--[[
|
664
667
|
Function to update a bunch of fields in a job.
|
@@ -739,8 +742,11 @@ if rcall("EXISTS", jobIdKey) == 1 then -- Make sure job exists
|
|
739
742
|
local targetSet = KEYS[11]
|
740
743
|
-- Add to complete/failed set
|
741
744
|
rcall("ZADD", targetSet, timestamp, jobId)
|
742
|
-
rcall("
|
745
|
+
rcall("HSET", jobIdKey, ARGV[3], ARGV[4], "finishedOn", timestamp)
|
743
746
|
-- "returnvalue" / "failedReason" and "finishedOn"
|
747
|
+
if ARGV[5] == "failed" then
|
748
|
+
rcall("HDEL", jobIdKey, "defa")
|
749
|
+
end
|
744
750
|
-- Remove old jobs?
|
745
751
|
if maxAge ~= nil then
|
746
752
|
removeJobsByMaxAge(timestamp, maxAge, targetSet, prefix)
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAo0Bf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
|
@@ -39,12 +39,19 @@ local jobId = ARGV[4]
|
|
39
39
|
Function to recursively move from waitingChildren to failed.
|
40
40
|
]]
|
41
41
|
-- Includes
|
42
|
+
--[[
|
43
|
+
Validate and move parent to a wait status (waiting, delayed or prioritized)
|
44
|
+
if no pending dependencies.
|
45
|
+
]]
|
46
|
+
-- Includes
|
42
47
|
--[[
|
43
48
|
Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
|
44
49
|
]]
|
50
|
+
-- Includes
|
45
51
|
--[[
|
46
|
-
|
52
|
+
Move parent to a wait status (wait, prioritized or delayed)
|
47
53
|
]]
|
54
|
+
-- Includes
|
48
55
|
--[[
|
49
56
|
Add delay marker if needed.
|
50
57
|
]]
|
@@ -139,46 +146,53 @@ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
|
139
146
|
return waitKey, 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
|
189
|
+
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)
|
195
|
+
end
|
182
196
|
end
|
183
197
|
--[[
|
184
198
|
Function to remove deduplication key if needed.
|
@@ -369,38 +383,27 @@ moveParentToFailedIfNeeded = function (parentQueueKey, parentKey, parentId, jobI
|
|
369
383
|
local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
|
370
384
|
local parentDelayedKey = parentQueueKey .. ":delayed"
|
371
385
|
local parentPrioritizedKey = parentQueueKey .. ":prioritized"
|
372
|
-
local
|
386
|
+
local parentWaitingChildrenOrDelayedKey
|
373
387
|
local prevState
|
374
388
|
if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
|
375
|
-
|
389
|
+
parentWaitingChildrenOrDelayedKey = parentWaitingChildrenKey
|
376
390
|
prevState = "waiting-children"
|
377
391
|
elseif rcall("ZSCORE", parentDelayedKey, parentId) then
|
378
|
-
|
392
|
+
parentWaitingChildrenOrDelayedKey = parentDelayedKey
|
379
393
|
prevState = "delayed"
|
380
|
-
|
381
|
-
parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
|
382
|
-
prevState = "prioritized"
|
394
|
+
rcall("HSET", parentKey, "delay", 0)
|
383
395
|
end
|
384
|
-
if
|
385
|
-
rcall("ZREM",
|
396
|
+
if parentWaitingChildrenOrDelayedKey then
|
397
|
+
rcall("ZREM", parentWaitingChildrenOrDelayedKey, parentId)
|
386
398
|
local parentQueuePrefix = parentQueueKey .. ":"
|
387
399
|
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)
|
400
|
+
local deferredFailure = "child " .. jobIdKey .. " failed"
|
401
|
+
rcall("HSET", parentKey, "defa", deferredFailure)
|
402
|
+
moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
|
399
403
|
else
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
|
404
|
+
if not rcall("ZSCORE", parentQueueKey .. ":failed", parentId) then
|
405
|
+
local deferredFailure = "child " .. jobIdKey .. " failed"
|
406
|
+
rcall("HSET", parentKey, "defa", deferredFailure)
|
404
407
|
end
|
405
408
|
end
|
406
409
|
end
|
@@ -426,11 +429,11 @@ moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, failedRea
|
|
426
429
|
if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
|
427
430
|
local parentFailedChildrenKey = parentKey .. ":failed"
|
428
431
|
rcall("HSET", parentFailedChildrenKey, childKey, failedReason)
|
429
|
-
|
432
|
+
moveParentToWaitIfNeeded(parentData['queueKey'], parentKey, parentData['id'], timestamp)
|
430
433
|
end
|
431
434
|
elseif parentData['idof'] or parentData['rdof'] then
|
432
435
|
if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
|
433
|
-
|
436
|
+
moveParentToWaitIfNoPendingDependencies(parentData['queueKey'], parentDependenciesChildrenKey,
|
434
437
|
parentKey, parentData['id'], timestamp)
|
435
438
|
if parentData['idof'] then
|
436
439
|
local parentFailedChildrenKey = parentKey .. ":failed"
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"moveToWaitingChildren-8.js","sourceRoot":"","sources":["../../../src/scripts/moveToWaitingChildren-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"moveToWaitingChildren-8.js","sourceRoot":"","sources":["../../../src/scripts/moveToWaitingChildren-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8ff,CAAC;AACW,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|