bullmq 5.44.1 → 5.52.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 (204) hide show
  1. package/dist/cjs/classes/async-fifo-queue.js.map +1 -1
  2. package/dist/cjs/classes/child-processor.js.map +1 -1
  3. package/dist/cjs/classes/child.js.map +1 -1
  4. package/dist/cjs/classes/flow-producer.js +15 -4
  5. package/dist/cjs/classes/flow-producer.js.map +1 -1
  6. package/dist/cjs/classes/job-scheduler.js +1 -1
  7. package/dist/cjs/classes/job-scheduler.js.map +1 -1
  8. package/dist/cjs/classes/job.js +137 -54
  9. package/dist/cjs/classes/job.js.map +1 -1
  10. package/dist/cjs/classes/queue-base.js +1 -4
  11. package/dist/cjs/classes/queue-base.js.map +1 -1
  12. package/dist/cjs/classes/queue-events-producer.js.map +1 -1
  13. package/dist/cjs/classes/queue-events.js.map +1 -1
  14. package/dist/cjs/classes/queue-getters.js +12 -15
  15. package/dist/cjs/classes/queue-getters.js.map +1 -1
  16. package/dist/cjs/classes/queue-keys.js.map +1 -1
  17. package/dist/cjs/classes/queue.js +12 -13
  18. package/dist/cjs/classes/queue.js.map +1 -1
  19. package/dist/cjs/classes/redis-connection.js +1 -1
  20. package/dist/cjs/classes/redis-connection.js.map +1 -1
  21. package/dist/cjs/classes/repeat.js +1 -1
  22. package/dist/cjs/classes/repeat.js.map +1 -1
  23. package/dist/cjs/classes/scripts.js +18 -7
  24. package/dist/cjs/classes/scripts.js.map +1 -1
  25. package/dist/cjs/classes/worker.js +4 -0
  26. package/dist/cjs/classes/worker.js.map +1 -1
  27. package/dist/cjs/commands/addJobScheduler-11.lua +52 -33
  28. package/dist/cjs/commands/includes/deduplicateJob.lua +16 -17
  29. package/dist/cjs/commands/includes/isLocked.lua +1 -0
  30. package/dist/cjs/commands/includes/moveChildFromDependenciesIfNeeded.lua +79 -0
  31. package/dist/cjs/commands/includes/moveParentToWait.lua +48 -0
  32. package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +9 -50
  33. package/dist/cjs/commands/includes/moveParentToWaitIfNoPendingDependencies.lua +13 -0
  34. package/dist/cjs/commands/includes/removeDeduplicationKeyIfNeededOnFinalization.lua +23 -0
  35. package/dist/cjs/commands/includes/removeDeduplicationKeyIfNeededOnRemoval.lua +16 -0
  36. package/dist/cjs/commands/includes/removeJob.lua +2 -2
  37. package/dist/cjs/commands/includes/removeJobWithChildren.lua +94 -0
  38. package/dist/cjs/commands/includes/removeParentDependencyKey.lua +5 -5
  39. package/dist/cjs/commands/includes/storeJob.lua +1 -1
  40. package/dist/cjs/commands/includes/updateParentDepsIfNeeded.lua +2 -2
  41. package/dist/cjs/commands/moveStalledJobsToWait-9.lua +18 -53
  42. package/dist/cjs/commands/moveToFinished-14.lua +43 -51
  43. package/dist/cjs/commands/moveToWaitingChildren-8.lua +5 -32
  44. package/dist/cjs/commands/removeJob-3.lua +14 -72
  45. package/dist/cjs/commands/removeUnprocessedChildren-2.lua +31 -0
  46. package/dist/cjs/commands/updateJobScheduler-12.lua +29 -23
  47. package/dist/cjs/scripts/addDelayedJob-6.js +73 -55
  48. package/dist/cjs/scripts/addDelayedJob-6.js.map +1 -1
  49. package/dist/cjs/scripts/addJobScheduler-11.js +59 -40
  50. package/dist/cjs/scripts/addJobScheduler-11.js.map +1 -1
  51. package/dist/cjs/scripts/addParentJob-4.js +73 -55
  52. package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
  53. package/dist/cjs/scripts/addPrioritizedJob-8.js +73 -55
  54. package/dist/cjs/scripts/addPrioritizedJob-8.js.map +1 -1
  55. package/dist/cjs/scripts/addRepeatableJob-2.js +14 -9
  56. package/dist/cjs/scripts/addRepeatableJob-2.js.map +1 -1
  57. package/dist/cjs/scripts/addStandardJob-8.js +73 -55
  58. package/dist/cjs/scripts/addStandardJob-8.js.map +1 -1
  59. package/dist/cjs/scripts/cleanJobsInSet-3.js +14 -9
  60. package/dist/cjs/scripts/cleanJobsInSet-3.js.map +1 -1
  61. package/dist/cjs/scripts/drain-5.js +14 -9
  62. package/dist/cjs/scripts/drain-5.js.map +1 -1
  63. package/dist/cjs/scripts/index.js +1 -0
  64. package/dist/cjs/scripts/index.js.map +1 -1
  65. package/dist/cjs/scripts/moveStalledJobsToWait-9.js +157 -155
  66. package/dist/cjs/scripts/moveStalledJobsToWait-9.js.map +1 -1
  67. package/dist/cjs/scripts/moveToFinished-14.js +183 -157
  68. package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
  69. package/dist/cjs/scripts/moveToWaitingChildren-8.js +145 -137
  70. package/dist/cjs/scripts/moveToWaitingChildren-8.js.map +1 -1
  71. package/dist/cjs/scripts/obliterate-2.js +14 -9
  72. package/dist/cjs/scripts/obliterate-2.js.map +1 -1
  73. package/dist/cjs/scripts/removeChildDependency-1.js +5 -5
  74. package/dist/cjs/scripts/removeJob-3.js +97 -63
  75. package/dist/cjs/scripts/removeJob-3.js.map +1 -1
  76. package/dist/cjs/scripts/removeUnprocessedChildren-2.js +338 -0
  77. package/dist/cjs/scripts/removeUnprocessedChildren-2.js.map +1 -0
  78. package/dist/cjs/scripts/updateJobScheduler-12.js +27 -21
  79. package/dist/cjs/scripts/updateJobScheduler-12.js.map +1 -1
  80. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  81. package/dist/cjs/types/index.js +1 -0
  82. package/dist/cjs/types/index.js.map +1 -1
  83. package/dist/cjs/types/job-progress.js +3 -0
  84. package/dist/cjs/types/job-progress.js.map +1 -0
  85. package/dist/cjs/utils.js +12 -1
  86. package/dist/cjs/utils.js.map +1 -1
  87. package/dist/cjs/version.js +1 -1
  88. package/dist/esm/classes/async-fifo-queue.js.map +1 -1
  89. package/dist/esm/classes/child-processor.js.map +1 -1
  90. package/dist/esm/classes/child.js.map +1 -1
  91. package/dist/esm/classes/flow-producer.js +15 -4
  92. package/dist/esm/classes/flow-producer.js.map +1 -1
  93. package/dist/esm/classes/job-scheduler.js +1 -1
  94. package/dist/esm/classes/job-scheduler.js.map +1 -1
  95. package/dist/esm/classes/job.d.ts +49 -14
  96. package/dist/esm/classes/job.js +138 -55
  97. package/dist/esm/classes/job.js.map +1 -1
  98. package/dist/esm/classes/queue-base.d.ts +1 -4
  99. package/dist/esm/classes/queue-base.js +1 -4
  100. package/dist/esm/classes/queue-base.js.map +1 -1
  101. package/dist/esm/classes/queue-events-producer.d.ts +2 -2
  102. package/dist/esm/classes/queue-events-producer.js.map +1 -1
  103. package/dist/esm/classes/queue-events.d.ts +118 -29
  104. package/dist/esm/classes/queue-events.js.map +1 -1
  105. package/dist/esm/classes/queue-getters.d.ts +11 -14
  106. package/dist/esm/classes/queue-getters.js +12 -15
  107. package/dist/esm/classes/queue-getters.js.map +1 -1
  108. package/dist/esm/classes/queue-keys.js.map +1 -1
  109. package/dist/esm/classes/queue.d.ts +14 -15
  110. package/dist/esm/classes/queue.js +12 -13
  111. package/dist/esm/classes/queue.js.map +1 -1
  112. package/dist/esm/classes/redis-connection.js +1 -1
  113. package/dist/esm/classes/redis-connection.js.map +1 -1
  114. package/dist/esm/classes/repeat.js +1 -1
  115. package/dist/esm/classes/repeat.js.map +1 -1
  116. package/dist/esm/classes/scripts.d.ts +4 -3
  117. package/dist/esm/classes/scripts.js +18 -7
  118. package/dist/esm/classes/scripts.js.map +1 -1
  119. package/dist/esm/classes/worker.d.ts +2 -1
  120. package/dist/esm/classes/worker.js +5 -1
  121. package/dist/esm/classes/worker.js.map +1 -1
  122. package/dist/esm/commands/addJobScheduler-11.lua +52 -33
  123. package/dist/esm/commands/includes/deduplicateJob.lua +16 -17
  124. package/dist/esm/commands/includes/isLocked.lua +1 -0
  125. package/dist/esm/commands/includes/moveChildFromDependenciesIfNeeded.lua +79 -0
  126. package/dist/esm/commands/includes/moveParentToWait.lua +48 -0
  127. package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +9 -50
  128. package/dist/esm/commands/includes/moveParentToWaitIfNoPendingDependencies.lua +13 -0
  129. package/dist/esm/commands/includes/removeDeduplicationKeyIfNeededOnFinalization.lua +23 -0
  130. package/dist/esm/commands/includes/removeDeduplicationKeyIfNeededOnRemoval.lua +16 -0
  131. package/dist/esm/commands/includes/removeJob.lua +2 -2
  132. package/dist/esm/commands/includes/removeJobWithChildren.lua +94 -0
  133. package/dist/esm/commands/includes/removeParentDependencyKey.lua +5 -5
  134. package/dist/esm/commands/includes/storeJob.lua +1 -1
  135. package/dist/esm/commands/includes/updateParentDepsIfNeeded.lua +2 -2
  136. package/dist/esm/commands/moveStalledJobsToWait-9.lua +18 -53
  137. package/dist/esm/commands/moveToFinished-14.lua +43 -51
  138. package/dist/esm/commands/moveToWaitingChildren-8.lua +5 -32
  139. package/dist/esm/commands/removeJob-3.lua +14 -72
  140. package/dist/esm/commands/removeUnprocessedChildren-2.lua +31 -0
  141. package/dist/esm/commands/updateJobScheduler-12.lua +29 -23
  142. package/dist/esm/interfaces/job-json.d.ts +5 -2
  143. package/dist/esm/interfaces/minimal-job.d.ts +29 -11
  144. package/dist/esm/interfaces/queue-options.d.ts +6 -2
  145. package/dist/esm/interfaces/repeat-options.d.ts +1 -1
  146. package/dist/esm/interfaces/sandboxed-job.d.ts +2 -2
  147. package/dist/esm/interfaces/sandboxed-options.d.ts +1 -1
  148. package/dist/esm/interfaces/telemetry.d.ts +18 -15
  149. package/dist/esm/interfaces/worker-options.d.ts +10 -10
  150. package/dist/esm/scripts/addDelayedJob-6.js +73 -55
  151. package/dist/esm/scripts/addDelayedJob-6.js.map +1 -1
  152. package/dist/esm/scripts/addJobScheduler-11.js +59 -40
  153. package/dist/esm/scripts/addJobScheduler-11.js.map +1 -1
  154. package/dist/esm/scripts/addParentJob-4.js +73 -55
  155. package/dist/esm/scripts/addParentJob-4.js.map +1 -1
  156. package/dist/esm/scripts/addPrioritizedJob-8.js +73 -55
  157. package/dist/esm/scripts/addPrioritizedJob-8.js.map +1 -1
  158. package/dist/esm/scripts/addRepeatableJob-2.js +14 -9
  159. package/dist/esm/scripts/addRepeatableJob-2.js.map +1 -1
  160. package/dist/esm/scripts/addStandardJob-8.js +73 -55
  161. package/dist/esm/scripts/addStandardJob-8.js.map +1 -1
  162. package/dist/esm/scripts/cleanJobsInSet-3.js +14 -9
  163. package/dist/esm/scripts/cleanJobsInSet-3.js.map +1 -1
  164. package/dist/esm/scripts/drain-5.js +14 -9
  165. package/dist/esm/scripts/drain-5.js.map +1 -1
  166. package/dist/esm/scripts/index.d.ts +1 -0
  167. package/dist/esm/scripts/index.js +1 -0
  168. package/dist/esm/scripts/index.js.map +1 -1
  169. package/dist/esm/scripts/moveStalledJobsToWait-9.js +157 -155
  170. package/dist/esm/scripts/moveStalledJobsToWait-9.js.map +1 -1
  171. package/dist/esm/scripts/moveToFinished-14.js +183 -157
  172. package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
  173. package/dist/esm/scripts/moveToWaitingChildren-8.js +145 -137
  174. package/dist/esm/scripts/moveToWaitingChildren-8.js.map +1 -1
  175. package/dist/esm/scripts/obliterate-2.js +14 -9
  176. package/dist/esm/scripts/obliterate-2.js.map +1 -1
  177. package/dist/esm/scripts/removeChildDependency-1.js +5 -5
  178. package/dist/esm/scripts/removeJob-3.js +97 -63
  179. package/dist/esm/scripts/removeJob-3.js.map +1 -1
  180. package/dist/esm/scripts/removeUnprocessedChildren-2.d.ts +5 -0
  181. package/dist/esm/scripts/removeUnprocessedChildren-2.js +335 -0
  182. package/dist/esm/scripts/removeUnprocessedChildren-2.js.map +1 -0
  183. package/dist/esm/scripts/updateJobScheduler-12.js +27 -21
  184. package/dist/esm/scripts/updateJobScheduler-12.js.map +1 -1
  185. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  186. package/dist/esm/types/index.d.ts +1 -0
  187. package/dist/esm/types/index.js +1 -0
  188. package/dist/esm/types/index.js.map +1 -1
  189. package/dist/esm/types/job-options.d.ts +13 -2
  190. package/dist/esm/types/job-progress.d.ts +1 -0
  191. package/dist/esm/types/job-progress.js +2 -0
  192. package/dist/esm/types/job-progress.js.map +1 -0
  193. package/dist/esm/utils.d.ts +17 -0
  194. package/dist/esm/utils.js +11 -0
  195. package/dist/esm/utils.js.map +1 -1
  196. package/dist/esm/version.d.ts +1 -1
  197. package/dist/esm/version.js +1 -1
  198. package/package.json +26 -21
  199. package/dist/cjs/commands/includes/moveParentFromWaitingChildrenToFailed.lua +0 -80
  200. package/dist/cjs/commands/includes/removeDeduplicationKey.lua +0 -11
  201. package/dist/cjs/commands/includes/removeDeduplicationKeyIfNeeded.lua +0 -14
  202. package/dist/esm/commands/includes/moveParentFromWaitingChildrenToFailed.lua +0 -80
  203. package/dist/esm/commands/includes/removeDeduplicationKey.lua +0 -11
  204. package/dist/esm/commands/includes/removeDeduplicationKeyIfNeeded.lua +0 -14
