bullmq 5.49.0 → 5.49.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/cjs/classes/flow-producer.js +1 -0
  2. package/dist/cjs/classes/flow-producer.js.map +1 -1
  3. package/dist/cjs/classes/job.js +3 -0
  4. package/dist/cjs/classes/job.js.map +1 -1
  5. package/dist/cjs/classes/worker.js +4 -0
  6. package/dist/cjs/classes/worker.js.map +1 -1
  7. package/dist/cjs/commands/includes/moveChildFromDependenciesIfNeeded.lua +15 -31
  8. package/dist/cjs/commands/includes/moveParentToWait.lua +32 -33
  9. package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +8 -4
  10. package/dist/cjs/commands/includes/moveParentToWaitIfNoPendingDependencies.lua +13 -0
  11. package/dist/cjs/commands/includes/updateParentDepsIfNeeded.lua +2 -2
  12. package/dist/cjs/commands/moveStalledJobsToWait-9.lua +0 -2
  13. package/dist/cjs/commands/moveToFinished-14.lua +5 -3
  14. package/dist/cjs/commands/moveToWaitingChildren-8.lua +0 -2
  15. package/dist/cjs/scripts/addDelayedJob-6.js +51 -37
  16. package/dist/cjs/scripts/addDelayedJob-6.js.map +1 -1
  17. package/dist/cjs/scripts/addParentJob-4.js +51 -37
  18. package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
  19. package/dist/cjs/scripts/addPrioritizedJob-8.js +51 -37
  20. package/dist/cjs/scripts/addPrioritizedJob-8.js.map +1 -1
  21. package/dist/cjs/scripts/addStandardJob-8.js +51 -37
  22. package/dist/cjs/scripts/addStandardJob-8.js.map +1 -1
  23. package/dist/cjs/scripts/moveStalledJobsToWait-9.js +64 -61
  24. package/dist/cjs/scripts/moveStalledJobsToWait-9.js.map +1 -1
  25. package/dist/cjs/scripts/moveToFinished-14.js +69 -63
  26. package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
  27. package/dist/cjs/scripts/moveToWaitingChildren-8.js +64 -61
  28. package/dist/cjs/scripts/moveToWaitingChildren-8.js.map +1 -1
  29. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  30. package/dist/cjs/version.js +1 -1
  31. package/dist/esm/classes/flow-producer.js +1 -0
  32. package/dist/esm/classes/flow-producer.js.map +1 -1
  33. package/dist/esm/classes/job.d.ts +5 -0
  34. package/dist/esm/classes/job.js +3 -0
  35. package/dist/esm/classes/job.js.map +1 -1
  36. package/dist/esm/classes/worker.js +5 -1
  37. package/dist/esm/classes/worker.js.map +1 -1
  38. package/dist/esm/commands/includes/moveChildFromDependenciesIfNeeded.lua +15 -31
  39. package/dist/esm/commands/includes/moveParentToWait.lua +32 -33
  40. package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +8 -4
  41. package/dist/esm/commands/includes/moveParentToWaitIfNoPendingDependencies.lua +13 -0
  42. package/dist/esm/commands/includes/updateParentDepsIfNeeded.lua +2 -2
  43. package/dist/esm/commands/moveStalledJobsToWait-9.lua +0 -2
  44. package/dist/esm/commands/moveToFinished-14.lua +5 -3
  45. package/dist/esm/commands/moveToWaitingChildren-8.lua +0 -2
  46. package/dist/esm/interfaces/job-json.d.ts +1 -0
  47. package/dist/esm/scripts/addDelayedJob-6.js +51 -37
  48. package/dist/esm/scripts/addDelayedJob-6.js.map +1 -1
  49. package/dist/esm/scripts/addParentJob-4.js +51 -37
  50. package/dist/esm/scripts/addParentJob-4.js.map +1 -1
  51. package/dist/esm/scripts/addPrioritizedJob-8.js +51 -37
  52. package/dist/esm/scripts/addPrioritizedJob-8.js.map +1 -1
  53. package/dist/esm/scripts/addStandardJob-8.js +51 -37
  54. package/dist/esm/scripts/addStandardJob-8.js.map +1 -1
  55. package/dist/esm/scripts/moveStalledJobsToWait-9.js +64 -61
  56. package/dist/esm/scripts/moveStalledJobsToWait-9.js.map +1 -1
  57. package/dist/esm/scripts/moveToFinished-14.js +69 -63
  58. package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
  59. package/dist/esm/scripts/moveToWaitingChildren-8.js +64 -61
  60. package/dist/esm/scripts/moveToWaitingChildren-8.js.map +1 -1
  61. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  62. package/dist/esm/version.d.ts +1 -1
  63. package/dist/esm/version.js +1 -1
  64. package/package.json +1 -1
