bullmq 5.44.0 → 5.44.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.
Files changed (38) hide show
  1. package/dist/cjs/commands/includes/moveParentToFailedIfNeeded.lua +82 -0
  2. package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +1 -1
  3. package/dist/cjs/commands/moveStalledJobsToWait-9.lua +2 -2
  4. package/dist/cjs/commands/moveToFinished-14.lua +2 -2
  5. package/dist/cjs/commands/moveToWaitingChildren-8.lua +3 -3
  6. package/dist/cjs/scripts/addDelayedJob-6.js +1 -1
  7. package/dist/cjs/scripts/addParentJob-4.js +1 -1
  8. package/dist/cjs/scripts/addPrioritizedJob-8.js +1 -1
  9. package/dist/cjs/scripts/addStandardJob-8.js +1 -1
  10. package/dist/cjs/scripts/moveStalledJobsToWait-9.js +60 -82
  11. package/dist/cjs/scripts/moveStalledJobsToWait-9.js.map +1 -1
  12. package/dist/cjs/scripts/moveToFinished-14.js +60 -82
  13. package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
  14. package/dist/cjs/scripts/moveToWaitingChildren-8.js +61 -83
  15. package/dist/cjs/scripts/moveToWaitingChildren-8.js.map +1 -1
  16. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  17. package/dist/cjs/version.js +1 -1
  18. package/dist/esm/commands/includes/moveParentToFailedIfNeeded.lua +82 -0
  19. package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +1 -1
  20. package/dist/esm/commands/moveStalledJobsToWait-9.lua +2 -2
  21. package/dist/esm/commands/moveToFinished-14.lua +2 -2
  22. package/dist/esm/commands/moveToWaitingChildren-8.lua +3 -3
  23. package/dist/esm/scripts/addDelayedJob-6.js +1 -1
  24. package/dist/esm/scripts/addParentJob-4.js +1 -1
  25. package/dist/esm/scripts/addPrioritizedJob-8.js +1 -1
  26. package/dist/esm/scripts/addStandardJob-8.js +1 -1
  27. package/dist/esm/scripts/moveStalledJobsToWait-9.js +60 -82
  28. package/dist/esm/scripts/moveStalledJobsToWait-9.js.map +1 -1
  29. package/dist/esm/scripts/moveToFinished-14.js +60 -82
  30. package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
  31. package/dist/esm/scripts/moveToWaitingChildren-8.js +61 -83
  32. package/dist/esm/scripts/moveToWaitingChildren-8.js.map +1 -1
  33. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  34. package/dist/esm/version.d.ts +1 -1
  35. package/dist/esm/version.js +1 -1
  36. package/package.json +1 -1
  37. package/dist/cjs/commands/includes/moveParentFromWaitingChildrenToFailed.lua +0 -108
  38. package/dist/esm/commands/includes/moveParentFromWaitingChildrenToFailed.lua +0 -108
