bullmq 5.49.1 → 5.50.0

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 (110) hide show
  1. package/dist/cjs/classes/job.js +23 -18
  2. package/dist/cjs/classes/job.js.map +1 -1
  3. package/dist/cjs/classes/queue.js +0 -1
  4. package/dist/cjs/classes/queue.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 -32
  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/removeDeduplicationKeyIfNeededOnFinalization.lua +23 -0
  12. package/dist/cjs/commands/includes/removeDeduplicationKeyIfNeededOnRemoval.lua +16 -0
  13. package/dist/cjs/commands/includes/removeJob.lua +2 -2
  14. package/dist/cjs/commands/includes/removeJobWithChildren.lua +2 -2
  15. package/dist/cjs/commands/includes/updateParentDepsIfNeeded.lua +2 -2
  16. package/dist/cjs/commands/moveStalledJobsToWait-9.lua +2 -4
  17. package/dist/cjs/commands/moveToFinished-14.lua +7 -5
  18. package/dist/cjs/commands/moveToWaitingChildren-8.lua +2 -4
  19. package/dist/cjs/scripts/addDelayedJob-6.js +51 -37
  20. package/dist/cjs/scripts/addDelayedJob-6.js.map +1 -1
  21. package/dist/cjs/scripts/addJobScheduler-11.js +9 -4
  22. package/dist/cjs/scripts/addJobScheduler-11.js.map +1 -1
  23. package/dist/cjs/scripts/addParentJob-4.js +51 -37
  24. package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
  25. package/dist/cjs/scripts/addPrioritizedJob-8.js +51 -37
  26. package/dist/cjs/scripts/addPrioritizedJob-8.js.map +1 -1
  27. package/dist/cjs/scripts/addRepeatableJob-2.js +9 -4
  28. package/dist/cjs/scripts/addRepeatableJob-2.js.map +1 -1
  29. package/dist/cjs/scripts/addStandardJob-8.js +51 -37
  30. package/dist/cjs/scripts/addStandardJob-8.js.map +1 -1
  31. package/dist/cjs/scripts/cleanJobsInSet-3.js +9 -4
  32. package/dist/cjs/scripts/cleanJobsInSet-3.js.map +1 -1
  33. package/dist/cjs/scripts/drain-5.js +9 -4
  34. package/dist/cjs/scripts/drain-5.js.map +1 -1
  35. package/dist/cjs/scripts/moveStalledJobsToWait-9.js +92 -76
  36. package/dist/cjs/scripts/moveStalledJobsToWait-9.js.map +1 -1
  37. package/dist/cjs/scripts/moveToFinished-14.js +97 -78
  38. package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
  39. package/dist/cjs/scripts/moveToWaitingChildren-8.js +92 -76
  40. package/dist/cjs/scripts/moveToWaitingChildren-8.js.map +1 -1
  41. package/dist/cjs/scripts/obliterate-2.js +9 -4
  42. package/dist/cjs/scripts/obliterate-2.js.map +1 -1
  43. package/dist/cjs/scripts/removeJob-3.js +9 -4
  44. package/dist/cjs/scripts/removeJob-3.js.map +1 -1
  45. package/dist/cjs/scripts/removeUnprocessedChildren-2.js +9 -4
  46. package/dist/cjs/scripts/removeUnprocessedChildren-2.js.map +1 -1
  47. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  48. package/dist/cjs/utils.js +11 -1
  49. package/dist/cjs/utils.js.map +1 -1
  50. package/dist/cjs/version.js +1 -1
  51. package/dist/esm/classes/job.d.ts +21 -4
  52. package/dist/esm/classes/job.js +24 -19
  53. package/dist/esm/classes/job.js.map +1 -1
  54. package/dist/esm/classes/queue.d.ts +0 -1
  55. package/dist/esm/classes/queue.js +0 -1
  56. package/dist/esm/classes/queue.js.map +1 -1
  57. package/dist/esm/classes/worker.js +5 -1
  58. package/dist/esm/classes/worker.js.map +1 -1
  59. package/dist/esm/commands/includes/moveChildFromDependenciesIfNeeded.lua +15 -32
  60. package/dist/esm/commands/includes/moveParentToWait.lua +32 -33
  61. package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +8 -4
  62. package/dist/esm/commands/includes/moveParentToWaitIfNoPendingDependencies.lua +13 -0
  63. package/dist/esm/commands/includes/removeDeduplicationKeyIfNeededOnFinalization.lua +23 -0
  64. package/dist/esm/commands/includes/removeDeduplicationKeyIfNeededOnRemoval.lua +16 -0
  65. package/dist/esm/commands/includes/removeJob.lua +2 -2
  66. package/dist/esm/commands/includes/removeJobWithChildren.lua +2 -2
  67. package/dist/esm/commands/includes/updateParentDepsIfNeeded.lua +2 -2
  68. package/dist/esm/commands/moveStalledJobsToWait-9.lua +2 -4
  69. package/dist/esm/commands/moveToFinished-14.lua +7 -5
  70. package/dist/esm/commands/moveToWaitingChildren-8.lua +2 -4
  71. package/dist/esm/interfaces/job-json.d.ts +1 -0
  72. package/dist/esm/scripts/addDelayedJob-6.js +51 -37
  73. package/dist/esm/scripts/addDelayedJob-6.js.map +1 -1
  74. package/dist/esm/scripts/addJobScheduler-11.js +9 -4
  75. package/dist/esm/scripts/addJobScheduler-11.js.map +1 -1
  76. package/dist/esm/scripts/addParentJob-4.js +51 -37
  77. package/dist/esm/scripts/addParentJob-4.js.map +1 -1
  78. package/dist/esm/scripts/addPrioritizedJob-8.js +51 -37
  79. package/dist/esm/scripts/addPrioritizedJob-8.js.map +1 -1
  80. package/dist/esm/scripts/addRepeatableJob-2.js +9 -4
  81. package/dist/esm/scripts/addRepeatableJob-2.js.map +1 -1
  82. package/dist/esm/scripts/addStandardJob-8.js +51 -37
  83. package/dist/esm/scripts/addStandardJob-8.js.map +1 -1
  84. package/dist/esm/scripts/cleanJobsInSet-3.js +9 -4
  85. package/dist/esm/scripts/cleanJobsInSet-3.js.map +1 -1
  86. package/dist/esm/scripts/drain-5.js +9 -4
  87. package/dist/esm/scripts/drain-5.js.map +1 -1
  88. package/dist/esm/scripts/moveStalledJobsToWait-9.js +92 -76
  89. package/dist/esm/scripts/moveStalledJobsToWait-9.js.map +1 -1
  90. package/dist/esm/scripts/moveToFinished-14.js +97 -78
  91. package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
  92. package/dist/esm/scripts/moveToWaitingChildren-8.js +92 -76
  93. package/dist/esm/scripts/moveToWaitingChildren-8.js.map +1 -1
  94. package/dist/esm/scripts/obliterate-2.js +9 -4
  95. package/dist/esm/scripts/obliterate-2.js.map +1 -1
  96. package/dist/esm/scripts/removeJob-3.js +9 -4
  97. package/dist/esm/scripts/removeJob-3.js.map +1 -1
  98. package/dist/esm/scripts/removeUnprocessedChildren-2.js +9 -4
  99. package/dist/esm/scripts/removeUnprocessedChildren-2.js.map +1 -1
  100. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  101. package/dist/esm/utils.d.ts +17 -0
  102. package/dist/esm/utils.js +10 -0
  103. package/dist/esm/utils.js.map +1 -1
  104. package/dist/esm/version.d.ts +1 -1
  105. package/dist/esm/version.js +1 -1
  106. package/package.json +1 -1
  107. package/dist/cjs/commands/includes/removeDeduplicationKey.lua +0 -11
  108. package/dist/cjs/commands/includes/removeDeduplicationKeyIfNeeded.lua +0 -14
  109. package/dist/esm/commands/includes/removeDeduplicationKey.lua +0 -11
  110. package/dist/esm/commands/includes/removeDeduplicationKeyIfNeeded.lua +0 -14
