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'],
@@ -235,7 +235,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
235
235
  parentKey, parentId, timestamp)
236
236
  local isParentActive = rcall("ZSCORE",
237
237
  parentQueueKey .. ":waiting-children", parentId)
238
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
238
+ if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
239
239
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
240
240
  local parentWaitKey = parentQueueKey .. ":wait"
241
241
  local parentPausedKey = parentQueueKey .. ":paused"
@@ -191,7 +191,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
191
191
  parentKey, parentId, timestamp)
192
192
  local isParentActive = rcall("ZSCORE",
193
193
  parentQueueKey .. ":waiting-children", parentId)
194
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
194
+ if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
195
195
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
196
196
  local parentWaitKey = parentQueueKey .. ":wait"
197
197
  local parentPausedKey = parentQueueKey .. ":paused"
@@ -228,7 +228,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
228
228
  parentKey, parentId, timestamp)
229
229
  local isParentActive = rcall("ZSCORE",
230
230
  parentQueueKey .. ":waiting-children", parentId)
231
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
231
+ if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
232
232
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
233
233
  local parentWaitKey = parentQueueKey .. ":wait"
234
234
  local parentPausedKey = parentQueueKey .. ":paused"
@@ -201,7 +201,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
201
201
  parentKey, parentId, timestamp)
202
202
  local isParentActive = rcall("ZSCORE",
203
203
  parentQueueKey .. ":waiting-children", parentId)
204
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
204
+ if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
205
205
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
206
206
  local parentWaitKey = parentQueueKey .. ":wait"
207
207
  local parentPausedKey = parentQueueKey .. ":paused"
@@ -140,7 +140,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
140
140
  parentKey, parentId, timestamp)
141
141
  local isParentActive = rcall("ZSCORE",
142
142
  parentQueueKey .. ":waiting-children", parentId)
143
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
143
+ if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
144
144
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
145
145
  local parentWaitKey = parentQueueKey .. ":wait"
146
146
  local parentPausedKey = parentQueueKey .. ":paused"