@@ -0,0 +1,82 @@
1
+ --[[
2
+ Function to recursively move from waitingChildren to failed.
3
+ ]]
4
+
5
+ -- Includes
6
+ --- @include "moveParentToWaitIfNeeded"
7
+ --- @include "removeDeduplicationKeyIfNeeded"
8
+ --- @include "removeJobsOnFail"
9
+
10
+ local function moveParentToFailedIfNeeded(parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
11
+ if rcall("EXISTS", parentKey) == 1 then
12
+ local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
13
+ local parentDelayedKey = parentQueueKey .. ":delayed"
14
+ local parentPrioritizedKey = parentQueueKey .. ":prioritized"
15
+ local parentWaitingChildrenOrDelayedOrPrioritizedKey
16
+ local prevState
17
+ if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
18
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentWaitingChildrenKey
19
+ prevState = "waiting-children"
20
+ elseif rcall("ZSCORE", parentDelayedKey, parentId) then
21
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentDelayedKey
22
+ prevState = "delayed"
23
+ elseif rcall("ZSCORE", parentPrioritizedKey, parentId) then
24
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
25
+ prevState = "prioritized"
26
+ end
27
+
28
+ if parentWaitingChildrenOrDelayedOrPrioritizedKey then
29
+ rcall("ZREM", parentWaitingChildrenOrDelayedOrPrioritizedKey, parentId)
30
+ local parentQueuePrefix = parentQueueKey .. ":"
31
+ local parentFailedKey = parentQueueKey .. ":failed"
32
+ rcall("ZADD", parentFailedKey, timestamp, parentId)
33
+ local failedReason = "child " .. jobIdKey .. " failed"
34
+ rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
35
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
36
+ failedReason, "prev", prevState)
37
+
38
+ local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
39
+
40
+ removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
41
+
42
+ if jobAttributes[1] then
43
+ local parentData = cjson.decode(jobAttributes[1])
44
+ local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
45
+ local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
46
+ rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
47
+ if parentData['fpof'] then
48
+ moveParentToFailedIfNeeded(
49
+ parentData['queueKey'],
50
+ parentData['queueKey'] .. ':' .. parentData['id'],
51
+ parentData['id'],
52
+ parentKey,
53
+ timestamp
54
+ )
55
+ elseif parentData['idof'] or parentData['rdof'] then
56
+ local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
57
+ local grandParentDependenciesSet = grandParentKey .. ":dependencies"
58
+ if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
59
+ moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
60
+ grandParentKey, parentData['id'], timestamp)
61
+ if parentData['idof'] then
62
+ local grandParentFailedSet = grandParentKey .. ":failed"
63
+ rcall("HSET", grandParentFailedSet, parentKey, failedReason)
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ local parentRawOpts = jobAttributes[3]
70
+ local parentOpts = cjson.decode(parentRawOpts)
71
+
72
+ removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
73
+ else
74
+ local grandParentKey = rcall("HGET", parentKey, "parentKey")
75
+
76
+ if grandParentKey then
77
+ local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
78
+ rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -13,7 +13,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
13
13
  parentKey, parentId, timestamp)
14
14
  local isParentActive = rcall("ZSCORE",
15
15
  parentQueueKey .. ":waiting-children", parentId)
16
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
16
+ if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
17
17
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
18
18
  local parentWaitKey = parentQueueKey .. ":wait"
19
19
  local parentPausedKey = parentQueueKey .. ":paused"
@@ -27,7 +27,7 @@ local rcall = redis.call
27
27
  --- @include "includes/addJobInTargetList"
28
28
  --- @include "includes/batches"
29
29
  --- @include "includes/getTargetQueueList"
30
- --- @include "includes/moveParentFromWaitingChildrenToFailed"
30
+ --- @include "includes/moveParentToFailedIfNeeded"
31
31
  --- @include "includes/moveParentToWaitIfNeeded"
32
32
  --- @include "includes/removeDeduplicationKeyIfNeeded"
33
33
  --- @include "includes/removeJobsOnFail"