@@ -32,13 +32,18 @@ local prefixKey = ARGV[5]
32
32
  ]]
33
33
  -- Includes
34
34
  --[[
35
- Function to remove deduplication key.
35
+ Function to remove deduplication key if needed
36
+ when a job is being removed.
36
37
  ]]
37
- local function removeDeduplicationKey(prefixKey, jobKey)
38
+ local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
39
+ jobKey, jobId)
38
40
  local deduplicationId = rcall("HGET", jobKey, "deid")
39
41
  if deduplicationId then
40
42
  local deduplicationKey = prefixKey .. "de:" .. deduplicationId
41
- rcall("DEL", deduplicationKey)
43
+ local currentJobId = rcall('GET', deduplicationKey)
44
+ if currentJobId and currentJobId == jobId then
45
+ return rcall("DEL", deduplicationKey)
46
+ end
42
47
  end
43
48
  end
44
49
  --[[
@@ -176,7 +181,7 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
176
181
  local jobKey = baseKey .. jobId
177
182
  removeParentDependencyKey(jobKey, hard, nil, baseKey)
178
183
  if shouldRemoveDeduplicationKey then
179
- removeDeduplicationKey(baseKey, jobKey)
184
+ removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
180
185
  end
181
186
  removeJobKeys(jobKey)
182
187
  end
@@ -1 +1 @@
1
- {"version":3,"file":"addRepeatableJob-2.js","sourceRoot":"","sources":["../../../src/scripts/addRepeatableJob-2.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Nf,CAAC;AACW,QAAA,gBAAgB,GAAG;IAC9B,IAAI,EAAE,kBAAkB;IACxB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"addRepeatableJob-2.js","sourceRoot":"","sources":["../../../src/scripts/addRepeatableJob-2.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiOf,CAAC;AACW,QAAA,gBAAgB,GAAG;IAC9B,IAAI,EAAE,kBAAkB;IACxB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -139,12 +139,19 @@ end
139
139
  Validate and move or add dependencies to parent.
140
140
  ]]
141
141
  -- Includes
142
+ --[[
143
+ Validate and move parent to a wait status (waiting, delayed or prioritized)
144
+ if no pending dependencies.
145
+ ]]
146
+ -- Includes
142
147
  --[[
143
148
  Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
144
149
  ]]
150
+ -- Includes
145
151
  --[[
146
- Validate and move parent to a wait status (wait, prioritized or delayed)
152
+ Move parent to a wait status (wait, prioritized or delayed)
147
153
  ]]
154
+ -- Includes
148
155
  --[[
149
156
  Add delay marker if needed.
150
157
  ]]
@@ -203,52 +210,59 @@ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
203
210
  return false
204
211
  end
205
212
  local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
206
- local isParentWaitingChildren = rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
207
- if isParentWaitingChildren > 0 then
208
- local parentWaitKey = parentQueueKey .. ":wait"
209
- local parentPausedKey = parentQueueKey .. ":paused"
210
- local parentActiveKey = parentQueueKey .. ":active"
211
- local parentMetaKey = parentQueueKey .. ":meta"
212
- local parentMarkerKey = parentQueueKey .. ":marker"
213
- local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
214
- local priority = tonumber(jobAttributes[1]) or 0
215
- local delay = tonumber(jobAttributes[2]) or 0
216
- -- ignore dependencies if any left
217
- rcall("HSET", parentKey, "igdp", 1)
218
- if delay > 0 then
219
- local delayedTimestamp = tonumber(timestamp) + delay
220
- local score = delayedTimestamp * 0x1000
221
- local parentDelayedKey = parentQueueKey .. ":delayed"
222
- rcall("ZADD", parentDelayedKey, score, parentId)
223
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
224
- delayedTimestamp)
225
- addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
213
+ local parentWaitKey = parentQueueKey .. ":wait"
214
+ local parentPausedKey = parentQueueKey .. ":paused"
215
+ local parentActiveKey = parentQueueKey .. ":active"
216
+ local parentMetaKey = parentQueueKey .. ":meta"
217
+ local parentMarkerKey = parentQueueKey .. ":marker"
218
+ local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
219
+ local priority = tonumber(jobAttributes[1]) or 0
220
+ local delay = tonumber(jobAttributes[2]) or 0
221
+ -- ignore dependencies if any left
222
+ rcall("HSET", parentKey, "igdp", 1)
223
+ if delay > 0 then
224
+ local delayedTimestamp = tonumber(timestamp) + delay
225
+ local score = delayedTimestamp * 0x1000
226
+ local parentDelayedKey = parentQueueKey .. ":delayed"
227
+ rcall("ZADD", parentDelayedKey, score, parentId)
228
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
229
+ delayedTimestamp)
230
+ addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
231
+ else
232
+ if priority == 0 then
233
+ local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
234
+ parentWaitKey, parentPausedKey)
235
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
226
236
  else