@@ -167,12 +167,19 @@ end
167
167
  Function to recursively move from waitingChildren to failed.
168
168
  ]]
169
169
  -- Includes
170
+ --[[
171
+ Validate and move parent to a wait status (waiting, delayed or prioritized)
172
+ if no pending dependencies.
173
+ ]]
174
+ -- Includes
170
175
  --[[
171
176
  Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
172
177
  ]]
178
+ -- Includes
173
179
  --[[
174
- Validate and move parent to a wait status (wait, prioritized or delayed)
180
+ Move parent to a wait status (wait, prioritized or delayed)
175
181
  ]]
182
+ -- Includes
176
183
  --[[
177
184
  Add delay marker if needed.
178
185
  ]]
@@ -235,46 +242,53 @@ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
235
242
  return false
236
243
  end
237
244
  local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
238
- local isParentWaitingChildren = rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
239
- if isParentWaitingChildren > 0 then
240
- local parentWaitKey = parentQueueKey .. ":wait"
241
- local parentPausedKey = parentQueueKey .. ":paused"
242
- local parentActiveKey = parentQueueKey .. ":active"
243
- local parentMetaKey = parentQueueKey .. ":meta"
244
- local parentMarkerKey = parentQueueKey .. ":marker"
245
- local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
246
- local priority = tonumber(jobAttributes[1]) or 0
247
- local delay = tonumber(jobAttributes[2]) or 0
248
- -- ignore dependencies if any left
249
- rcall("HSET", parentKey, "igdp", 1)
250
- if delay > 0 then
251
- local delayedTimestamp = tonumber(timestamp) + delay
252
- local score = delayedTimestamp * 0x1000
253
- local parentDelayedKey = parentQueueKey .. ":delayed"
254
- rcall("ZADD", parentDelayedKey, score, parentId)
255
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
256
- delayedTimestamp)
257
- addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
245
+ local parentWaitKey = parentQueueKey .. ":wait"
246
+ local parentPausedKey = parentQueueKey .. ":paused"
247
+ local parentActiveKey = parentQueueKey .. ":active"
248
+ local parentMetaKey = parentQueueKey .. ":meta"
249
+ local parentMarkerKey = parentQueueKey .. ":marker"
250
+ local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
251
+ local priority = tonumber(jobAttributes[1]) or 0
252
+ local delay = tonumber(jobAttributes[2]) or 0
253
+ -- ignore dependencies if any left
254
+ rcall("HSET", parentKey, "igdp", 1)
255
+ if delay > 0 then
256
+ local delayedTimestamp = tonumber(timestamp) + delay
257
+ local score = delayedTimestamp * 0x1000
258
+ local parentDelayedKey = parentQueueKey .. ":delayed"
259
+ rcall("ZADD", parentDelayedKey, score, parentId)
260
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
261
+ delayedTimestamp)
262
+ addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
263
+ else
264
+ if priority == 0 then
265
+ local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
266
+ parentWaitKey, parentPausedKey)
267
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
258
268
  else
259
- if priority == 0 then
260
- local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
261
- parentWaitKey, parentPausedKey)
262
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
263
- else
264
- local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
265
- addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
266
- parentQueueKey .. ":pc", isPausedOrMaxed)
267
- end
268
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
269
- "waiting-children")
269
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
270
+ addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
271
+ parentQueueKey .. ":pc", isPausedOrMaxed)
270
272
  end
273
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
274
+ "waiting-children")
271
275
  end
272
276
  end
273
- local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
274
- local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
275
- if doNotHavePendingDependencies then
276
- moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
277
+ local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
278
+ if rcall("EXISTS", parentKey) == 1 then
279
+ local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
280
+ if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
281
+ rcall("ZREM", parentWaitingChildrenKey, parentId)
282
+ moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
277
283
  end
284
+ end
285
+ end
286
+ local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
287
+ parentId, timestamp)
288
+ local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
289
+ if doNotHavePendingDependencies then
290
+ moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
291
+ end
278
292
  end