@@ -358,91 +358,69 @@ local function removeJobsOnFail(queueKeyPrefix, failedKey, jobId, opts, timestam
358
358
  end
359
359
  end
360
360
  end
361
- local function moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
362
- local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
363
- local parentDelayedKey = parentQueueKey .. ":delayed"
364
- if rcall("ZSCORE", parentWaitingChildrenKey, parentId) ~= false then
365
- rcall("ZREM", parentWaitingChildrenKey, parentId)
366
- local parentQueuePrefix = parentQueueKey .. ":"
367
- local parentFailedKey = parentQueueKey .. ":failed"
368
- rcall("ZADD", parentFailedKey, timestamp, parentId)
369
- local failedReason = "child " .. jobIdKey .. " failed"
370
- rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
371
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
372
- failedReason, "prev", "waiting-children")
373
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
374
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
375
- if jobAttributes[1] then
376
- local parentData = cjson.decode(jobAttributes[1])
377
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
378
- local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
379
- rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
380
- if parentData['fpof'] then
381
- moveParentFromWaitingChildrenToFailed(
382
- parentData['queueKey'],
383
- parentData['queueKey'] .. ':' .. parentData['id'],
384
- parentData['id'],
385
- parentKey,
386
- timestamp
387
- )
388
- elseif parentData['idof'] or parentData['rdof'] then
389
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
390
- local grandParentDependenciesSet = grandParentKey .. ":dependencies"
391
- if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
392
- moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
393
- grandParentKey, parentData['id'], timestamp)
394
- if parentData['idof'] then
395
- local grandParentFailedSet = grandParentKey .. ":failed"
396
- rcall("HSET", grandParentFailedSet, parentKey, failedReason)
397
- end
398
- end
399
- end
361
+ local function moveParentToFailedIfNeeded(parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
362
+ if rcall("EXISTS", parentKey) == 1 then
363
+ local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
364
+ local parentDelayedKey = parentQueueKey .. ":delayed"
365
+ local parentPrioritizedKey = parentQueueKey .. ":prioritized"
366
+ local parentWaitingChildrenOrDelayedOrPrioritizedKey
367
+ local prevState
368
+ if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
369
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentWaitingChildrenKey
370
+ prevState = "waiting-children"
371
+ elseif rcall("ZSCORE", parentDelayedKey, parentId) then
372
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentDelayedKey
373
+ prevState = "delayed"
374
+ elseif rcall("ZSCORE", parentPrioritizedKey, parentId) then
375
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
376
+ prevState = "prioritized"
400
377
  end
401
- local parentRawOpts = jobAttributes[3]
402
- local parentOpts = cjson.decode(parentRawOpts)
403
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
404
- elseif rcall("ZSCORE", parentDelayedKey, parentId) ~= false then
405
- rcall("ZREM", parentDelayedKey, parentId)
406
- local parentQueuePrefix = parentQueueKey .. ":"
407
- local parentFailedKey = parentQueueKey .. ":failed"
408
- rcall("ZADD", parentFailedKey, timestamp, parentId)
409
- local failedReason = "child " .. jobIdKey .. " failed"
410
- rcall("HMSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
411
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
412
- failedReason, "prev", "delayed")
413
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
414
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
415
- if jobAttributes[1] then
416
- local parentData = cjson.decode(jobAttributes[1])
417
- if parentData['fpof'] then
418
- moveParentFromWaitingChildrenToFailed(
419
- parentData['queueKey'],
420
- parentData['queueKey'] .. ':' .. parentData['id'],
421
- parentData['id'],
422
- parentKey,
423
- timestamp
424
- )
425
- elseif parentData['idof'] or parentData['rdof'] then
378
+ if parentWaitingChildrenOrDelayedOrPrioritizedKey then
379
+ rcall("ZREM", parentWaitingChildrenOrDelayedOrPrioritizedKey, parentId)
380
+ local parentQueuePrefix = parentQueueKey .. ":"
381
+ local parentFailedKey = parentQueueKey .. ":failed"
382
+ rcall("ZADD", parentFailedKey, timestamp, parentId)
383
+ local failedReason = "child " .. jobIdKey .. " failed"
384
+ rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
385
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
386
+ failedReason, "prev", prevState)
387
+ local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
388
+ removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
389
+ if jobAttributes[1] then
390
+ local parentData = cjson.decode(jobAttributes[1])
426
391
  local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
427
- local grandParentDependenciesSet = grandParentKey .. ":dependencies"
428
- if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
429
- moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
430
- grandParentKey, parentData['id'], timestamp)
431
- if parentData['idof'] then
432
- local grandParentFailedSet = grandParentKey .. ":failed"
433
- rcall("HSET", grandParentFailedSet, parentKey, failedReason)
392
+ local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
393
+ rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
394
+ if parentData['fpof'] then
395
+ moveParentToFailedIfNeeded(
396
+ parentData['queueKey'],
397
+ parentData['queueKey'] .. ':' .. parentData['id'],
398
+ parentData['id'],
399
+ parentKey,
400
+ timestamp
401
+ )
402
+ elseif parentData['idof'] or parentData['rdof'] then
403
+ local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
404
+ local grandParentDependenciesSet = grandParentKey .. ":dependencies"
405
+ if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
406
+ moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
407
+ grandParentKey, parentData['id'], timestamp)
408
+ if parentData['idof'] then
409
+ local grandParentFailedSet = grandParentKey .. ":failed"
410
+ rcall("HSET", grandParentFailedSet, parentKey, failedReason)
411
+ end
434
412
  end
435
413
  end
436
414
  end
437
- end
438
- local parentRawOpts = jobAttributes[3]
439
- local parentOpts = cjson.decode(parentRawOpts)
440
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
441
- else
442
- local grandParentKey = rcall("HGET", parentKey, "parentKey")
443
- if grandParentKey then
444
- local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
445
- rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
415
+ local parentRawOpts = jobAttributes[3]
416
+ local parentOpts = cjson.decode(parentRawOpts)
417
+ removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
418
+ else
419
+ local grandParentKey = rcall("HGET", parentKey, "parentKey")
420
+ if grandParentKey then
421
+ local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
422
+ rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
423
+ end
446
424
  end