@@ -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
  --[[
@@ -136,7 +141,7 @@ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
136
141
  end
137
142
  return waitKey, false
138
143
  end
139
- local function moveParentToWait(parentPrefix, parentId, emitEvent)
144
+ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
140
145
  local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
141
146
  parentPrefix .. "wait", parentPrefix .. "paused")
142
147
  addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
@@ -164,10 +169,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
164
169
  rcall("DEL", parentPrefix .. "de:" .. debounceId)
165
170
  end
166
171
  else
167
- moveParentToWait(parentPrefix, parentId)
172
+ _moveParentToWait(parentPrefix, parentId)
168
173
  end
169
174
  else
170
- moveParentToWait(parentPrefix, parentId, true)
175
+ _moveParentToWait(parentPrefix, parentId, true)
171
176
  end
172
177
  end
173
178
  end
@@ -195,10 +200,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
195
200
  rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
196
201
  end
197
202
  else
198
- moveParentToWait(parentPrefix, parentId)
203
+ _moveParentToWait(parentPrefix, parentId)
199
204
  end
200
205
  else
201
- moveParentToWait(parentPrefix, parentId, true)
206
+ _moveParentToWait(parentPrefix, parentId, true)
202
207
  end
203
208
  end
204
209
  end
@@ -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
  --[[
@@ -108,7 +113,7 @@ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
108
113
  end
109
114
  return waitKey, false
110
115
  end
111
- local function moveParentToWait(parentPrefix, parentId, emitEvent)
116
+ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
112
117
  local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
113
118
  parentPrefix .. "wait", parentPrefix .. "paused")
114
119
  addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
@@ -136,10 +141,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
136
141
  rcall("DEL", parentPrefix .. "de:" .. debounceId)
137
142
  end
138
143
  else
139
- moveParentToWait(parentPrefix, parentId)
144
+ _moveParentToWait(parentPrefix, parentId)
140
145
  end
141
146
  else
142
- moveParentToWait(parentPrefix, parentId, true)
147
+ _moveParentToWait(parentPrefix, parentId, true)
143
148
  end
144
149
  end
145
150
  end
@@ -167,10 +172,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
167
172
  rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
168
173
  end
169
174
  else
170
- moveParentToWait(parentPrefix, parentId)
175
+ _moveParentToWait(parentPrefix, parentId)
171
176
  end
172
177
  else
173
- moveParentToWait(parentPrefix, parentId, true)
178
+ _moveParentToWait(parentPrefix, parentId, true)
174
179
  end
175
180
  end
176
181
  end
@@ -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"}
@@ -41,6 +41,7 @@ tslib_1.__exportStar(require("./removeChildDependency-1"), exports);
41
41
  tslib_1.__exportStar(require("./removeJob-3"), exports);
42
42
  tslib_1.__exportStar(require("./removeJobScheduler-3"), exports);
43
43
  tslib_1.__exportStar(require("./removeRepeatable-3"), exports);
44
+ tslib_1.__exportStar(require("./removeUnprocessedChildren-2"), exports);
44
45
  tslib_1.__exportStar(require("./reprocessJob-8"), exports);
45
46
  tslib_1.__exportStar(require("./retryJob-11"), exports);
46
47
  tslib_1.__exportStar(require("./saveStacktrace-1"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC;AAClC,+DAAqC;AACrC,qDAA2B;AAC3B,2DAAiC;AACjC,gEAAsC;AACtC,+DAAqC;AACrC,6DAAmC;AACnC,0DAAgC;AAChC,6DAAmC;AACnC,6DAAmC;AACnC,oDAA0B;AAC1B,yDAA+B;AAC/B,0DAAgC;AAChC,wDAA8B;AAC9B,mEAAyC;AACzC,kEAAwC;AACxC,8DAAoC;AACpC,wDAA8B;AAC9B,8DAAoC;AACpC,uDAA6B;AAC7B,yDAA+B;AAC/B,yDAA+B;AAC/B,0DAAgC;AAChC,sDAA4B;AAC5B,sEAA4C;AAC5C,6DAAmC;AACnC,oEAA0C;AAC1C,4DAAkC;AAClC,4DAAkC;AAClC,8DAAoC;AACpC,oEAA0C;AAC1C,yDAA+B;AAC/B,uDAA6B;AAC7B,oDAA0B;AAC1B,sDAA4B;AAC5B,0DAAgC;AAChC,oEAA0C;AAC1C,wDAA8B;AAC9B,iEAAuC;AACvC,+DAAqC;AACrC,2DAAiC;AACjC,wDAA8B;AAC9B,6DAAmC;AACnC,yDAA+B;AAC/B,kEAAwC;AACxC,6DAAmC;AACnC,wEAA8C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC;AAClC,+DAAqC;AACrC,qDAA2B;AAC3B,2DAAiC;AACjC,gEAAsC;AACtC,+DAAqC;AACrC,6DAAmC;AACnC,0DAAgC;AAChC,6DAAmC;AACnC,6DAAmC;AACnC,oDAA0B;AAC1B,yDAA+B;AAC/B,0DAAgC;AAChC,wDAA8B;AAC9B,mEAAyC;AACzC,kEAAwC;AACxC,8DAAoC;AACpC,wDAA8B;AAC9B,8DAAoC;AACpC,uDAA6B;AAC7B,yDAA+B;AAC/B,yDAA+B;AAC/B,0DAAgC;AAChC,sDAA4B;AAC5B,sEAA4C;AAC5C,6DAAmC;AACnC,oEAA0C;AAC1C,4DAAkC;AAClC,4DAAkC;AAClC,8DAAoC;AACpC,oEAA0C;AAC1C,yDAA+B;AAC/B,uDAA6B;AAC7B,oDAA0B;AAC1B,sDAA4B;AAC5B,0DAAgC;AAChC,oEAA0C;AAC1C,wDAA8B;AAC9B,iEAAuC;AACvC,+DAAqC;AACrC,wEAA8C;AAC9C,2DAAiC;AACjC,wDAA8B;AAC9B,6DAAmC;AACnC,yDAA+B;AAC/B,kEAAwC;AACxC,6DAAmC;AACnC,wEAA8C"}
@@ -79,7 +79,16 @@ end
79
79
  ]]
80
80
  -- Includes
81
81
  --[[
82
- Validate and move parent to active if needed.
82
+ Validate and move parent to a wait status (waiting, delayed or prioritized)
83
+ if no pending dependencies.
84
+ ]]
85
+ -- Includes
86
+ --[[
87
+ Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
88
+ ]]
89
+ -- Includes
90
+ --[[
91
+ Move parent to a wait status (wait, prioritized or delayed)
83
92
  ]]
84
93
  -- Includes
85
94
  --[[
@@ -139,58 +148,55 @@ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
139
148
  end
140
149
  return false
141
150
  end
142
- local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
143
- parentKey, parentId, timestamp)
144
- local isParentActive = rcall("ZSCORE",
145
- parentQueueKey .. ":waiting-children", parentId)
146
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
147
- rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
148
- local parentWaitKey = parentQueueKey .. ":wait"
149
- local parentPausedKey = parentQueueKey .. ":paused"
150
- local parentActiveKey = parentQueueKey .. ":active"
151
- local parentMetaKey = parentQueueKey .. ":meta"
152
- local parentMarkerKey = parentQueueKey .. ":marker"
153
- local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
154
- local priority = tonumber(jobAttributes[1]) or 0
155
- local delay = tonumber(jobAttributes[2]) or 0
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",
162
- "jobId", parentId, "delay", delayedTimestamp)
163
- addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
151
+ local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
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)
164
175
  else
165
- if priority == 0 then
166
- local parentTarget, isParentPausedOrMaxed =
167
- getTargetQueueList(parentMetaKey, parentActiveKey, parentWaitKey,
168
- parentPausedKey)
169
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed,
170
- parentId)
171
- else
172
- local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
173
- addJobWithPriority(parentMarkerKey,
174
- parentQueueKey .. ":prioritized", priority,
175
- parentId, parentQueueKey .. ":pc", isPausedOrMaxed)
176
- end
177
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
178
- "jobId", parentId, "prev", "waiting-children")
176
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
177
+ addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
178
+ parentQueueKey .. ":pc", isPausedOrMaxed)
179
179
  end