279
293
  --[[
280
294
  Function to remove deduplication key if needed.
@@ -465,38 +479,27 @@ moveParentToFailedIfNeeded = function (parentQueueKey, parentKey, parentId, jobI
465
479
  local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
466
480
  local parentDelayedKey = parentQueueKey .. ":delayed"
467
481
  local parentPrioritizedKey = parentQueueKey .. ":prioritized"
468
- local parentWaitingChildrenOrDelayedOrPrioritizedKey
482
+ local parentWaitingChildrenOrDelayedKey
469
483
  local prevState
470
484
  if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
471
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentWaitingChildrenKey
485
+ parentWaitingChildrenOrDelayedKey = parentWaitingChildrenKey
472
486
  prevState = "waiting-children"
473
487
  elseif rcall("ZSCORE", parentDelayedKey, parentId) then
474
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentDelayedKey
488
+ parentWaitingChildrenOrDelayedKey = parentDelayedKey
475
489
  prevState = "delayed"
476
- elseif rcall("ZSCORE", parentPrioritizedKey, parentId) then
477
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
478
- prevState = "prioritized"
490
+ rcall("HSET", parentKey, "delay", 0)
479
491
  end
480
- if parentWaitingChildrenOrDelayedOrPrioritizedKey then
481
- rcall("ZREM", parentWaitingChildrenOrDelayedOrPrioritizedKey, parentId)
492
+ if parentWaitingChildrenOrDelayedKey then
493
+ rcall("ZREM", parentWaitingChildrenOrDelayedKey, parentId)
482
494
  local parentQueuePrefix = parentQueueKey .. ":"
483
495
  local parentFailedKey = parentQueueKey .. ":failed"
484
- rcall("ZADD", parentFailedKey, timestamp, parentId)
485
- local failedReason = "child " .. jobIdKey .. " failed"
486
- rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
487
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
488
- failedReason, "prev", prevState)
489
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
490
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
491
- moveChildFromDependenciesIfNeeded(jobAttributes[1], parentKey, failedReason, timestamp)
492
- local parentRawOpts = jobAttributes[3]
493
- local parentOpts = cjson.decode(parentRawOpts)
494
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
496
+ local deferredFailure = "child " .. jobIdKey .. " failed"
497
+ rcall("HSET", parentKey, "defa", deferredFailure)
498
+ moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
495
499
  else
496
- local grandParentKey = rcall("HGET", parentKey, "parentKey")
497
- if grandParentKey then
498
- local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
499
- rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
500
+ if not rcall("ZSCORE", parentQueueKey .. ":failed", parentId) then
501
+ local deferredFailure = "child " .. jobIdKey .. " failed"
502
+ rcall("HSET", parentKey, "defa", deferredFailure)
500
503
  end
501
504
  end
502
505
  end
@@ -522,11 +525,11 @@ moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, failedRea
522
525
  if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
523
526
  local parentFailedChildrenKey = parentKey .. ":failed"
524
527
  rcall("HSET", parentFailedChildrenKey, childKey, failedReason)
525
- moveParentToWait(parentData['queueKey'], parentKey, parentData['id'], timestamp)
528
+ moveParentToWaitIfNeeded(parentData['queueKey'], parentKey, parentData['id'], timestamp)
526
529
  end
527
530
  elseif parentData['idof'] or parentData['rdof'] then
528
531
  if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
529
- moveParentToWaitIfNeeded(parentData['queueKey'], parentDependenciesChildrenKey,
532
+ moveParentToWaitIfNoPendingDependencies(parentData['queueKey'], parentDependenciesChildrenKey,
530
533
  parentKey, parentData['id'], timestamp)
531
534
  if parentData['idof'] then
532
535
  local parentFailedChildrenKey = parentKey .. ":failed"
@@ -655,7 +658,7 @@ local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDepende
655
658
  parentId, jobIdKey, returnvalue, timestamp )
656
659
  local processedSet = parentKey .. ":processed"
657
660
  rcall("HSET", processedSet, jobIdKey, returnvalue)
658
- moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
661
+ moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
659
662
  end
660
663
  --[[
661
664
  Function to update a bunch of fields in a job.
@@ -736,8 +739,11 @@ if rcall("EXISTS", jobIdKey) == 1 then -- Make sure job exists
736
739
  local targetSet = KEYS[11]
737
740
  -- Add to complete/failed set
738
741
  rcall("ZADD", targetSet, timestamp, jobId)
739
- rcall("HMSET", jobIdKey, ARGV[3], ARGV[4], "finishedOn", timestamp)
742
+ rcall("HSET", jobIdKey, ARGV[3], ARGV[4], "finishedOn", timestamp)
740
743
  -- "returnvalue" / "failedReason" and "finishedOn"
744
+ if ARGV[5] == "failed" then
745
+ rcall("HDEL", jobIdKey, "defa")
746
+ end
741
747
  -- Remove old jobs?
742
748
  if maxAge ~= nil then
743
749
  removeJobsByMaxAge(timestamp, maxAge, targetSet, prefix)
@@ -1 +1 @@
1
- {"version":3,"file":"moveToFinished-14.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-14.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8zBf,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAo0Bf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
@@ -36,12 +36,19 @@ local jobId = ARGV[4]
36
36
  Function to recursively move from waitingChildren to failed.
37
37
  ]]
38
38
  -- Includes
39
+ --[[
40
+ Validate and move parent to a wait status (waiting, delayed or prioritized)
41
+ if no pending dependencies.
42
+ ]]
43
+ -- Includes
39
44
  --[[
40
45
  Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
41
46
  ]]
47
+ -- Includes
42
48
  --[[
43
- Validate and move parent to a wait status (wait, prioritized or delayed)
49
+ Move parent to a wait status (wait, prioritized or delayed)
44
50
  ]]
51
+ -- Includes
45
52
  --[[
46
53
  Add delay marker if needed.
47
54
  ]]
@@ -136,46 +143,53 @@ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
136
143
  return waitKey, false
137
144
  end
138
145
  local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
139
- local isParentWaitingChildren = rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
140
- if isParentWaitingChildren > 0 then
141
- local parentWaitKey = parentQueueKey .. ":wait"
142
- local parentPausedKey = parentQueueKey .. ":paused"
143
- local parentActiveKey = parentQueueKey .. ":active"
144
- local parentMetaKey = parentQueueKey .. ":meta"
145
- local parentMarkerKey = parentQueueKey .. ":marker"
146
- local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
147
- local priority = tonumber(jobAttributes[1]) or 0
148
- local delay = tonumber(jobAttributes[2]) or 0
149
- -- ignore dependencies if any left
150
- rcall("HSET", parentKey, "igdp", 1)
151
- if delay > 0 then
152
- local delayedTimestamp = tonumber(timestamp) + delay
153
- local score = delayedTimestamp * 0x1000
154
- local parentDelayedKey = parentQueueKey .. ":delayed"
155
- rcall("ZADD", parentDelayedKey, score, parentId)
156
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
157
- delayedTimestamp)
158
- addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
146
+ local parentWaitKey = parentQueueKey .. ":wait"
147
+ local parentPausedKey = parentQueueKey .. ":paused"
148
+ local parentActiveKey = parentQueueKey .. ":active"
149
+ local parentMetaKey = parentQueueKey .. ":meta"
150
+ local parentMarkerKey = parentQueueKey .. ":marker"
151
+ local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
152
+ local priority = tonumber(jobAttributes[1]) or 0
153
+ local delay = tonumber(jobAttributes[2]) or 0
154
+ -- ignore dependencies if any left
155
+ rcall("HSET", parentKey, "igdp", 1)
156
+ if delay > 0 then
157
+ local delayedTimestamp = tonumber(timestamp) + delay
158
+ local score = delayedTimestamp * 0x1000
159
+ local parentDelayedKey = parentQueueKey .. ":delayed"
160
+ rcall("ZADD", parentDelayedKey, score, parentId)
161
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
162
+ delayedTimestamp)
163
+ addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
164
+ else
165
+ if priority == 0 then
166
+ local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
167
+ parentWaitKey, parentPausedKey)
168
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
159
169
  else