227
- if priority == 0 then
228
- local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
229
- parentWaitKey, parentPausedKey)
230
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
231
- else
232
- local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
233
- addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
234
- parentQueueKey .. ":pc", isPausedOrMaxed)
235
- end
236
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
237
- "waiting-children")
237
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
238
+ addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
239
+ parentQueueKey .. ":pc", isPausedOrMaxed)
238
240
  end
241
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
242
+ "waiting-children")
239
243
  end
240
244
  end
241
- local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
242
- local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
243
- if doNotHavePendingDependencies then
244
- moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
245
+ local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
246
+ if rcall("EXISTS", parentKey) == 1 then
247
+ local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
248
+ if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
249
+ rcall("ZREM", parentWaitingChildrenKey, parentId)
250
+ moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
245
251
  end
252
+ end
253
+ end
254
+ local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
255
+ parentId, timestamp)
256
+ local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
257
+ if doNotHavePendingDependencies then
258
+ moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
259
+ end
246
260
  end
247
261
  local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
248
262
  parentId, jobIdKey, returnvalue, timestamp )
249
263
  local processedSet = parentKey .. ":processed"
250
264
  rcall("HSET", processedSet, jobIdKey, returnvalue)
251
- moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
265
+ moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
252
266
  end
253
267
  local function updateExistingJobsParent(parentKey, parent, parentData,
254
268
  parentDependenciesKey, completedKey,
@@ -1 +1 @@
1
- {"version":3,"file":"addStandardJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkWf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"addStandardJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgXf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -68,13 +68,18 @@ end
68
68
  ]]