180
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
181
+ "waiting-children")
180
182
  end
181
183
  end
182
- --[[
183
- Function to remove deduplication key if needed.
184
- ]]
185
- local function removeDeduplicationKeyIfNeeded(prefixKey, deduplicationId)
186
- if deduplicationId then
187
- local deduplicationKey = prefixKey .. "de:" .. deduplicationId
188
- local pttl = rcall("PTTL", deduplicationKey)
189
- if pttl == 0 or pttl == -1 then
190
- rcall("DEL", deduplicationKey)
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)
191
190
  end
192
191
  end
193
192
  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)
198
+ end
199
+ end
194
200
  --[[
195
201
  Functions to remove jobs when removeOnFail option is provided.
196
202
  ]]
@@ -200,13 +206,18 @@ end
200
206
  ]]
201
207
  -- Includes
202
208
  --[[
203
- Function to remove deduplication key.
209
+ Function to remove deduplication key if needed
210
+ when a job is being removed.
204
211
  ]]
205
- local function removeDeduplicationKey(prefixKey, jobKey)
212
+ local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
213
+ jobKey, jobId)
206
214
  local deduplicationId = rcall("HGET", jobKey, "deid")
207
215
  if deduplicationId then
208
216
  local deduplicationKey = prefixKey .. "de:" .. deduplicationId