160
- if priority == 0 then
161
- local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
162
- parentWaitKey, parentPausedKey)
163
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
164
- else
165
- local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
166
- addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
167
- parentQueueKey .. ":pc", isPausedOrMaxed)
168
- end
169
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
170
- "waiting-children")
170
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
171
+ addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
172
+ parentQueueKey .. ":pc", isPausedOrMaxed)
171
173
  end
174
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
175
+ "waiting-children")
172
176
  end
173
177
  end
174
- local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
175
- local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
176
- if doNotHavePendingDependencies then
177
- moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
178
+ local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
179
+ if rcall("EXISTS", parentKey) == 1 then
180
+ local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
181
+ if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
182
+ rcall("ZREM", parentWaitingChildrenKey, parentId)
183
+ moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
178
184
  end
185
+ end
186
+ end
187
+ local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
188
+ parentId, timestamp)
189
+ local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
190
+ if doNotHavePendingDependencies then
191
+ moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
192
+ end
179
193
  end
180
194
  --[[
181
195
  Function to remove deduplication key if needed.
@@ -366,38 +380,27 @@ moveParentToFailedIfNeeded = function (parentQueueKey, parentKey, parentId, jobI
366
380
  local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
367
381
  local parentDelayedKey = parentQueueKey .. ":delayed"
368
382
  local parentPrioritizedKey = parentQueueKey .. ":prioritized"
369
- local parentWaitingChildrenOrDelayedOrPrioritizedKey
383
+ local parentWaitingChildrenOrDelayedKey
370
384
  local prevState
371
385
  if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
372
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentWaitingChildrenKey
386
+ parentWaitingChildrenOrDelayedKey = parentWaitingChildrenKey
373
387
  prevState = "waiting-children"
374
388
  elseif rcall("ZSCORE", parentDelayedKey, parentId) then
375
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentDelayedKey
389
+ parentWaitingChildrenOrDelayedKey = parentDelayedKey
376
390
  prevState = "delayed"
377
- elseif rcall("ZSCORE", parentPrioritizedKey, parentId) then
378
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
379
- prevState = "prioritized"
391
+ rcall("HSET", parentKey, "delay", 0)
380
392
  end
381
- if parentWaitingChildrenOrDelayedOrPrioritizedKey then
382
- rcall("ZREM", parentWaitingChildrenOrDelayedOrPrioritizedKey, parentId)
393
+ if parentWaitingChildrenOrDelayedKey then
394
+ rcall("ZREM", parentWaitingChildrenOrDelayedKey, parentId)
383
395
  local parentQueuePrefix = parentQueueKey .. ":"
384
396
  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
- moveChildFromDependenciesIfNeeded(jobAttributes[1], parentKey, failedReason, timestamp)
393
- local parentRawOpts = jobAttributes[3]
394
- local parentOpts = cjson.decode(parentRawOpts)
395
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
397
+ local deferredFailure = "child " .. jobIdKey .. " failed"
398
+ rcall("HSET", parentKey, "defa", deferredFailure)
399
+ moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
396
400
  else
397
- local grandParentKey = rcall("HGET", parentKey, "parentKey")
398
- if grandParentKey then
399
- local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
400
- rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
401
+ if not rcall("ZSCORE", parentQueueKey .. ":failed", parentId) then
402
+ local deferredFailure = "child " .. jobIdKey .. " failed"
403
+ rcall("HSET", parentKey, "defa", deferredFailure)
401
404
  end
402
405
  end
403
406
  end
@@ -423,11 +426,11 @@ moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, failedRea
423
426
  if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
424
427
  local parentFailedChildrenKey = parentKey .. ":failed"
425
428
  rcall("HSET", parentFailedChildrenKey, childKey, failedReason)
426
- moveParentToWait(parentData['queueKey'], parentKey, parentData['id'], timestamp)
429
+ moveParentToWaitIfNeeded(parentData['queueKey'], parentKey, parentData['id'], timestamp)
427
430
  end
428
431
  elseif parentData['idof'] or parentData['rdof'] then
429
432
  if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
430
- moveParentToWaitIfNeeded(parentData['queueKey'], parentDependenciesChildrenKey,
433
+ moveParentToWaitIfNoPendingDependencies(parentData['queueKey'], parentDependenciesChildrenKey,
431
434
  parentKey, parentData['id'], timestamp)
432
435
  if parentData['idof'] then
433
436
  local parentFailedChildrenKey = parentKey .. ":failed"
@@ -1 +1 @@
1
- {"version":3,"file":"moveToWaitingChildren-8.js","sourceRoot":"","sources":["../../../src/scripts/moveToWaitingChildren-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2ff,CAAC;AACF,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"moveToWaitingChildren-8.js","sourceRoot":"","sources":["../../../src/scripts/moveToWaitingChildren-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8ff,CAAC;AACF,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}