69
69
  -- Includes
70
70
  --[[
71
- Function to remove deduplication key.
71
+ Function to remove deduplication key if needed
72
+ when a job is being removed.
72
73
  ]]
73
- local function removeDeduplicationKey(prefixKey, jobKey)
74
+ local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
75
+ jobKey, jobId)
74
76
  local deduplicationId = rcall("HGET", jobKey, "deid")
75
77
  if deduplicationId then
76
78
  local deduplicationKey = prefixKey .. "de:" .. deduplicationId
77
- rcall("DEL", deduplicationKey)
79
+ local currentJobId = rcall('GET', deduplicationKey)
80
+ if currentJobId and currentJobId == jobId then
81
+ return rcall("DEL", deduplicationKey)
82
+ end
78
83
  end
79
84
  end
80
85
  --[[
@@ -212,7 +217,7 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
212
217
  local jobKey = baseKey .. jobId
213
218
  removeParentDependencyKey(jobKey, hard, nil, baseKey)
214
219
  if shouldRemoveDeduplicationKey then
215
- removeDeduplicationKey(baseKey, jobKey)
220
+ removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
216
221
  end
217
222
  removeJobKeys(jobKey)
218
223
  end
@@ -1 +1 @@
1
- {"version":3,"file":"cleanJobsInSet-3.js","sourceRoot":"","sources":["../../../src/scripts/cleanJobsInSet-3.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Vf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"cleanJobsInSet-3.js","sourceRoot":"","sources":["../../../src/scripts/cleanJobsInSet-3.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoWf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -40,13 +40,18 @@ end
40
40
  ]]
41
41
  -- Includes
42
42
  --[[
43
- Function to remove deduplication key.
43
+ Function to remove deduplication key if needed
44
+ when a job is being removed.
44
45
  ]]
45
- local function removeDeduplicationKey(prefixKey, jobKey)
46
+ local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
47
+ jobKey, jobId)
46
48
  local deduplicationId = rcall("HGET", jobKey, "deid")
47
49
  if deduplicationId then
48
50
  local deduplicationKey = prefixKey .. "de:" .. deduplicationId
49
- rcall("DEL", deduplicationKey)
51
+ local currentJobId = rcall('GET', deduplicationKey)
52
+ if currentJobId and currentJobId == jobId then
53
+ return rcall("DEL", deduplicationKey)
54
+ end
50
55
  end
51
56
  end
52
57
  --[[
@@ -184,7 +189,7 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
184
189
  local jobKey = baseKey .. jobId
185
190
  removeParentDependencyKey(jobKey, hard, nil, baseKey)
186
191
  if shouldRemoveDeduplicationKey then
187
- removeDeduplicationKey(baseKey, jobKey)
192
+ removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
188
193
  end
189
194
  removeJobKeys(jobKey)
190
195
  end
@@ -1 +1 @@
1
- {"version":3,"file":"drain-5.js","sourceRoot":"","sources":["../../../src/scripts/drain-5.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiQf,CAAC;AACW,QAAA,KAAK,GAAG;IACnB,IAAI,EAAE,OAAO;IACb,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"drain-5.js","sourceRoot":"","sources":["../../../src/scripts/drain-5.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsQf,CAAC;AACW,QAAA,KAAK,GAAG;IACnB,IAAI,EAAE,OAAO;IACb,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -78,12 +78,19 @@ end
78
78
  Function to recursively move from waitingChildren to failed.
79
79
  ]]
80
80
  -- Includes
81
+ --[[
82
+ Validate and move parent to a wait status (waiting, delayed or prioritized)
83
+ if no pending dependencies.
84
+ ]]
85
+ -- Includes
81
86
  --[[
82
87
  Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
83
88
  ]]
89
+ -- Includes
84
90
  --[[
85
- Validate and move parent to a wait status (wait, prioritized or delayed)
91
+ Move parent to a wait status (wait, prioritized or delayed)
86
92
  ]]
93
+ -- Includes
87
94
  --[[
88
95
  Add delay marker if needed.
89
96
  ]]
@@ -142,57 +149,52 @@ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
142
149
  return false
143
150
  end
144
151
  local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
145
- local isParentWaitingChildren = rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
146
- if isParentWaitingChildren > 0 then
147
- local parentWaitKey = parentQueueKey .. ":wait"
148
- local parentPausedKey = parentQueueKey .. ":paused"
149
- local parentActiveKey = parentQueueKey .. ":active"
150
- local parentMetaKey = parentQueueKey .. ":meta"
151
- local parentMarkerKey = parentQueueKey .. ":marker"
152
- local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
153
- local priority = tonumber(jobAttributes[1]) or 0
154
- local delay = tonumber(jobAttributes[2]) or 0
155
- -- ignore dependencies if any left
156
- rcall("HSET", parentKey, "igdp", 1)
157
- if delay > 0 then
158
- local delayedTimestamp = tonumber(timestamp) + delay
159
- local score = delayedTimestamp * 0x1000
160
- local parentDelayedKey = parentQueueKey .. ":delayed"
161
- rcall("ZADD", parentDelayedKey, score, parentId)
162
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
163
- delayedTimestamp)
164
- addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
152
+ local parentWaitKey = parentQueueKey .. ":wait"
153
+ local parentPausedKey = parentQueueKey .. ":paused"
154
+ local parentActiveKey = parentQueueKey .. ":active"
155
+ local parentMetaKey = parentQueueKey .. ":meta"
156
+ local parentMarkerKey = parentQueueKey .. ":marker"
157
+ local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
158
+ local priority = tonumber(jobAttributes[1]) or 0
159
+ local delay = tonumber(jobAttributes[2]) or 0
160
+ -- ignore dependencies if any left
161
+ rcall("HSET", parentKey, "igdp", 1)
162
+ if delay > 0 then
163
+ local delayedTimestamp = tonumber(timestamp) + delay
164
+ local score = delayedTimestamp * 0x1000
165
+ local parentDelayedKey = parentQueueKey .. ":delayed"
166
+ rcall("ZADD", parentDelayedKey, score, parentId)
167
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
168
+ delayedTimestamp)
169
+ addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
170
+ else
171
+ if priority == 0 then
172
+ local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
173
+ parentWaitKey, parentPausedKey)
174
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
165
175
  else
