bullmq 5.46.1 → 5.47.1

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 (77) hide show
  1. package/dist/cjs/classes/flow-producer.js +1 -1
  2. package/dist/cjs/classes/flow-producer.js.map +1 -1
  3. package/dist/cjs/classes/job.js +11 -9
  4. package/dist/cjs/classes/job.js.map +1 -1
  5. package/dist/cjs/classes/scripts.js +4 -3
  6. package/dist/cjs/classes/scripts.js.map +1 -1
  7. package/dist/cjs/classes/worker.js.map +1 -1
  8. package/dist/cjs/commands/includes/moveParentToFailedIfNeeded.lua +3 -0
  9. package/dist/cjs/commands/includes/moveParentToWait.lua +49 -0
  10. package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +6 -51
  11. package/dist/cjs/commands/includes/removeParentDependencyKey.lua +5 -5
  12. package/dist/cjs/commands/moveStalledJobsToWait-9.lua +26 -30
  13. package/dist/cjs/commands/moveToFinished-14.lua +38 -30
  14. package/dist/cjs/commands/moveToWaitingChildren-8.lua +13 -8
  15. package/dist/cjs/scripts/addDelayedJob-6.js +24 -20
  16. package/dist/cjs/scripts/addDelayedJob-6.js.map +1 -1
  17. package/dist/cjs/scripts/addJobScheduler-11.js +5 -5
  18. package/dist/cjs/scripts/addParentJob-4.js +24 -20
  19. package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
  20. package/dist/cjs/scripts/addPrioritizedJob-8.js +24 -20
  21. package/dist/cjs/scripts/addPrioritizedJob-8.js.map +1 -1
  22. package/dist/cjs/scripts/addRepeatableJob-2.js +5 -5
  23. package/dist/cjs/scripts/addStandardJob-8.js +24 -20
  24. package/dist/cjs/scripts/addStandardJob-8.js.map +1 -1
  25. package/dist/cjs/scripts/cleanJobsInSet-3.js +5 -5
  26. package/dist/cjs/scripts/drain-5.js +5 -5
  27. package/dist/cjs/scripts/moveStalledJobsToWait-9.js +56 -54
  28. package/dist/cjs/scripts/moveStalledJobsToWait-9.js.map +1 -1
  29. package/dist/cjs/scripts/moveToFinished-14.js +67 -55
  30. package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
  31. package/dist/cjs/scripts/moveToWaitingChildren-8.js +43 -33
  32. package/dist/cjs/scripts/moveToWaitingChildren-8.js.map +1 -1
  33. package/dist/cjs/scripts/obliterate-2.js +5 -5
  34. package/dist/cjs/scripts/removeChildDependency-1.js +5 -5
  35. package/dist/cjs/scripts/removeJob-3.js +5 -5
  36. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  37. package/dist/cjs/version.js +1 -1
  38. package/dist/esm/classes/flow-producer.js +1 -1
  39. package/dist/esm/classes/flow-producer.js.map +1 -1
  40. package/dist/esm/classes/job.js +11 -9
  41. package/dist/esm/classes/job.js.map +1 -1
  42. package/dist/esm/classes/scripts.js +4 -3
  43. package/dist/esm/classes/scripts.js.map +1 -1
  44. package/dist/esm/classes/worker.js.map +1 -1
  45. package/dist/esm/commands/includes/moveParentToFailedIfNeeded.lua +3 -0
  46. package/dist/esm/commands/includes/moveParentToWait.lua +49 -0
  47. package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +6 -51
  48. package/dist/esm/commands/includes/removeParentDependencyKey.lua +5 -5
  49. package/dist/esm/commands/moveStalledJobsToWait-9.lua +26 -30
  50. package/dist/esm/commands/moveToFinished-14.lua +38 -30
  51. package/dist/esm/commands/moveToWaitingChildren-8.lua +13 -8
  52. package/dist/esm/scripts/addDelayedJob-6.js +24 -20
  53. package/dist/esm/scripts/addDelayedJob-6.js.map +1 -1
  54. package/dist/esm/scripts/addJobScheduler-11.js +5 -5
  55. package/dist/esm/scripts/addParentJob-4.js +24 -20
  56. package/dist/esm/scripts/addParentJob-4.js.map +1 -1
  57. package/dist/esm/scripts/addPrioritizedJob-8.js +24 -20
  58. package/dist/esm/scripts/addPrioritizedJob-8.js.map +1 -1
  59. package/dist/esm/scripts/addRepeatableJob-2.js +5 -5
  60. package/dist/esm/scripts/addStandardJob-8.js +24 -20
  61. package/dist/esm/scripts/addStandardJob-8.js.map +1 -1
  62. package/dist/esm/scripts/cleanJobsInSet-3.js +5 -5
  63. package/dist/esm/scripts/drain-5.js +5 -5
  64. package/dist/esm/scripts/moveStalledJobsToWait-9.js +56 -54
  65. package/dist/esm/scripts/moveStalledJobsToWait-9.js.map +1 -1
  66. package/dist/esm/scripts/moveToFinished-14.js +67 -55
  67. package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
  68. package/dist/esm/scripts/moveToWaitingChildren-8.js +43 -33
  69. package/dist/esm/scripts/moveToWaitingChildren-8.js.map +1 -1
  70. package/dist/esm/scripts/obliterate-2.js +5 -5
  71. package/dist/esm/scripts/removeChildDependency-1.js +5 -5
  72. package/dist/esm/scripts/removeJob-3.js +5 -5
  73. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  74. package/dist/esm/types/job-options.d.ts +12 -1
  75. package/dist/esm/version.d.ts +1 -1
  76. package/dist/esm/version.js +1 -1
  77. package/package.json +1 -1
