bullmq 5.44.1 → 5.44.3

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 +5 -4
  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 +61 -59
  11. package/dist/cjs/scripts/moveStalledJobsToWait-9.js.map +1 -1
  12. package/dist/cjs/scripts/moveToFinished-14.js +64 -61
  13. package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
  14. package/dist/cjs/scripts/moveToWaitingChildren-8.js +62 -60
  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 +5 -4
  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 +61 -59
  28. package/dist/esm/scripts/moveStalledJobsToWait-9.js.map +1 -1
  29. package/dist/esm/scripts/moveToFinished-14.js +64 -61
  30. package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
  31. package/dist/esm/scripts/moveToWaitingChildren-8.js +62 -60
  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 -80
  38. package/dist/esm/commands/includes/moveParentFromWaitingChildrenToFailed.lua +0 -80
@@ -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"
@@ -95,7 +95,8 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
95
95
  local maxCount = opts['keepJobs']['count']
96
96
  local maxAge = opts['keepJobs']['age']
97
97
 
98
- if rcall("SCARD", jobIdKey .. ":dependencies") ~= 0 then -- // Make sure it does not have pending dependencies
98
+ -- Make sure it does not have pending dependencies
99
+ if ARGV[5] == "completed" and rcall("SCARD", jobIdKey .. ":dependencies") ~= 0 then
99
100
  return -4
100
101
  end
101
102
 
@@ -148,7 +149,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
148
149
  if opts['fpof'] then
149
150
  local unsuccesssfulSet = parentKey .. ":unsuccessful"
150
151
  rcall("ZADD", unsuccesssfulSet, timestamp, jobIdKey)
151
- moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey,
152
+ moveParentToFailedIfNeeded(parentQueueKey, parentKey,
152
153
  parentId, jobIdKey,
153
154
  timestamp)
154
155
  elseif opts['idof'] or opts['rdof'] then
@@ -194,7 +195,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
194
195
  end
195
196
 
196
197
  rcall("XADD", eventStreamKey, "*", "event", ARGV[5], "jobId", jobId, ARGV[3],
197
- ARGV[4])
198
+ ARGV[4], "prev", "active")
198
199
 
199
200
  if ARGV[5] == "failed" then
200
201
  if tonumber(attemptsMade) >= tonumber(attempts) 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,67 +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
- local parentPrioritizedKey = parentQueueKey .. ":prioritized"
368
- local parentWaitingChildrenOrDelayedOrPrioritizedKey
369
- local prevState
370
- if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
371
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentWaitingChildrenKey
372
- prevState = "waiting-children"
373
- elseif rcall("ZSCORE", parentDelayedKey, parentId) then
374
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentDelayedKey
375
- prevState = "delayed"
376
- elseif rcall("ZSCORE", parentPrioritizedKey, parentId) then
377
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
378
- prevState = "prioritized"
379
- end
380
- if parentWaitingChildrenOrDelayedOrPrioritizedKey then
381
- rcall("ZREM", parentWaitingChildrenOrDelayedOrPrioritizedKey, parentId)
382
- local parentQueuePrefix = parentQueueKey .. ":"
383
- local parentFailedKey = parentQueueKey .. ":failed"
384
- rcall("ZADD", parentFailedKey, timestamp, parentId)
385
- local failedReason = "child " .. jobIdKey .. " failed"
386
- rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
387
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
388
- failedReason, "prev", prevState)
389
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
390
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
391
- if jobAttributes[1] then
392
- local parentData = cjson.decode(jobAttributes[1])
393
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
394
- local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
395
- rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
396
- if parentData['fpof'] then
397
- moveParentFromWaitingChildrenToFailed(
398
- parentData['queueKey'],
399
- parentData['queueKey'] .. ':' .. parentData['id'],
400
- parentData['id'],
401
- parentKey,
402
- timestamp
403
- )
404
- elseif parentData['idof'] or parentData['rdof'] then
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"
380
+ end
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])
405
394
  local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
406
- local grandParentDependenciesSet = grandParentKey .. ":dependencies"
407
- if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
408
- moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
409
- grandParentKey, parentData['id'], timestamp)
410
- if parentData['idof'] then
411
- local grandParentFailedSet = grandParentKey .. ":failed"
412
- 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
413
415
  end
414
416
  end
415
417
  end
416
- end
417
- local parentRawOpts = jobAttributes[3]
418
- local parentOpts = cjson.decode(parentRawOpts)
419
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
420
- else
421
- local grandParentKey = rcall("HGET", parentKey, "parentKey")
422
- if grandParentKey then
423
- local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
424
- 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
425
427
  end
426
428
  end
427
429
  end