166
- if priority == 0 then
167
- local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
168
- parentWaitKey, parentPausedKey)
169
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
170
- else
171
- local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
172
- addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
173
- parentQueueKey .. ":pc", isPausedOrMaxed)
174
- end
175
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
176
- "waiting-children")
176
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
177
+ addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
178
+ parentQueueKey .. ":pc", isPausedOrMaxed)
177
179
  end
180
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
181
+ "waiting-children")
178
182
  end
179
183
  end
180
- local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
181
- local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
182
- if doNotHavePendingDependencies then
183
- moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
184
+ local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
185
+ if rcall("EXISTS", parentKey) == 1 then
186
+ local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
187
+ if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
188
+ rcall("ZREM", parentWaitingChildrenKey, parentId)
189
+ moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
184
190
  end
191
+ end
185
192
  end
186
- --[[
187
- Function to remove deduplication key if needed.
188
- ]]
189
- local function removeDeduplicationKeyIfNeeded(prefixKey, deduplicationId)
190
- if deduplicationId then
191
- local deduplicationKey = prefixKey .. "de:" .. deduplicationId
192
- local pttl = rcall("PTTL", deduplicationKey)
193
- if pttl == 0 or pttl == -1 then
194
- rcall("DEL", deduplicationKey)
195
- end
193
+ local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
194
+ parentId, timestamp)
195
+ local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
196
+ if doNotHavePendingDependencies then
197
+ moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
196
198
  end