@@ -103,7 +103,7 @@ if (#stalling > 0) then
103
103
  local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
104
104
  local unsuccesssfulSet = parentKey .. ":unsuccessful"
105
105
  rcall("ZADD", unsuccesssfulSet, timestamp, jobKey)
106
- moveParentFromWaitingChildrenToFailed(
106
+ moveParentToFailedIfNeeded(
107
107
  parentData['queueKey'],
108
108
  parentData['queueKey'] .. ':' .. parentData['id'],
109
109
  parentData['id'],
@@ -63,7 +63,7 @@ local rcall = redis.call
63
63
  --- @include "includes/getRateLimitTTL"
64
64
  --- @include "includes/getTargetQueueList"
65
65
  --- @include "includes/moveJobFromPriorityToActive"
66
- --- @include "includes/moveParentFromWaitingChildrenToFailed"
66
+ --- @include "includes/moveParentToFailedIfNeeded"
67
67
  --- @include "includes/moveParentToWaitIfNeeded"
68
68
  --- @include "includes/prepareJobForProcessing"
69
69
  --- @include "includes/promoteDelayedJobs"
@@ -148,7 +148,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
148
148
  if opts['fpof'] then
149
149
  local unsuccesssfulSet = parentKey .. ":unsuccessful"
150
150
  rcall("ZADD", unsuccesssfulSet, timestamp, jobIdKey)
151
- moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey,
151
+ moveParentToFailedIfNeeded(parentQueueKey, parentKey,
152
152
  parentId, jobIdKey,
153
153
  timestamp)
154
154
  elseif opts['idof'] or opts['rdof'] then
@@ -36,13 +36,13 @@ local timestamp = ARGV[3]
36
36
  local jobId = ARGV[4]
37
37
 
38
38
  --- Includes
39
- --- @include "includes/moveParentFromWaitingChildrenToFailed"
39
+ --- @include "includes/moveParentToFailedIfNeeded"
40
40
  --- @include "includes/moveParentToWaitIfNeeded"
41
41
  --- @include "includes/removeDeduplicationKeyIfNeeded"
42
42
  --- @include "includes/removeJobsOnFail"
43
43
  --- @include "includes/removeLock"
44
44
 
45
- local function moveToWaitingChildren (activeKey, waitingChildrenKey, jobId,
45
+ local function moveToWaitingChildren(activeKey, waitingChildrenKey, jobId,
46
46
  timestamp)
47
47
  local score = tonumber(timestamp)
48
48
 
@@ -80,7 +80,7 @@ if rcall("EXISTS", jobKey) == 1 then
80
80
  local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
81
81
  local parentUnsuccesssful = parentKey .. ":unsuccessful"
82
82
  rcall("ZADD", parentUnsuccesssful, timestamp, jobKey)
83
- moveParentFromWaitingChildrenToFailed(
83
+ moveParentToFailedIfNeeded(
84
84
  parentData['queueKey'],
85
85
  parentData['queueKey'] .. ':' .. parentData['id'],
86
86
  parentData['id'],
@@ -238,7 +238,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
238
238
  parentKey, parentId, timestamp)
239
239
  local isParentActive = rcall("ZSCORE",
240
240
  parentQueueKey .. ":waiting-children", parentId)
241
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
241
+ if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
242
242
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
243
243
  local parentWaitKey = parentQueueKey .. ":wait"
244
244
  local parentPausedKey = parentQueueKey .. ":paused"
@@ -194,7 +194,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
194
194
  parentKey, parentId, timestamp)
195
195
  local isParentActive = rcall("ZSCORE",
196
196
  parentQueueKey .. ":waiting-children", parentId)
197
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
197
+ if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
198
198
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
199
199
  local parentWaitKey = parentQueueKey .. ":wait"
200
200
  local parentPausedKey = parentQueueKey .. ":paused"
@@ -231,7 +231,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
231
231
  parentKey, parentId, timestamp)
232
232
  local isParentActive = rcall("ZSCORE",
233
233
  parentQueueKey .. ":waiting-children", parentId)
234
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
234
+ if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
235
235
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
236
236
  local parentWaitKey = parentQueueKey .. ":wait"
237
237
  local parentPausedKey = parentQueueKey .. ":paused"
@@ -204,7 +204,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
204
204
  parentKey, parentId, timestamp)
205
205
  local isParentActive = rcall("ZSCORE",
206
206
  parentQueueKey .. ":waiting-children", parentId)
207
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
207
+ if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
208
208
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
209
209
  local parentWaitKey = parentQueueKey .. ":wait"
210
210
  local parentPausedKey = parentQueueKey .. ":paused"
@@ -143,7 +143,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
143
143
  parentKey, parentId, timestamp)
144
144
  local isParentActive = rcall("ZSCORE",
145
145
  parentQueueKey .. ":waiting-children", parentId)
146
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
146
+ if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
147
147
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
148
148
  local parentWaitKey = parentQueueKey .. ":wait"
149
149
  local parentPausedKey = parentQueueKey .. ":paused"
@@ -361,91 +361,69 @@ local function removeJobsOnFail(queueKeyPrefix, failedKey, jobId, opts, timestam
361
361
  end
362
362
  end
363
363
  end
364
- local function moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
365
- local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
366
- local parentDelayedKey = parentQueueKey .. ":delayed"
367
- if rcall("ZSCORE", parentWaitingChildrenKey, parentId) ~= false then
368
- rcall("ZREM", parentWaitingChildrenKey, parentId)
369
- local parentQueuePrefix = parentQueueKey .. ":"
370
- local parentFailedKey = parentQueueKey .. ":failed"
371
- rcall("ZADD", parentFailedKey, timestamp, parentId)
372
- local failedReason = "child " .. jobIdKey .. " failed"
373
- rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
374
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
375
- failedReason, "prev", "waiting-children")
376
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
377
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
378
- if jobAttributes[1] then
379
- local parentData = cjson.decode(jobAttributes[1])
380
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
381
- local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
382
- rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
383
- if parentData['fpof'] then
384
- moveParentFromWaitingChildrenToFailed(
385
- parentData['queueKey'],
386
- parentData['queueKey'] .. ':' .. parentData['id'],
387
- parentData['id'],
388
- parentKey,
389
- timestamp
390
- )
391
- elseif parentData['idof'] or parentData['rdof'] then
392
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
393
- local grandParentDependenciesSet = grandParentKey .. ":dependencies"
394
- if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
395
- moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
396
- grandParentKey, parentData['id'], timestamp)
397
- if parentData['idof'] then
398
- local grandParentFailedSet = grandParentKey .. ":failed"
399
- rcall("HSET", grandParentFailedSet, parentKey, failedReason)
400
- end
401
- end
402
- end
364
+ local function moveParentToFailedIfNeeded(parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
365
+ if rcall("EXISTS", parentKey) == 1 then
366
+ local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
367
+ local parentDelayedKey = parentQueueKey .. ":delayed"
368
+ local parentPrioritizedKey = parentQueueKey .. ":prioritized"
369
+ local parentWaitingChildrenOrDelayedOrPrioritizedKey
370
+ local prevState
371
+ if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
372
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentWaitingChildrenKey
373
+ prevState = "waiting-children"
374
+ elseif rcall("ZSCORE", parentDelayedKey, parentId) then
375
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentDelayedKey
376
+ prevState = "delayed"
377
+ elseif rcall("ZSCORE", parentPrioritizedKey, parentId) then
378
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
379
+ prevState = "prioritized"
403
380
  end
404
- local parentRawOpts = jobAttributes[3]
405
- local parentOpts = cjson.decode(parentRawOpts)
406
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
407
- elseif rcall("ZSCORE", parentDelayedKey, parentId) ~= false then
408
- rcall("ZREM", parentDelayedKey, parentId)
409
- local parentQueuePrefix = parentQueueKey .. ":"
410
- local parentFailedKey = parentQueueKey .. ":failed"
411
- rcall("ZADD", parentFailedKey, timestamp, parentId)
412
- local failedReason = "child " .. jobIdKey .. " failed"
413
- rcall("HMSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
414
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
415
- failedReason, "prev", "delayed")
416
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
417
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
418
- if jobAttributes[1] then
419
- local parentData = cjson.decode(jobAttributes[1])
420
- if parentData['fpof'] then
421
- moveParentFromWaitingChildrenToFailed(
422
- parentData['queueKey'],
423
- parentData['queueKey'] .. ':' .. parentData['id'],
424
- parentData['id'],
425
- parentKey,
426
- timestamp
427
- )
428
- elseif parentData['idof'] or parentData['rdof'] then
381
+ if parentWaitingChildrenOrDelayedOrPrioritizedKey then
382
+ rcall("ZREM", parentWaitingChildrenOrDelayedOrPrioritizedKey, parentId)
383
+ local parentQueuePrefix = parentQueueKey .. ":"
384
+ local parentFailedKey = parentQueueKey .. ":failed"
385
+ rcall("ZADD", parentFailedKey, timestamp, parentId)
386
+ local failedReason = "child " .. jobIdKey .. " failed"
387
+ rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
388
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
389
+ failedReason, "prev", prevState)
390
+ local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
391
+ removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
392
+ if jobAttributes[1] then
393
+ local parentData = cjson.decode(jobAttributes[1])
429
394
  local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