@@ -509,7 +511,7 @@ if (#stalling > 0) then
509
511
  local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
510
512
  local unsuccesssfulSet = parentKey .. ":unsuccessful"
511
513
  rcall("ZADD", unsuccesssfulSet, timestamp, jobKey)
512
- moveParentFromWaitingChildrenToFailed(
514
+ moveParentToFailedIfNeeded(
513
515
  parentData['queueKey'],
514
516
  parentData['queueKey'] .. ':' .. parentData['id'],
515
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBA2iBS,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,67 +456,69 @@ 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
- local parentPrioritizedKey = parentQueueKey .. ":prioritized"
463
- local parentWaitingChildrenOrDelayedOrPrioritizedKey
464
- local prevState
465
- if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
466
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentWaitingChildrenKey
467
- prevState = "waiting-children"
468
- elseif rcall("ZSCORE", parentDelayedKey, parentId) then
469
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentDelayedKey
470
- prevState = "delayed"
471
- elseif rcall("ZSCORE", parentPrioritizedKey, parentId) then
472
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
473
- prevState = "prioritized"
474
- end
475
- if parentWaitingChildrenOrDelayedOrPrioritizedKey then
476
- rcall("ZREM", parentWaitingChildrenOrDelayedOrPrioritizedKey, parentId)
477
- local parentQueuePrefix = parentQueueKey .. ":"
478
- local parentFailedKey = parentQueueKey .. ":failed"
479
- rcall("ZADD", parentFailedKey, timestamp, parentId)
480
- local failedReason = "child " .. jobIdKey .. " failed"
481
- rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
482
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
483
- failedReason, "prev", prevState)
484
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
485
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
486
- if jobAttributes[1] then
487
- local parentData = cjson.decode(jobAttributes[1])
488
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
489
- local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
490
- rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
491
- if parentData['fpof'] then
492
- moveParentFromWaitingChildrenToFailed(
493
- parentData['queueKey'],
494
- parentData['queueKey'] .. ':' .. parentData['id'],
495
- parentData['id'],
496
- parentKey,
497
- timestamp
498
- )
499
- 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])
500
489
  local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
501
- local grandParentDependenciesSet = grandParentKey .. ":dependencies"
502
- if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
503
- moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
504
- grandParentKey, parentData['id'], timestamp)
505
- if parentData['idof'] then
506
- local grandParentFailedSet = grandParentKey .. ":failed"
507
- 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
508
510
  end
509
511
  end
510
512
  end
511
- end
512
- local parentRawOpts = jobAttributes[3]
513
- local parentOpts = cjson.decode(parentRawOpts)
514
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
515
- else
516
- local grandParentKey = rcall("HGET", parentKey, "parentKey")
517
- if grandParentKey then
518
- local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
519
- rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
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)
521
+ end
520
522
  end
521
523
  end
522
524
  end
@@ -665,7 +667,8 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
665
667
  local maxMetricsSize = opts['maxMetricsSize']
666
668
  local maxCount = opts['keepJobs']['count']
667
669
  local maxAge = opts['keepJobs']['age']
668
- if rcall("SCARD", jobIdKey .. ":dependencies") ~= 0 then -- // Make sure it does not have pending dependencies
670
+ -- Make sure it does not have pending dependencies
671
+ if ARGV[5] == "completed" and rcall("SCARD", jobIdKey .. ":dependencies") ~= 0 then
669
672
  return -4
670
673
  end
671
674
  local jobAttributes = rcall("HMGET", jobIdKey, "parentKey", "parent", "deid")
@@ -709,7 +712,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
709
712
  if opts['fpof'] then
710
713
  local unsuccesssfulSet = parentKey .. ":unsuccessful"
711
714
  rcall("ZADD", unsuccesssfulSet, timestamp, jobIdKey)
712
- moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey,
715
+ moveParentToFailedIfNeeded(parentQueueKey, parentKey,
713
716
  parentId, jobIdKey,
714
717
  timestamp)
715
718
  elseif opts['idof'] or opts['rdof'] then
@@ -750,7 +753,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
750
753
  end
751
754
  end
752
755
  rcall("XADD", eventStreamKey, "*", "event", ARGV[5], "jobId", jobId, ARGV[3],
753
- ARGV[4])
756
+ ARGV[4], "prev", "active")
754
757
  if ARGV[5] == "failed" then
755
758
  if tonumber(attemptsMade) >= tonumber(attempts) then
756
759
  rcall("XADD", eventStreamKey, "*", "event", "retries-exhausted", "jobId",
@@ -1 +1 @@
1
- {"version":3,"file":"moveToFinished-14.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-14.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuzBf,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0zBf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}