447
425
  end
448
426
  end
@@ -530,7 +508,7 @@ if (#stalling > 0) then
530
508
  local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
531
509
  local unsuccesssfulSet = parentKey .. ":unsuccessful"
532
510
  rcall("ZADD", unsuccesssfulSet, timestamp, jobKey)
533
- moveParentFromWaitingChildrenToFailed(
511
+ moveParentToFailedIfNeeded(
534
512
  parentData['queueKey'],
535
513
  parentData['queueKey'] .. ':' .. parentData['id'],
536
514
  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;AAC1B,MAAM,CAAC,MAAM,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;AAC1B,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -235,7 +235,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
235
235
  parentKey, parentId, timestamp)
236
236
  local isParentActive = rcall("ZSCORE",
237
237
  parentQueueKey .. ":waiting-children", parentId)
238
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
238
+ if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
239
239
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
240
240
  local parentWaitKey = parentQueueKey .. ":wait"
241
241
  local parentPausedKey = parentQueueKey .. ":paused"
@@ -453,92 +453,70 @@ local function removeJobsOnFail(queueKeyPrefix, failedKey, jobId, opts, timestam
453
453
  end
454
454
  end
455
455
  end
456
- local function moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
457
- local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
458
- local parentDelayedKey = parentQueueKey .. ":delayed"
459
- if rcall("ZSCORE", parentWaitingChildrenKey, parentId) ~= false then
460
- rcall("ZREM", parentWaitingChildrenKey, parentId)
461
- local parentQueuePrefix = parentQueueKey .. ":"
462
- local parentFailedKey = parentQueueKey .. ":failed"
463
- rcall("ZADD", parentFailedKey, timestamp, parentId)
464
- local failedReason = "child " .. jobIdKey .. " failed"
465
- rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
466
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
467
- failedReason, "prev", "waiting-children")
468
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
469
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
470
- if jobAttributes[1] then
471
- local parentData = cjson.decode(jobAttributes[1])
472
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
473
- local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
474
- rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
475
- if parentData['fpof'] then
476
- moveParentFromWaitingChildrenToFailed(
477
- parentData['queueKey'],
478
- parentData['queueKey'] .. ':' .. parentData['id'],
479
- parentData['id'],
480
- parentKey,
481
- timestamp
482
- )
483
- elseif parentData['idof'] or parentData['rdof'] then
456
+ local function moveParentToFailedIfNeeded(parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
457
+ if rcall("EXISTS", parentKey) == 1 then
458
+ local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
459
+ local parentDelayedKey = parentQueueKey .. ":delayed"
460
+ local parentPrioritizedKey = parentQueueKey .. ":prioritized"
461
+ local parentWaitingChildrenOrDelayedOrPrioritizedKey
462
+ local prevState
463
+ if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
464
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentWaitingChildrenKey
465
+ prevState = "waiting-children"
466
+ elseif rcall("ZSCORE", parentDelayedKey, parentId) then
467
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentDelayedKey
468
+ prevState = "delayed"
469
+ elseif rcall("ZSCORE", parentPrioritizedKey, parentId) then
470
+ parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
471
+ prevState = "prioritized"
472
+ end
473
+ if parentWaitingChildrenOrDelayedOrPrioritizedKey then
474
+ rcall("ZREM", parentWaitingChildrenOrDelayedOrPrioritizedKey, parentId)
475
+ local parentQueuePrefix = parentQueueKey .. ":"
476
+ local parentFailedKey = parentQueueKey .. ":failed"
477
+ rcall("ZADD", parentFailedKey, timestamp, parentId)
478
+ local failedReason = "child " .. jobIdKey .. " failed"
479
+ rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
480
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
481
+ failedReason, "prev", prevState)
482
+ local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
483
+ removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
484
+ if jobAttributes[1] then
485
+ local parentData = cjson.decode(jobAttributes[1])
484
486
  local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
485
- local grandParentDependenciesSet = grandParentKey .. ":dependencies"
486
- if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
487
- moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
488
- grandParentKey, parentData['id'], timestamp)
489
- if parentData['idof'] then
490
- local grandParentFailedSet = grandParentKey .. ":failed"
491
- rcall("HSET", grandParentFailedSet, parentKey, failedReason)
487
+ local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
488
+ rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
489
+ if parentData['fpof'] then
490
+ moveParentToFailedIfNeeded(
491
+ parentData['queueKey'],
492
+ parentData['queueKey'] .. ':' .. parentData['id'],
493
+ parentData['id'],
494
+ parentKey,
495
+ timestamp
496
+ )
497
+ elseif parentData['idof'] or parentData['rdof'] then
498
+ local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
499
+ local grandParentDependenciesSet = grandParentKey .. ":dependencies"
500
+ if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
501
+ moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
502
+ grandParentKey, parentData['id'], timestamp)
503
+ if parentData['idof'] then
504
+ local grandParentFailedSet = grandParentKey .. ":failed"
505
+ rcall("HSET", grandParentFailedSet, parentKey, failedReason)
506
+ end
492
507
  end