430
- local grandParentDependenciesSet = grandParentKey .. ":dependencies"
431
- if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
432
- moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
433
- grandParentKey, parentData['id'], timestamp)
434
- if parentData['idof'] then
435
- local grandParentFailedSet = grandParentKey .. ":failed"
436
- rcall("HSET", grandParentFailedSet, parentKey, failedReason)
395
+ local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
396
+ rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
397
+ if parentData['fpof'] then
398
+ moveParentToFailedIfNeeded(
399
+ parentData['queueKey'],
400
+ parentData['queueKey'] .. ':' .. parentData['id'],
401
+ parentData['id'],
402
+ parentKey,
403
+ timestamp
404
+ )
405
+ elseif parentData['idof'] or parentData['rdof'] then
406
+ local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
407
+ local grandParentDependenciesSet = grandParentKey .. ":dependencies"
408
+ if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
409
+ moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
410
+ grandParentKey, parentData['id'], timestamp)
411
+ if parentData['idof'] then
412
+ local grandParentFailedSet = grandParentKey .. ":failed"
413
+ rcall("HSET", grandParentFailedSet, parentKey, failedReason)
414
+ end
437
415
  end
438
416
  end
439
417
  end
440
- end
441
- local parentRawOpts = jobAttributes[3]
442
- local parentOpts = cjson.decode(parentRawOpts)
443
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
444
- else
445
- local grandParentKey = rcall("HGET", parentKey, "parentKey")
446
- if grandParentKey then
447
- local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
448
- rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
418
+ local parentRawOpts = jobAttributes[3]
419
+ local parentOpts = cjson.decode(parentRawOpts)
420
+ removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
421
+ else
422
+ local grandParentKey = rcall("HGET", parentKey, "parentKey")
423
+ if grandParentKey then
424
+ local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
425
+ rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
426
+ end
449
427
  end
