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
@@ -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'],
@@ -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,67 +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
- local parentPrioritizedKey = parentQueueKey .. ":prioritized"
365
- local parentWaitingChildrenOrDelayedOrPrioritizedKey
366
- local prevState
367
- if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
368
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentWaitingChildrenKey
369
- prevState = "waiting-children"
370
- elseif rcall("ZSCORE", parentDelayedKey, parentId) then
371
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentDelayedKey
372
- prevState = "delayed"
373
- elseif rcall("ZSCORE", parentPrioritizedKey, parentId) then
374
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
375
- prevState = "prioritized"
376
- end
377
- if parentWaitingChildrenOrDelayedOrPrioritizedKey then
378
- rcall("ZREM", parentWaitingChildrenOrDelayedOrPrioritizedKey, parentId)
379
- local parentQueuePrefix = parentQueueKey .. ":"
380
- local parentFailedKey = parentQueueKey .. ":failed"
381
- rcall("ZADD", parentFailedKey, timestamp, parentId)
382
- local failedReason = "child " .. jobIdKey .. " failed"
383
- rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
384
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
385
- failedReason, "prev", prevState)
386
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
387
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
388
- if jobAttributes[1] then
389
- local parentData = cjson.decode(jobAttributes[1])
390
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
391
- local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
392
- rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
393
- if parentData['fpof'] then
394
- moveParentFromWaitingChildrenToFailed(
395
- parentData['queueKey'],
396
- parentData['queueKey'] .. ':' .. parentData['id'],
397
- parentData['id'],
398
- parentKey,
399
- timestamp
400
- )
401
- elseif parentData['idof'] or parentData['rdof'] then
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"
377
+ end
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])
402
391
  local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
403
- local grandParentDependenciesSet = grandParentKey .. ":dependencies"
404
- if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
405
- moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
406
- grandParentKey, parentData['id'], timestamp)
407
- if parentData['idof'] then
408
- local grandParentFailedSet = grandParentKey .. ":failed"
409
- 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
410
412
  end
411
413
  end
412
414
  end
413
- end
414
- local parentRawOpts = jobAttributes[3]
415
- local parentOpts = cjson.decode(parentRawOpts)
416
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
417
- else
418
- local grandParentKey = rcall("HGET", parentKey, "parentKey")
419
- if grandParentKey then
420
- local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
421
- 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
422
424
  end
423
425
  end
424
426
  end
@@ -506,7 +508,7 @@ if (#stalling > 0) then
506
508
  local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
507
509
  local unsuccesssfulSet = parentKey .. ":unsuccessful"
508
510
  rcall("ZADD", unsuccesssfulSet, timestamp, jobKey)
509
- moveParentFromWaitingChildrenToFailed(
511
+ moveParentToFailedIfNeeded(
510
512
  parentData['queueKey'],
511
513
  parentData['queueKey'] .. ':' .. parentData['id'],
512
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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@ 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,67 +453,69 @@ 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
- local parentPrioritizedKey = parentQueueKey .. ":prioritized"
460
- local parentWaitingChildrenOrDelayedOrPrioritizedKey
461
- local prevState
462
- if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
463
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentWaitingChildrenKey
464
- prevState = "waiting-children"
465
- elseif rcall("ZSCORE", parentDelayedKey, parentId) then
466
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentDelayedKey
467
- prevState = "delayed"
468
- elseif rcall("ZSCORE", parentPrioritizedKey, parentId) then
469
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
470
- prevState = "prioritized"
471
- end
472
- if parentWaitingChildrenOrDelayedOrPrioritizedKey then
473
- rcall("ZREM", parentWaitingChildrenOrDelayedOrPrioritizedKey, parentId)
474
- local parentQueuePrefix = parentQueueKey .. ":"
475
- local parentFailedKey = parentQueueKey .. ":failed"
476
- rcall("ZADD", parentFailedKey, timestamp, parentId)
477
- local failedReason = "child " .. jobIdKey .. " failed"
478
- rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
479
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
480
- failedReason, "prev", prevState)
481
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
482
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
483
- if jobAttributes[1] then
484
- local parentData = cjson.decode(jobAttributes[1])
485
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
486
- local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
487
- rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
488
- if parentData['fpof'] then
489
- moveParentFromWaitingChildrenToFailed(
490
- parentData['queueKey'],
491
- parentData['queueKey'] .. ':' .. parentData['id'],
492
- parentData['id'],
493
- parentKey,
494
- timestamp
495
- )
496
- 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])
497
486
  local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
498
- local grandParentDependenciesSet = grandParentKey .. ":dependencies"
499
- if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
500
- moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
501
- grandParentKey, parentData['id'], timestamp)
502
- if parentData['idof'] then
503
- local grandParentFailedSet = grandParentKey .. ":failed"
504
- 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
505
507
  end
506
508
  end
507
509
  end
508
- end
509
- local parentRawOpts = jobAttributes[3]
510
- local parentOpts = cjson.decode(parentRawOpts)
511
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
512
- else
513
- local grandParentKey = rcall("HGET", parentKey, "parentKey")
514
- if grandParentKey then
515
- local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
516
- rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
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)
518
+ end
517
519
  end
518
520
  end
519
521
  end
@@ -662,7 +664,8 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
662
664
  local maxMetricsSize = opts['maxMetricsSize']
663
665
  local maxCount = opts['keepJobs']['count']
664
666
  local maxAge = opts['keepJobs']['age']
665
- if rcall("SCARD", jobIdKey .. ":dependencies") ~= 0 then -- // Make sure it does not have pending dependencies
667
+ -- Make sure it does not have pending dependencies
668
+ if ARGV[5] == "completed" and rcall("SCARD", jobIdKey .. ":dependencies") ~= 0 then
666
669
  return -4
667
670
  end
668
671
  local jobAttributes = rcall("HMGET", jobIdKey, "parentKey", "parent", "deid")
@@ -706,7 +709,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
706
709
  if opts['fpof'] then
707
710
  local unsuccesssfulSet = parentKey .. ":unsuccessful"
708
711
  rcall("ZADD", unsuccesssfulSet, timestamp, jobIdKey)
709
- moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey,
712
+ moveParentToFailedIfNeeded(parentQueueKey, parentKey,
710
713
  parentId, jobIdKey,
711
714
  timestamp)
712
715
  elseif opts['idof'] or opts['rdof'] then
@@ -747,7 +750,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
747
750
  end
748
751
  end
749
752
  rcall("XADD", eventStreamKey, "*", "event", ARGV[5], "jobId", jobId, ARGV[3],
750
- ARGV[4])
753
+ ARGV[4], "prev", "active")
751
754
  if ARGV[5] == "failed" then
752
755
  if tonumber(attemptsMade) >= tonumber(attempts) then
753
756
  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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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