209
- rcall("DEL", deduplicationKey)
217
+ local currentJobId = rcall('GET', deduplicationKey)
218
+ if currentJobId and currentJobId == jobId then
219
+ return rcall("DEL", deduplicationKey)
220
+ end
210
221
  end
211
222
  end
212
223
  --[[
@@ -232,7 +243,7 @@ end
232
243
  local getJobKeyPrefix = function (jobKey, jobId)
233
244
  return string.sub(jobKey, 0, #jobKey - #jobId)
234
245
  end
235
- local function moveParentToWait(parentPrefix, parentId, emitEvent)
246
+ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
236
247
  local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
237
248
  parentPrefix .. "wait", parentPrefix .. "paused")
238
249
  addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
@@ -260,10 +271,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
260
271
  rcall("DEL", parentPrefix .. "de:" .. debounceId)
261
272
  end
262
273
  else
263
- moveParentToWait(parentPrefix, parentId)
274
+ _moveParentToWait(parentPrefix, parentId)
264
275
  end
265
276
  else
266
- moveParentToWait(parentPrefix, parentId, true)
277
+ _moveParentToWait(parentPrefix, parentId, true)
267
278
  end
268
279
  end
269
280
  end
@@ -291,10 +302,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
291
302
  rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
292
303
  end
293
304
  else
294
- moveParentToWait(parentPrefix, parentId)
305
+ _moveParentToWait(parentPrefix, parentId)
295
306
  end
296
307
  else
297
- moveParentToWait(parentPrefix, parentId, true)
308
+ _moveParentToWait(parentPrefix, parentId, true)
298
309
  end
299
310
  end
300
311
  end
@@ -308,7 +319,7 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
308
319
  local jobKey = baseKey .. jobId
309
320
  removeParentDependencyKey(jobKey, hard, nil, baseKey)
310
321
  if shouldRemoveDeduplicationKey then
311
- removeDeduplicationKey(baseKey, jobKey)
322
+ removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
312
323
  end
313
324
  removeJobKeys(jobKey)
314
325
  end
@@ -361,67 +372,90 @@ local function removeJobsOnFail(queueKeyPrefix, failedKey, jobId, opts, timestam
361
372
  end
362
373
  end
363
374
  end
364
- local function moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
365
- local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
366
- local parentDelayedKey = parentQueueKey .. ":delayed"
367
- local parentPrioritizedKey = parentQueueKey .. ":prioritized"
368
- local parentWaitingChildrenOrDelayedOrPrioritizedKey
369
- local prevState
370
- if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
371
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentWaitingChildrenKey
372
- prevState = "waiting-children"
373
- elseif rcall("ZSCORE", parentDelayedKey, parentId) then
374
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentDelayedKey
375
- prevState = "delayed"
376
- elseif rcall("ZSCORE", parentPrioritizedKey, parentId) then
377
- parentWaitingChildrenOrDelayedOrPrioritizedKey = parentPrioritizedKey
378
- prevState = "prioritized"
375
+ local moveParentToFailedIfNeeded
376
+ local moveChildFromDependenciesIfNeeded
377
+ moveParentToFailedIfNeeded = function (parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
378
+ if rcall("EXISTS", parentKey) == 1 then
379
+ local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
380
+ local parentDelayedKey = parentQueueKey .. ":delayed"
381
+ local parentPrioritizedKey = parentQueueKey .. ":prioritized"
382
+ local parentWaitingChildrenOrDelayedKey
383
+ local prevState
384
+ if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
385
+ parentWaitingChildrenOrDelayedKey = parentWaitingChildrenKey
386
+ prevState = "waiting-children"
387
+ elseif rcall("ZSCORE", parentDelayedKey, parentId) then
388
+ parentWaitingChildrenOrDelayedKey = parentDelayedKey
389
+ prevState = "delayed"
390
+ rcall("HSET", parentKey, "delay", 0)
391
+ end
392
+ if parentWaitingChildrenOrDelayedKey then
393
+ rcall("ZREM", parentWaitingChildrenOrDelayedKey, parentId)
394
+ local parentQueuePrefix = parentQueueKey .. ":"
395
+ local parentFailedKey = parentQueueKey .. ":failed"
396
+ local deferredFailure = "child " .. jobIdKey .. " failed"
397
+ rcall("HSET", parentKey, "defa", deferredFailure)
398
+ moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
399
+ else
400
+ if not rcall("ZSCORE", parentQueueKey .. ":failed", parentId) then
401
+ local deferredFailure = "child " .. jobIdKey .. " failed"
402
+ rcall("HSET", parentKey, "defa", deferredFailure)
403
+ end
404
+ end
379
405
  end
380
- if parentWaitingChildrenOrDelayedOrPrioritizedKey then
381
- rcall("ZREM", parentWaitingChildrenOrDelayedOrPrioritizedKey, parentId)
382
- local parentQueuePrefix = parentQueueKey .. ":"
383
- local parentFailedKey = parentQueueKey .. ":failed"
384
- rcall("ZADD", parentFailedKey, timestamp, parentId)
385
- local failedReason = "child " .. jobIdKey .. " failed"
386
- rcall("HSET", parentKey, "failedReason", failedReason, "finishedOn", timestamp)
387
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "failed", "jobId", parentId, "failedReason",
388
- failedReason, "prev", prevState)
389
- local jobAttributes = rcall("HMGET", parentKey, "parent", "deid", "opts")
390
- removeDeduplicationKeyIfNeeded(parentQueueKey .. ":", jobAttributes[2])
391
- if jobAttributes[1] then
392
- local parentData = cjson.decode(jobAttributes[1])
393
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
394
- local grandParentUnsuccesssful = grandParentKey .. ":unsuccessful"
395
- rcall("ZADD", grandParentUnsuccesssful, timestamp, parentKey)
396
- if parentData['fpof'] then
397
- moveParentFromWaitingChildrenToFailed(
406
+ end
407
+ moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, failedReason, timestamp)
408
+ if rawParentData then
409
+ local parentData = cjson.decode(rawParentData)
410
+ local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
411
+ local parentDependenciesChildrenKey = parentKey .. ":dependencies"
412
+ if parentData['fpof'] then
413
+ if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
414
+ local parentUnsuccesssfulChildrenKey = parentKey .. ":unsuccessful"
415
+ rcall("ZADD", parentUnsuccesssfulChildrenKey, timestamp, childKey)
416
+ moveParentToFailedIfNeeded(
398
417
  parentData['queueKey'],
399
- parentData['queueKey'] .. ':' .. parentData['id'],
400
- parentData['id'],
401
418
  parentKey,
419
+ parentData['id'],
420
+ childKey,
402
421
  timestamp
403
422
  )
404
- elseif parentData['idof'] or parentData['rdof'] then
405
- local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
406
- local grandParentDependenciesSet = grandParentKey .. ":dependencies"
407
- if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
408
- moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
409
- grandParentKey, parentData['id'], timestamp)
410
- if parentData['idof'] then
411
- local grandParentFailedSet = grandParentKey .. ":failed"
412
- rcall("HSET", grandParentFailedSet, parentKey, failedReason)
413
- end
423
+ end
424
+ elseif parentData['cpof'] then
425
+ if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
426
+ local parentFailedChildrenKey = parentKey .. ":failed"
427
+ rcall("HSET", parentFailedChildrenKey, childKey, failedReason)
428
+ moveParentToWaitIfNeeded(parentData['queueKey'], parentKey, parentData['id'], timestamp)
429
+ end
430
+ elseif parentData['idof'] or parentData['rdof'] then
431
+ if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
432
+ moveParentToWaitIfNoPendingDependencies(parentData['queueKey'], parentDependenciesChildrenKey,
433
+ parentKey, parentData['id'], timestamp)
434
+ if parentData['idof'] then
435
+ local parentFailedChildrenKey = parentKey .. ":failed"
436
+ rcall("HSET", parentFailedChildrenKey, childKey, failedReason)
414
437
  end
415
438
  end
416
439
  end
417
- local parentRawOpts = jobAttributes[3]
418
- local parentOpts = cjson.decode(parentRawOpts)
419
- removeJobsOnFail(parentQueuePrefix, parentFailedKey, parentId, parentOpts, timestamp)
420
- else
421
- local grandParentKey = rcall("HGET", parentKey, "parentKey")
422
- if grandParentKey then
423
- local grandParentUnsuccesssfulSet = grandParentKey .. ":unsuccessful"
424
- rcall("ZADD", grandParentUnsuccesssfulSet, timestamp, parentKey)
440
+ end
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
425
459
  end
426
460
  end
427
461
  end
@@ -461,7 +495,9 @@ local maxStalledJobCount = tonumber(ARGV[1])
461
495
  local queueKeyPrefix = ARGV[2]
462
496
  local timestamp = ARGV[3]
463
497
  local maxCheckTime = ARGV[4]
464
- if rcall("EXISTS", stalledCheckKey) == 1 then return {{}, {}} end
498
+ if rcall("EXISTS", stalledCheckKey) == 1 then
499
+ return {{}, {}}
500
+ end
465
501
  rcall("SET", stalledCheckKey, timestamp, "PX", maxCheckTime)
466
502
  -- Trim events before emiting them to avoid trimming events emitted in this script
467
503
  trimEvents(metaKey, eventStreamKey)
@@ -485,63 +521,28 @@ if (#stalling > 0) then
485
521
  local removed = rcall("LREM", activeKey, 1, jobId)
486
522
  if (removed > 0) then
487
523
  -- If this job has been stalled too many times, such as if it crashes the worker, then fail it.
488
- local stalledCount =
489
- rcall("HINCRBY", jobKey, "stalledCounter", 1)
524
+ local stalledCount = rcall("HINCRBY", jobKey, "stc", 1)
490
525
  if (stalledCount > maxStalledJobCount) then
491
526
  local jobAttributes = rcall("HMGET", jobKey, "opts", "parent", "deid")
492
527
  local rawOpts = jobAttributes[1]
493
528
  local rawParentData = jobAttributes[2]
494
529
  local opts = cjson.decode(rawOpts)
495
530
  rcall("ZADD", failedKey, timestamp, jobId)
496
- removeDeduplicationKeyIfNeeded(queueKeyPrefix, jobAttributes[3])
497
- local failedReason =
498
- "job stalled more than allowable limit"
499
- rcall("HMSET", jobKey, "failedReason", failedReason,
500
- "finishedOn", timestamp)
501
- rcall("XADD", eventStreamKey, "*", "event",
502
- "failed", "jobId", jobId, 'prev', 'active',
503
- 'failedReason', failedReason)
504
- if rawParentData then
505
- if opts['fpof'] then
506
- local parentData = cjson.decode(rawParentData)
507
- -- TODO: need to remove this job from dependencies set in next breaking change
508
- -- no for now as it would imply a breaking change
509
- local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
510
- local unsuccesssfulSet = parentKey .. ":unsuccessful"
511
- rcall("ZADD", unsuccesssfulSet, timestamp, jobKey)
512
- moveParentFromWaitingChildrenToFailed(
513
- parentData['queueKey'],
514
- parentData['queueKey'] .. ':' .. parentData['id'],
515
- parentData['id'],
516
- jobKey,
517
- timestamp
518
- )
519
- elseif opts['idof'] or opts['rdof'] then
520
- local parentData = cjson.decode(rawParentData)
521
- local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
522
- local dependenciesSet = parentKey .. ":dependencies"
523
- if rcall("SREM", dependenciesSet, jobKey) == 1 then
524
- moveParentToWaitIfNeeded(parentData['queueKey'], dependenciesSet,
525
- parentKey, parentData['id'], timestamp)
526
- if opts['idof'] then
527
- local failedSet = parentKey .. ":failed"
528
- rcall("HSET", failedSet, jobKey, failedReason)
529
- end
530
- end
531
- end
532
- end
531
+ removeDeduplicationKeyIfNeededOnFinalization(queueKeyPrefix, jobAttributes[3], jobId)
532
+ local failedReason = "job stalled more than allowable limit"
533
+ rcall("HMSET", jobKey, "failedReason", failedReason, "finishedOn", timestamp)
534
+ rcall("XADD", eventStreamKey, "*", "event", "failed", "jobId", jobId, 'prev', 'active',
535
+ 'failedReason', failedReason)
536
+ moveChildFromDependenciesIfNeeded(rawParentData, jobKey, failedReason, timestamp)
533
537
  removeJobsOnFail(queueKeyPrefix, failedKey, jobId, opts, timestamp)
534
538
  table.insert(failed, jobId)
535
539
  else
536
- local target, isPausedOrMaxed =
537
- getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
540
+ local target, isPausedOrMaxed = getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
538
541
  -- Move the job back to the wait queue, to immediately be picked up by a waiting worker.
539
542
  addJobInTargetList(target, markerKey, "RPUSH", isPausedOrMaxed, jobId)
540
- rcall("XADD", eventStreamKey, "*", "event",
541
- "waiting", "jobId", jobId, 'prev', 'active')
543
+ rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId", jobId, 'prev', 'active')
542
544
  -- Emit the stalled event
543
- rcall("XADD", eventStreamKey, "*", "event",
544
- "stalled", "jobId", jobId)
545
+ rcall("XADD", eventStreamKey, "*", "event", "stalled", "jobId", jobId)
545
546
  table.insert(stalled, jobId)
546
547
  end
547
548
  end
@@ -556,7 +557,8 @@ if (#active > 0) then
556
557
  rcall('SADD', stalledKey, unpack(active, from, to))
557
558
  end
558
559
  end
559
- return {failed, stalled}`;
560
+ return {failed, stalled}
561
+ `;
560
562
  exports.moveStalledJobsToWait = {
561
563
  name: 'moveStalledJobsToWait',
562
564
  content,
@@ -1 +1 @@
1
- {"version":3,"file":"moveStalledJobsToWait-9.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-9.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBA2iBS,CAAC;AACb,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"moveStalledJobsToWait-9.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-9.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6iBf,CAAC;AACW,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}