@@ -37,6 +37,7 @@ const content = `--[[
37
37
  opts - attempts max attempts
38
38
  opts - maxMetricsSize
39
39
  opts - fpof - fail parent on fail
40
+ opts - cpof - continue parent on fail
40
41
  opts - idof - ignore dependency on fail
41
42
  opts - rdof - remove dependency on fail
42
43
  opts - name - worker name
@@ -170,9 +171,11 @@ end
170
171
  ]]
171
172
  -- Includes
172
173
  --[[
173
- Validate and move parent to active if needed.
174
+ Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
175
+ ]]
176
+ --[[
177
+ Validate and move parent to a wait status (wait, prioritized or delayed)
174
178
  ]]
175
- -- Includes
176
179
  --[[
177
180
  Add delay marker if needed.
178
181
  ]]
@@ -234,12 +237,9 @@ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
234
237
  end
235
238
  return false
236
239
  end
237
- local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
238
- parentKey, parentId, timestamp)
239
- local isParentActive = rcall("ZSCORE",
240
- parentQueueKey .. ":waiting-children", parentId)
241
- if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
242
- rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
240
+ local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
241
+ local isParentWaitingChildren = rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
242
+ if isParentWaitingChildren > 0 then
243
243
  local parentWaitKey = parentQueueKey .. ":wait"
244
244
  local parentPausedKey = parentQueueKey .. ":paused"
245
245
  local parentActiveKey = parentQueueKey .. ":active"
@@ -248,32 +248,37 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
248
248
  local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
249
249
  local priority = tonumber(jobAttributes[1]) or 0
250
250
  local delay = tonumber(jobAttributes[2]) or 0
251
+ -- ignore dependencies if any left
252
+ rcall("HSET", parentKey, "igdp", 1)
251
253
  if delay > 0 then
252
254
  local delayedTimestamp = tonumber(timestamp) + delay
253
255
  local score = delayedTimestamp * 0x1000
254
256
  local parentDelayedKey = parentQueueKey .. ":delayed"
255
257
  rcall("ZADD", parentDelayedKey, score, parentId)
256
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed",
257
- "jobId", parentId, "delay", delayedTimestamp)
258
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
259
+ delayedTimestamp)
258
260
  addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
259
261
  else
260
262
  if priority == 0 then
261
- local parentTarget, isParentPausedOrMaxed =
262
- getTargetQueueList(parentMetaKey, parentActiveKey, parentWaitKey,
263
- parentPausedKey)
264
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed,
265
- parentId)
263
+ local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
264
+ parentWaitKey, parentPausedKey)
265
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
266
266
  else
267
267
  local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
268
- addJobWithPriority(parentMarkerKey,
269
- parentQueueKey .. ":prioritized", priority,
270
- parentId, parentQueueKey .. ":pc", isPausedOrMaxed)
268
+ addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
269
+ parentQueueKey .. ":pc", isPausedOrMaxed)
271
270
  end
272
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
273
- "jobId", parentId, "prev", "waiting-children")
271
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
272
+ "waiting-children")
274
273
  end
275
274
  end
276
275
  end
276
+ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
277
+ local hasPendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
278
+ if hasPendingDependencies then
279
+ moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
280
+ end
281
+ end
277
282
  --[[
278
283
  Function to remove deduplication key if needed.
279
284
  ]]
@@ -327,7 +332,7 @@ end
327
332
  local getJobKeyPrefix = function (jobKey, jobId)
328
333
  return string.sub(jobKey, 0, #jobKey - #jobId)
329
334
  end
330
- local function moveParentToWait(parentPrefix, parentId, emitEvent)
335
+ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
331
336
  local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
332
337
  parentPrefix .. "wait", parentPrefix .. "paused")
333
338
  addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
@@ -355,10 +360,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
355
360
  rcall("DEL", parentPrefix .. "de:" .. debounceId)
356
361
  end
357
362
  else
358
- moveParentToWait(parentPrefix, parentId)
363
+ _moveParentToWait(parentPrefix, parentId)
359
364
  end
360
365
  else
361
- moveParentToWait(parentPrefix, parentId, true)
366
+ _moveParentToWait(parentPrefix, parentId, true)
362
367
  end
363
368
  end
364
369
  end
@@ -386,10 +391,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
386
391
  rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
387
392
  end
388
393
  else
389
- moveParentToWait(parentPrefix, parentId)
394
+ _moveParentToWait(parentPrefix, parentId)
390
395
  end
391
396
  else
392
- moveParentToWait(parentPrefix, parentId, true)
397
+ _moveParentToWait(parentPrefix, parentId, true)
393
398
  end
394
399
  end
395
400
  end
@@ -497,6 +502,8 @@ local function moveParentToFailedIfNeeded(parentQueueKey, parentKey, parentId, j
497
502
  parentKey,
498
503
  timestamp
499
504
  )
505
+ elseif parentData['cpof'] then
506
+ moveParentToWait(parentData['queueKey'], parentKey, parentData['id'], timestamp)
500
507
  elseif parentData['idof'] or parentData['rdof'] then
501
508
  local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
502
509
  local grandParentDependenciesSet = grandParentKey .. ":dependencies"
@@ -658,7 +665,9 @@ local jobIdKey = KEYS[12]
658
665
  if rcall("EXISTS", jobIdKey) == 1 then -- Make sure job exists
659
666
  -- Make sure it does not have pending dependencies
660
667
  -- It must happen before removing lock
661
- if ARGV[5] == "completed" and rcall("SCARD", jobIdKey .. ":dependencies") ~= 0 then
668
+ if ARGV[5] == "completed" and
669
+ not rcall("HGET", jobIdKey, "igdp") and -- check if we should ignore this check
670
+ rcall("SCARD", jobIdKey .. ":dependencies") ~= 0 then
662
671
  return -4
663
672
  end
664
673
  local opts = cmsgpack.unpack(ARGV[8])
@@ -685,7 +694,9 @@ if rcall("EXISTS", jobIdKey) == 1 then -- Make sure job exists
685
694
  local timestamp = ARGV[2]
686
695
  -- Remove from active list (if not active we shall return error)
687
696
  local numRemovedElements = rcall("LREM", KEYS[2], -1, jobId)
688
- if (numRemovedElements < 1) then return -3 end
697
+ if (numRemovedElements < 1) then
698
+ return -3
699
+ end
689
700
  local eventStreamKey = KEYS[4]
690
701
  local metaKey = KEYS[9]
691
702
  -- Trim events before emiting them to avoid trimming events emitted in this script
@@ -705,22 +716,24 @@ if rcall("EXISTS", jobIdKey) == 1 then -- Make sure job exists
705
716
  if ARGV[5] == "completed" then
706
717
  local dependenciesSet = parentKey .. ":dependencies"
707
718
  if rcall("SREM", dependenciesSet, jobIdKey) == 1 then
708
- updateParentDepsIfNeeded(parentKey, parentQueueKey,
709
- dependenciesSet, parentId, jobIdKey,
710
- ARGV[4], timestamp)
719
+ updateParentDepsIfNeeded(parentKey, parentQueueKey, dependenciesSet, parentId, jobIdKey, ARGV[4],
720
+ timestamp)
711
721
  end
712
722
  else
713
- if opts['fpof'] then
723
+ if opts['fpof'] or opts['cpof'] then
714
724
  local unsuccesssfulSet = parentKey .. ":unsuccessful"
715
725
  rcall("ZADD", unsuccesssfulSet, timestamp, jobIdKey)
716
- moveParentToFailedIfNeeded(parentQueueKey, parentKey,
717
- parentId, jobIdKey,
718
- timestamp)
726
+ if opts['fpof'] then
727
+ moveParentToFailedIfNeeded(parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
728
+ elseif opts['cpof'] then
729
+ local failedSet = parentKey .. ":failed"
730
+ rcall("HSET", failedSet, jobIdKey, ARGV[4])
731
+ moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
732
+ end
719
733
  elseif opts['idof'] or opts['rdof'] then
720
734
  local dependenciesSet = parentKey .. ":dependencies"
721
735
  if rcall("SREM", dependenciesSet, jobIdKey) == 1 then
722
- moveParentToWaitIfNeeded(parentQueueKey, dependenciesSet,
723
- parentKey, parentId, timestamp)
736
+ moveParentToWaitIfNeeded(parentQueueKey, dependenciesSet, parentKey, parentId, timestamp)
724
737
  if opts['idof'] then
725
738
  local failedSet = parentKey .. ":failed"
726
739
  rcall("HSET", failedSet, jobIdKey, ARGV[4])
@@ -753,12 +766,11 @@ if rcall("EXISTS", jobIdKey) == 1 then -- Make sure job exists
753
766
  removeParentDependencyKey(jobIdKey, false, parentKey, jobAttributes[3])
754
767
  end
755
768
  end
756
- rcall("XADD", eventStreamKey, "*", "event", ARGV[5], "jobId", jobId, ARGV[3],
757
- ARGV[4], "prev", "active")
769
+ rcall("XADD", eventStreamKey, "*", "event", ARGV[5], "jobId", jobId, ARGV[3], ARGV[4], "prev", "active")
758
770
  if ARGV[5] == "failed" then
759
771
  if tonumber(attemptsMade) >= tonumber(attempts) then
760
- rcall("XADD", eventStreamKey, "*", "event", "retries-exhausted", "jobId",
761
- jobId, "attemptsMade", attemptsMade)
772
+ rcall("XADD", eventStreamKey, "*", "event", "retries-exhausted", "jobId", jobId, "attemptsMade",
773
+ attemptsMade)
762
774
  end
763
775
  end
764
776
  -- Collect metrics
@@ -771,14 +783,18 @@ if rcall("EXISTS", jobIdKey) == 1 then -- Make sure job exists
771
783
  local target, isPausedOrMaxed = getTargetQueueList(metaKey, KEYS[2], KEYS[1], KEYS[8])
772
784
  local markerKey = KEYS[14]
773
785
  -- Check if there are delayed jobs that can be promoted
774
- promoteDelayedJobs(KEYS[7], markerKey, target, KEYS[3], eventStreamKey, prefix,
775
- timestamp, KEYS[10], isPausedOrMaxed)
786
+ promoteDelayedJobs(KEYS[7], markerKey, target, KEYS[3], eventStreamKey, prefix, timestamp, KEYS[10],
787
+ isPausedOrMaxed)
776
788
  local maxJobs = tonumber(opts['limiter'] and opts['limiter']['max'])
777
789
  -- Check if we are rate limited first.
778
790
  local expireTime = getRateLimitTTL(maxJobs, KEYS[6])
779
- if expireTime > 0 then return {0, 0, expireTime, 0} end
791
+ if expireTime > 0 then
792
+ return {0, 0, expireTime, 0}
793
+ end
780
794
  -- paused or maxed queue
781
- if isPausedOrMaxed then return {0, 0, 0, 0} end
795
+ if isPausedOrMaxed then
796
+ return {0, 0, 0, 0}
797
+ end
782
798
  jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
783
799
  if jobId then
784
800
  -- Markers in waitlist DEPRECATED in v5: Remove in v6.
@@ -787,23 +803,19 @@ if rcall("EXISTS", jobIdKey) == 1 then -- Make sure job exists
787
803
  -- If jobId is special ID 0:delay (delay greater than 0), then there is no job to process
788
804
  -- but if ID is 0:0, then there is at least 1 prioritized job to process
789
805
  if jobId == "0:0" then
790
- jobId = moveJobFromPriorityToActive(KEYS[3], KEYS[2],
791
- KEYS[10])
792
- return prepareJobForProcessing(prefix, KEYS[6], eventStreamKey, jobId,
793
- timestamp, maxJobs, markerKey,
794
- opts)
806
+ jobId = moveJobFromPriorityToActive(KEYS[3], KEYS[2], KEYS[10])
807
+ return prepareJobForProcessing(prefix, KEYS[6], eventStreamKey, jobId, timestamp, maxJobs,
808
+ markerKey, opts)
795
809
  end
796
810
  else
797
- return prepareJobForProcessing(prefix, KEYS[6], eventStreamKey, jobId,
798
- timestamp, maxJobs, markerKey,
799
- opts)
811
+ return prepareJobForProcessing(prefix, KEYS[6], eventStreamKey, jobId, timestamp, maxJobs, markerKey,
812
+ opts)
800
813
  end
801
814
  else
802
815
  jobId = moveJobFromPriorityToActive(KEYS[3], KEYS[2], KEYS[10])
803
816
  if jobId then
804
- return prepareJobForProcessing(prefix, KEYS[6], eventStreamKey, jobId,
805
- timestamp, maxJobs, markerKey,
806
- opts)
817
+ return prepareJobForProcessing(prefix, KEYS[6], eventStreamKey, jobId, timestamp, maxJobs, markerKey,
818
+ opts)
807
819
  end
808
820
  end
809
821
  -- Return the timestamp for the next delayed job if any.
@@ -1 +1 @@
1
- {"version":3,"file":"moveToFinished-14.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-14.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2zBf,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAu0Bf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
@@ -40,9 +40,11 @@ local jobId = ARGV[4]
40
40
  ]]
41
41
  -- Includes
42
42
  --[[
43
- Validate and move parent to active if needed.
43
+ Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
44
+ ]]
45
+ --[[
46
+ Validate and move parent to a wait status (wait, prioritized or delayed)
44
47
  ]]
45
- -- Includes
46
48
  --[[
47
49
  Add delay marker if needed.
48
50
  ]]
@@ -136,12 +138,9 @@ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
136
138
  end
137
139
  return waitKey, false
138
140
  end
139
- local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
140
- parentKey, parentId, timestamp)
141
- local isParentActive = rcall("ZSCORE",
142
- parentQueueKey .. ":waiting-children", parentId)
143
- if isParentActive and rcall("SCARD", parentDependenciesKey) == 0 then
144
- rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
141
+ local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
142
+ local isParentWaitingChildren = rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
143
+ if isParentWaitingChildren > 0 then
145
144
  local parentWaitKey = parentQueueKey .. ":wait"
146
145
  local parentPausedKey = parentQueueKey .. ":paused"
147
146
  local parentActiveKey = parentQueueKey .. ":active"
@@ -150,32 +149,37 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
150
149
  local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
151
150
  local priority = tonumber(jobAttributes[1]) or 0
152
151
  local delay = tonumber(jobAttributes[2]) or 0
152
+ -- ignore dependencies if any left
153
+ rcall("HSET", parentKey, "igdp", 1)
153
154
  if delay > 0 then
154
155
  local delayedTimestamp = tonumber(timestamp) + delay
155
156
  local score = delayedTimestamp * 0x1000
156
157
  local parentDelayedKey = parentQueueKey .. ":delayed"
157
158
  rcall("ZADD", parentDelayedKey, score, parentId)
158
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed",
159
- "jobId", parentId, "delay", delayedTimestamp)
159
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
160
+ delayedTimestamp)
160
161
  addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
161
162
  else
162
163
  if priority == 0 then
163
- local parentTarget, isParentPausedOrMaxed =
164
- getTargetQueueList(parentMetaKey, parentActiveKey, parentWaitKey,
165
- parentPausedKey)
166
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed,
167
- parentId)
164
+ local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
165
+ parentWaitKey, parentPausedKey)
166
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
168
167
  else
169
168
  local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
170
- addJobWithPriority(parentMarkerKey,
171
- parentQueueKey .. ":prioritized", priority,
172
- parentId, parentQueueKey .. ":pc", isPausedOrMaxed)
169
+ addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
170
+ parentQueueKey .. ":pc", isPausedOrMaxed)
173
171
  end
174
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
175
- "jobId", parentId, "prev", "waiting-children")
172
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
173
+ "waiting-children")
176
174
  end
177
175
  end
178
176
  end
177
+ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
178
+ local hasPendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
179
+ if hasPendingDependencies then
180
+ moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
181
+ end
182
+ end
179
183
  --[[
180
184
  Function to remove deduplication key if needed.
181
185
  ]]
@@ -229,7 +233,7 @@ end
229
233
  local getJobKeyPrefix = function (jobKey, jobId)
230
234
  return string.sub(jobKey, 0, #jobKey - #jobId)
231
235
  end
232
- local function moveParentToWait(parentPrefix, parentId, emitEvent)
236
+ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
233
237
  local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
234
238
  parentPrefix .. "wait", parentPrefix .. "paused")
235
239
  addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
@@ -257,10 +261,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
257
261
  rcall("DEL", parentPrefix .. "de:" .. debounceId)
258
262
  end
259
263
  else
260
- moveParentToWait(parentPrefix, parentId)
264
+ _moveParentToWait(parentPrefix, parentId)
261
265
  end
262
266
  else
263
- moveParentToWait(parentPrefix, parentId, true)
267
+ _moveParentToWait(parentPrefix, parentId, true)
264
268
  end
265
269
  end
266
270
  end
@@ -288,10 +292,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
288
292
  rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
289
293
  end
290
294
  else
291
- moveParentToWait(parentPrefix, parentId)
295
+ _moveParentToWait(parentPrefix, parentId)
292
296
  end
293
297
  else
294
- moveParentToWait(parentPrefix, parentId, true)
298
+ _moveParentToWait(parentPrefix, parentId, true)
295
299
  end
296
300
  end
297
301
  end
@@ -399,6 +403,8 @@ local function moveParentToFailedIfNeeded(parentQueueKey, parentKey, parentId, j
399
403
  parentKey,
400
404
  timestamp
401
405
  )
406
+ elseif parentData['cpof'] then
407
+ moveParentToWait(parentData['queueKey'], parentKey, parentData['id'], timestamp)
402
408
  elseif parentData['idof'] or parentData['rdof'] then
403
409
  local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
404
410
  local grandParentDependenciesSet = grandParentKey .. ":dependencies"
@@ -467,18 +473,22 @@ if rcall("EXISTS", jobKey) == 1 then
467
473
  local rawOpts = jobAttributes[3]
468
474
  local opts = cjson.decode(rawOpts)
469
475
  if rawParentData ~= false then
470
- if opts['fpof'] then
476
+ if opts['fpof'] or opts['cpof'] then
471
477
  local parentData = cjson.decode(rawParentData)
472
478
  local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
473
479
  local parentUnsuccesssful = parentKey .. ":unsuccessful"
474
480
  rcall("ZADD", parentUnsuccesssful, timestamp, jobKey)
475
- moveParentToFailedIfNeeded(
476
- parentData['queueKey'],
477
- parentData['queueKey'] .. ':' .. parentData['id'],
478
- parentData['id'],
479
- jobKey,
480
- timestamp
481
- )
481
+ if opts['fpof'] then
482
+ moveParentToFailedIfNeeded(
483
+ parentData['queueKey'],
484
+ parentData['queueKey'] .. ':' .. parentData['id'],
485
+ parentData['id'],
486
+ jobKey,
487
+ timestamp
488
+ )
489
+ elseif opts['cpof'] then
490
+ moveParentToWait(parentData['queueKey'], parentKey, parentData['id'], timestamp)
491
+ end
482
492
  elseif opts['idof'] or opts['rdof'] then
483
493
  local parentData = cjson.decode(rawParentData)
484
494
  local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
@@ -1 +1 @@
1
- {"version":3,"file":"moveToWaitingChildren-8.js","sourceRoot":"","sources":["../../../src/scripts/moveToWaitingChildren-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqgBf,CAAC;AACW,QAAA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+gBf,CAAC;AACW,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -96,7 +96,7 @@ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
96
96
  end
97
97
  return waitKey, false
98
98
  end
99
- local function moveParentToWait(parentPrefix, parentId, emitEvent)
99
+ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
100
100
  local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
101
101
  parentPrefix .. "wait", parentPrefix .. "paused")
102
102
  addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
@@ -124,10 +124,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
124
124
  rcall("DEL", parentPrefix .. "de:" .. debounceId)
125
125
  end
126
126
  else
127
- moveParentToWait(parentPrefix, parentId)
127
+ _moveParentToWait(parentPrefix, parentId)
128
128
  end
129
129
  else
130
- moveParentToWait(parentPrefix, parentId, true)
130
+ _moveParentToWait(parentPrefix, parentId, true)
131
131
  end
132
132
  end
133
133
  end
@@ -155,10 +155,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
155
155
  rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
156
156
  end
157
157
  else
158
- moveParentToWait(parentPrefix, parentId)
158
+ _moveParentToWait(parentPrefix, parentId)
159
159
  end
160
160
  else
161
- moveParentToWait(parentPrefix, parentId, true)
161
+ _moveParentToWait(parentPrefix, parentId, true)
162
162
  end
163
163
  end
164
164
  end
@@ -77,7 +77,7 @@ local function removeJobKeys(jobKey)
77
77
  return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
78
78
  jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
79
79
  end
80
- local function moveParentToWait(parentPrefix, parentId, emitEvent)
80
+ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
81
81
  local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
82
82
  parentPrefix .. "wait", parentPrefix .. "paused")
83
83
  addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
@@ -105,10 +105,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
105
105
  rcall("DEL", parentPrefix .. "de:" .. debounceId)
106
106
  end
107
107
  else
108
- moveParentToWait(parentPrefix, parentId)
108
+ _moveParentToWait(parentPrefix, parentId)
109
109
  end
110
110
  else
111
- moveParentToWait(parentPrefix, parentId, true)
111
+ _moveParentToWait(parentPrefix, parentId, true)
112
112
  end
113
113
  end
114
114
  end
@@ -136,10 +136,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
136
136
  rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
137
137
  end
138
138
  else
139
- moveParentToWait(parentPrefix, parentId)
139
+ _moveParentToWait(parentPrefix, parentId)
140
140
  end
141
141
  else
142
- moveParentToWait(parentPrefix, parentId, true)
142
+ _moveParentToWait(parentPrefix, parentId, true)
143
143
  end
144
144
  end
145
145
  end
@@ -172,7 +172,7 @@ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
172
172
  end
173
173
  return waitKey, false
174
174
  end
175
- local function moveParentToWait(parentPrefix, parentId, emitEvent)
175
+ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
176
176
  local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
177
177
  parentPrefix .. "wait", parentPrefix .. "paused")
178
178
  addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
@@ -200,10 +200,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
200
200
  rcall("DEL", parentPrefix .. "de:" .. debounceId)
201
201
  end
202
202
  else
203
- moveParentToWait(parentPrefix, parentId)
203
+ _moveParentToWait(parentPrefix, parentId)
204
204
  end
205
205
  else
206
- moveParentToWait(parentPrefix, parentId, true)
206
+ _moveParentToWait(parentPrefix, parentId, true)
207
207
  end
208
208
  end
209
209
  end
@@ -231,10 +231,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
231
231
  rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
232
232
  end
233
233
  else
234
- moveParentToWait(parentPrefix, parentId)
234
+ _moveParentToWait(parentPrefix, parentId)
235
235
  end
236
236
  else
237
- moveParentToWait(parentPrefix, parentId, true)
237
+ _moveParentToWait(parentPrefix, parentId, true)
238
238
  end
239
239
  end
240
240
  end