197
199
  end
198
200
  --[[
@@ -204,13 +206,18 @@ end
204
206
  ]]
205
207
  -- Includes
206
208
  --[[
207
- Function to remove deduplication key.
209
+ Function to remove deduplication key if needed
210
+ when a job is being removed.
208
211
  ]]
209
- local function removeDeduplicationKey(prefixKey, jobKey)
212
+ local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
213
+ jobKey, jobId)
210
214
  local deduplicationId = rcall("HGET", jobKey, "deid")
211
215
  if deduplicationId then
212
216
  local deduplicationKey = prefixKey .. "de:" .. deduplicationId
213
- rcall("DEL", deduplicationKey)
217
+ local currentJobId = rcall('GET', deduplicationKey)
218
+ if currentJobId and currentJobId == jobId then
219
+ return rcall("DEL", deduplicationKey)
220
+ end
214
221
  end
215
222
  end
216
223
  --[[
@@ -312,7 +319,7 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
312
319
  local jobKey = baseKey .. jobId
313
320
  removeParentDependencyKey(jobKey, hard, nil, baseKey)
314
321
  if shouldRemoveDeduplicationKey then
315
- removeDeduplicationKey(baseKey, jobKey)
322
+ removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
316
323
  end
317
324
  removeJobKeys(jobKey)
318
325
  end
@@ -372,38 +379,27 @@ moveParentToFailedIfNeeded = function (parentQueueKey, parentKey, parentId, jobI
372
379
  local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
373
380
  local parentDelayedKey = parentQueueKey .. ":delayed"
374
381
  local parentPrioritizedKey = parentQueueKey .. ":prioritized"
375
- local parentWaitingChildrenOrDelayedOrPrioritizedKey
382
+ local parentWaitingChildrenOrDelayedKey
376
383
  local prevState
377
384
  if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
378
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentWaitingChildrenKey
385
+ parentWaitingChildrenOrDelayedKey = parentWaitingChildrenKey
379
386
  prevState = "waiting-children"
380
387
  elseif rcall("ZSCORE", parentDelayedKey, parentId) then
381
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentDelayedKey
388
+ parentWaitingChildrenOrDelayedKey = parentDelayedKey
382
389
  prevState = "delayed"
383
- elseif rcall("ZSCORE", parentPrioritizedKey, parentId) then
384
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
385
- prevState = "prioritized"
390
+ rcall("HSET", parentKey, "delay", 0)
386
391
  end
387
- if parentWaitingChildrenOrDelayedOrPrioritizedKey then
388
- rcall("ZREM", parentWaitingChildrenOrDelayedOrPrioritizedKey, parentId)
392
+ if parentWaitingChildrenOrDelayedKey then
393
+ rcall("ZREM", parentWaitingChildrenOrDelayedKey, parentId)
389
394
  local parentQueuePrefix = parentQueueKey .. ":"
390
395
  local parentFailedKey = parentQueueKey .. ":failed"
391
- rcall("ZADD", parentFailedKey, timestamp, parentId)
392
- local failedReason = "child " .. jobIdKey .. " failed"
393
- rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
394
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
395
- failedReason, "prev", prevState)
396
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
397
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
398
- moveChildFromDependenciesIfNeeded(jobAttributes[1], parentKey, failedReason, timestamp)
399
- local parentRawOpts = jobAttributes[3]
400
- local parentOpts = cjson.decode(parentRawOpts)
401
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
396
+ local deferredFailure = "child " .. jobIdKey .. " failed"
397
+ rcall("HSET", parentKey, "defa", deferredFailure)
398
+ moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
402
399
  else
403
- local grandParentKey = rcall("HGET", parentKey, "parentKey")
404
- if grandParentKey then
405
- local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
406
- rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
400
+ if not rcall("ZSCORE", parentQueueKey .. ":failed", parentId) then
401
+ local deferredFailure = "child " .. jobIdKey .. " failed"
402
+ rcall("HSET", parentKey, "defa", deferredFailure)
407
403
  end
408
404
  end
409
405
  end
@@ -429,11 +425,11 @@ moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, failedRea
429
425
  if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
430
426
  local parentFailedChildrenKey = parentKey .. ":failed"
431
427
  rcall("HSET", parentFailedChildrenKey, childKey, failedReason)
432
- moveParentToWait(parentData['queueKey'], parentKey, parentData['id'], timestamp)
428
+ moveParentToWaitIfNeeded(parentData['queueKey'], parentKey, parentData['id'], timestamp)
433
429
  end
434
430
  elseif parentData['idof'] or parentData['rdof'] then
435
431
  if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
436
- moveParentToWaitIfNeeded(parentData['queueKey'], parentDependenciesChildrenKey,
432
+ moveParentToWaitIfNoPendingDependencies(parentData['queueKey'], parentDependenciesChildrenKey,
437
433
  parentKey, parentData['id'], timestamp)
438
434
  if parentData['idof'] then
439
435
  local parentFailedChildrenKey = parentKey .. ":failed"
@@ -443,6 +439,26 @@ moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, failedRea
443
439
  end
444
440
  end
445
441
  end
442
+ --[[
443
+ Function to remove deduplication key if needed
444
+ when a job is moved to completed or failed states.
445
+ ]]
446
+ local function removeDeduplicationKeyIfNeededOnFinalization(prefixKey,
447
+ deduplicationId, jobId)
448
+ if deduplicationId then
449
+ local deduplicationKey = prefixKey .. "de:" .. deduplicationId
450
+ local pttl = rcall("PTTL", deduplicationKey)
451
+ if pttl == 0 then
452
+ return rcall("DEL", deduplicationKey)
453
+ end
454
+ if pttl == -1 then
455
+ local currentJobId = rcall('GET', deduplicationKey)
456
+ if currentJobId and currentJobId == jobId then
457
+ return rcall("DEL", deduplicationKey)
458
+ end
459
+ end
460
+ end
461
+ end
446
462
  --[[
447
463
  Function to trim events, default 10000.
448
464
  ]]
@@ -512,7 +528,7 @@ if (#stalling > 0) then
512
528
  local rawParentData = jobAttributes[2]
513
529
  local opts = cjson.decode(rawOpts)
514
530
  rcall("ZADD", failedKey, timestamp, jobId)
515
- removeDeduplicationKeyIfNeeded(queueKeyPrefix, jobAttributes[3])
531
+ removeDeduplicationKeyIfNeededOnFinalization(queueKeyPrefix, jobAttributes[3], jobId)
516
532
  local failedReason = "job stalled more than allowable limit"
517
533
  rcall("HMSET", jobKey, "failedReason", failedReason, "finishedOn", timestamp)
518
534
  rcall("XADD", eventStreamKey, "*", "event", "failed", "jobId", jobId, 'prev', 'active',
@@ -1 +1 @@
1
- {"version":3,"file":"moveStalledJobsToWait-9.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-9.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6hBf,CAAC;AACW,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6iBf,CAAC;AACW,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}