450
428
  end
451
429
  end
@@ -533,7 +511,7 @@ if (#stalling > 0) then
533
511
  local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
534
512
  local unsuccesssfulSet = parentKey .. ":unsuccessful"
535
513
  rcall("ZADD", unsuccesssfulSet, timestamp, jobKey)
536
- moveParentFromWaitingChildrenToFailed(
514
+ moveParentToFailedIfNeeded(
537
515
  parentData['queueKey'],
538
516
  parentData['queueKey'] .. ':' .. parentData['id'],
539
517
  parentData['id'],
@@ -1 +1 @@
1
- {"version":3,"file":"moveStalledJobsToWait-9.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-9.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAmkBS,CAAC;AACb,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"moveStalledJobsToWait-9.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-9.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBA6iBS,CAAC;AACb,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -238,7 +238,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
238
238
  parentKey, parentId, timestamp)
239
239
  local isParentActive = rcall("ZSCORE",
240
240
  parentQueueKey .. ":waiting-children", parentId)
241
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
241
+ if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
242
242
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
243
243
  local parentWaitKey = parentQueueKey .. ":wait"
244
244
  local parentPausedKey = parentQueueKey .. ":paused"
@@ -456,92 +456,70 @@ local function removeJobsOnFail(queueKeyPrefix, failedKey, jobId, opts, timestam
456
456
  end
457
457
  end
458
458
  end
459
- local function moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
460
- local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
461
- local parentDelayedKey = parentQueueKey .. ":delayed"
462
- if rcall("ZSCORE", parentWaitingChildrenKey, parentId) ~= false then
463
- rcall("ZREM", parentWaitingChildrenKey, parentId)
464
- local parentQueuePrefix = parentQueueKey .. ":"
465
- local parentFailedKey = parentQueueKey .. ":failed"
466
- rcall("ZADD", parentFailedKey, timestamp, parentId)
467
- local failedReason = "child " .. jobIdKey .. " failed"
468
- rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
469
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
470
- failedReason, "prev", "waiting-children")
471
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
472
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
473
- if jobAttributes[1] then
474
- local parentData = cjson.decode(jobAttributes[1])
475
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
476
- local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
477
- rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
478
- if parentData['fpof'] then
479
- moveParentFromWaitingChildrenToFailed(
480
- parentData['queueKey'],
481
- parentData['queueKey'] .. ':' .. parentData['id'],
482
- parentData['id'],
483
- parentKey,
484
- timestamp
485
- )
486
- elseif parentData['idof'] or parentData['rdof'] then
459
+ local function moveParentToFailedIfNeeded(parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
460
+ if rcall("EXISTS", parentKey) == 1 then
461
+ local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
462
+ local parentDelayedKey = parentQueueKey .. ":delayed"
463
+ local parentPrioritizedKey = parentQueueKey .. ":prioritized"
464
+ local parentWaitingChildrenOrDelayedOrPrioritizedKey
465
+ local prevState
466
+ if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
467
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentWaitingChildrenKey
468
+ prevState = "waiting-children"
469
+ elseif rcall("ZSCORE", parentDelayedKey, parentId) then
470
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentDelayedKey
471
+ prevState = "delayed"
472
+ elseif rcall("ZSCORE", parentPrioritizedKey, parentId) then
473
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
474
+ prevState = "prioritized"
475
+ end
476
+ if parentWaitingChildrenOrDelayedOrPrioritizedKey then
477
+ rcall("ZREM", parentWaitingChildrenOrDelayedOrPrioritizedKey, parentId)
478
+ local parentQueuePrefix = parentQueueKey .. ":"
479
+ local parentFailedKey = parentQueueKey .. ":failed"
480
+ rcall("ZADD", parentFailedKey, timestamp, parentId)
481
+ local failedReason = "child " .. jobIdKey .. " failed"
482
+ rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
483
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
484
+ failedReason, "prev", prevState)
485
+ local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
486
+ removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
487
+ if jobAttributes[1] then
488
+ local parentData = cjson.decode(jobAttributes[1])
487
489
  local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
488
- local grandParentDependenciesSet = grandParentKey .. ":dependencies"
489
- if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
490
- moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
491
- grandParentKey, parentData['id'], timestamp)
492
- if parentData['idof'] then
493
- local grandParentFailedSet = grandParentKey .. ":failed"
494
- rcall("HSET", grandParentFailedSet, parentKey, failedReason)
490
+ local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
491
+ rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
492
+ if parentData['fpof'] then
493
+ moveParentToFailedIfNeeded(
494
+ parentData['queueKey'],
495
+ parentData['queueKey'] .. ':' .. parentData['id'],
496
+ parentData['id'],
497
+ parentKey,
498
+ timestamp
499
+ )
500
+ elseif parentData['idof'] or parentData['rdof'] then
501
+ local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
502
+ local grandParentDependenciesSet = grandParentKey .. ":dependencies"
503
+ if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
504
+ moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
505
+ grandParentKey, parentData['id'], timestamp)
506
+ if parentData['idof'] then
507
+ local grandParentFailedSet = grandParentKey .. ":failed"
508
+ rcall("HSET", grandParentFailedSet, parentKey, failedReason)
509
+ end
495
510
  end
496
511
  end
497
512
  end
498
- end
499
- local parentRawOpts = jobAttributes[3]
500
- local parentOpts = cjson.decode(parentRawOpts)
501
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
502
- elseif rcall("ZSCORE", parentDelayedKey, parentId) ~= false then
503
- rcall("ZREM", parentDelayedKey, parentId)
504
- local parentQueuePrefix = parentQueueKey .. ":"
505
- local parentFailedKey = parentQueueKey .. ":failed"
506
- rcall("ZADD", parentFailedKey, timestamp, parentId)
507
- local failedReason = "child " .. jobIdKey .. " failed"
508
- rcall("HMSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
509
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
510
- failedReason, "prev", "delayed")
511
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
512
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
513
- if jobAttributes[1] then
514
- local parentData = cjson.decode(jobAttributes[1])
515
- if parentData['fpof'] then
516
- moveParentFromWaitingChildrenToFailed(
517
- parentData['queueKey'],
518
- parentData['queueKey'] .. ':' .. parentData['id'],
519
- parentData['id'],
520
- parentKey,
521
- timestamp
522
- )
523
- elseif parentData['idof'] or parentData['rdof'] then
524
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
525
- local grandParentDependenciesSet = grandParentKey .. ":dependencies"
526
- if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
527
- moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
528
- grandParentKey, parentData['id'], timestamp)
529
- if parentData['idof'] then
530
- local grandParentFailedSet = grandParentKey .. ":failed"
531
- rcall("HSET", grandParentFailedSet, parentKey, failedReason)
532
- end
533
- end
513
+ local parentRawOpts = jobAttributes[3]
514
+ local parentOpts = cjson.decode(parentRawOpts)
515
+ removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
516
+ else
517
+ local grandParentKey = rcall("HGET", parentKey, "parentKey")
518
+ if grandParentKey then
519
+ local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
520
+ rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
534
521
  end
535
522
  end
536
- local parentRawOpts = jobAttributes[3]
537
- local parentOpts = cjson.decode(parentRawOpts)
538
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
539
- else
540
- local grandParentKey = rcall("HGET", parentKey, "parentKey")
541
- if grandParentKey then
542
- local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
543
- rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
544
- end
545
523
  end
546
524
  end
547
525
  --[[
@@ -733,7 +711,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
733
711
  if opts['fpof'] then
734
712
  local unsuccesssfulSet = parentKey .. ":unsuccessful"
735
713
  rcall("ZADD", unsuccesssfulSet, timestamp, jobIdKey)
736
- moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey,
714
+ moveParentToFailedIfNeeded(parentQueueKey, parentKey,
737
715
  parentId, jobIdKey,
738
716
  timestamp)
739
717
  elseif opts['idof'] or opts['rdof'] then
@@ -1 +1 @@
1
- {"version":3,"file":"moveToFinished-14.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-14.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+0Bf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
1
+ {"version":3,"file":"moveToFinished-14.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-14.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyzBf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}