493
508
  end
494
509
  end
495
- end
496
- local parentRawOpts = jobAttributes[3]
497
- local parentOpts = cjson.decode(parentRawOpts)
498
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
499
- elseif rcall("ZSCORE", parentDelayedKey, parentId) ~= false then
500
- rcall("ZREM", parentDelayedKey, parentId)
501
- local parentQueuePrefix = parentQueueKey .. ":"
502
- local parentFailedKey = parentQueueKey .. ":failed"
503
- rcall("ZADD", parentFailedKey, timestamp, parentId)
504
- local failedReason = "child " .. jobIdKey .. " failed"
505
- rcall("HMSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
506
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
507
- failedReason, "prev", "delayed")
508
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
509
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
510
- if jobAttributes[1] then
511
- local parentData = cjson.decode(jobAttributes[1])
512
- if parentData['fpof'] then
513
- moveParentFromWaitingChildrenToFailed(
514
- parentData['queueKey'],
515
- parentData['queueKey'] .. ':' .. parentData['id'],
516
- parentData['id'],
517
- parentKey,
518
- timestamp
519
- )
520
- elseif parentData['idof'] or parentData['rdof'] then
521
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
522
- local grandParentDependenciesSet = grandParentKey .. ":dependencies"
523
- if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
524
- moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
525
- grandParentKey, parentData['id'], timestamp)
526
- if parentData['idof'] then
527
- local grandParentFailedSet = grandParentKey .. ":failed"
528
- rcall("HSET", grandParentFailedSet, parentKey, failedReason)
529
- end
530
- end
510
+ local parentRawOpts = jobAttributes[3]
511
+ local parentOpts = cjson.decode(parentRawOpts)
512
+ removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
513
+ else
514
+ local grandParentKey = rcall("HGET", parentKey, "parentKey")
515
+ if grandParentKey then
516
+ local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
517
+ rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
531
518
  end
532
519
  end
533
- local parentRawOpts = jobAttributes[3]
534
- local parentOpts = cjson.decode(parentRawOpts)
535
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
536
- else
537
- local grandParentKey = rcall("HGET", parentKey, "parentKey")
538
- if grandParentKey then
539
- local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
540
- rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
541
- end
542
520
  end
543
521
  end
544
522
  --[[
@@ -730,7 +708,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
730
708
  if opts['fpof'] then
731
709
  local unsuccesssfulSet = parentKey .. ":unsuccessful"
732
710
  rcall("ZADD", unsuccesssfulSet, timestamp, jobIdKey)
733
- moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey,
711
+ moveParentToFailedIfNeeded(parentQueueKey, parentKey,
734
712
  parentId, jobIdKey,
735
713
  timestamp)
736
714
  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;AACF,MAAM,CAAC,MAAM,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;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}