bullmq 4.3.0 → 4.5.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 (43) hide show
  1. package/dist/cjs/classes/job.js +8 -2
  2. package/dist/cjs/classes/job.js.map +1 -1
  3. package/dist/cjs/classes/queue.js +3 -2
  4. package/dist/cjs/classes/queue.js.map +1 -1
  5. package/dist/cjs/classes/scripts.js +6 -5
  6. package/dist/cjs/classes/scripts.js.map +1 -1
  7. package/dist/cjs/commands/includes/isLocked.lua +12 -10
  8. package/dist/cjs/commands/includes/moveParentFromWaitingChildrenToFailed.lua +10 -0
  9. package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +42 -0
  10. package/dist/cjs/commands/includes/updateParentDepsIfNeeded.lua +2 -31
  11. package/dist/cjs/commands/moveToFinished-13.lua +14 -3
  12. package/dist/cjs/commands/removeJob-1.lua +26 -22
  13. package/dist/cjs/scripts/addJob-9.js +15 -7
  14. package/dist/cjs/scripts/addJob-9.js.map +1 -1
  15. package/dist/cjs/scripts/moveToFinished-13.js +101 -76
  16. package/dist/cjs/scripts/moveToFinished-13.js.map +1 -1
  17. package/dist/cjs/scripts/removeJob-1.js +36 -31
  18. package/dist/cjs/scripts/removeJob-1.js.map +1 -1
  19. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  20. package/dist/esm/classes/job.d.ts +5 -1
  21. package/dist/esm/classes/job.js +8 -2
  22. package/dist/esm/classes/job.js.map +1 -1
  23. package/dist/esm/classes/queue.d.ts +4 -1
  24. package/dist/esm/classes/queue.js +3 -2
  25. package/dist/esm/classes/queue.js.map +1 -1
  26. package/dist/esm/classes/scripts.d.ts +1 -1
  27. package/dist/esm/classes/scripts.js +6 -5
  28. package/dist/esm/classes/scripts.js.map +1 -1
  29. package/dist/esm/commands/includes/isLocked.lua +12 -10
  30. package/dist/esm/commands/includes/moveParentFromWaitingChildrenToFailed.lua +10 -0
  31. package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +42 -0
  32. package/dist/esm/commands/includes/updateParentDepsIfNeeded.lua +2 -31
  33. package/dist/esm/commands/moveToFinished-13.lua +14 -3
  34. package/dist/esm/commands/removeJob-1.lua +26 -22
  35. package/dist/esm/scripts/addJob-9.js +15 -7
  36. package/dist/esm/scripts/addJob-9.js.map +1 -1
  37. package/dist/esm/scripts/moveToFinished-13.js +101 -76
  38. package/dist/esm/scripts/moveToFinished-13.js.map +1 -1
  39. package/dist/esm/scripts/removeJob-1.js +36 -31
  40. package/dist/esm/scripts/removeJob-1.js.map +1 -1
  41. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  42. package/dist/esm/types/job-options.d.ts +8 -0
  43. package/package.json +1 -1
@@ -126,12 +126,13 @@ end
126
126
  Validate and move or add dependencies to parent.
127
127
  ]]
128
128
  -- Includes
129
- local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
130
- parentId, jobIdKey, returnvalue, timestamp )
131
- local processedSet = parentKey .. ":processed"
132
- rcall("HSET", processedSet, jobIdKey, returnvalue)
133
- local activeParent = rcall("ZSCORE", parentQueueKey .. ":waiting-children", parentId)
134
- if rcall("SCARD", parentDependenciesKey) == 0 and activeParent then
129
+ --[[
130
+ Validate and move parent to active if needed.
131
+ ]]
132
+ -- Includes
133
+ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
134
+ local isParentActive = rcall("ZSCORE", parentQueueKey .. ":waiting-children", parentId)
135
+ if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
135
136
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
136
137
  local parentWaitKey = parentQueueKey .. ":wait"
137
138
  local parentTarget, paused = getTargetQueueList(parentQueueKey .. ":meta", parentWaitKey,
@@ -154,10 +155,17 @@ local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDepende
154
155
  addJobWithPriority(parentWaitKey, parentQueueKey .. ":prioritized", priority, paused,
155
156
  parentId, parentQueueKey .. ":pc")
156
157
  end
157
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
158
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId,
159
+ "prev", "waiting-children")
158
160
  end
159
161
  end
160
162
  end
163
+ local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
164
+ parentId, jobIdKey, returnvalue, timestamp )
165
+ local processedSet = parentKey .. ":processed"
166
+ rcall("HSET", processedSet, jobIdKey, returnvalue)
167
+ moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
168
+ end
161
169
  if parentKey ~= nil then
162
170
  if rcall("EXISTS", parentKey) ~= 1 then
163
171
  return -5
@@ -1 +1 @@
1
- {"version":3,"file":"addJob-9.js","sourceRoot":"","sources":["../../../src/scripts/addJob-9.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqPf,CAAC;AACW,QAAA,MAAM,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"addJob-9.js","sourceRoot":"","sources":["../../../src/scripts/addJob-9.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6Pf,CAAC;AACW,QAAA,MAAM,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -37,6 +37,7 @@ const content = `--[[
37
37
  opts - attemptsMade
38
38
  opts - maxMetricsSize
39
39
  opts - fpof - fail parent on fail
40
+ opts - rdof - remove dependency on fail
40
41
  Output:
41
42
  0 OK
42
43
  -1 Missing key.
@@ -195,6 +196,87 @@ end
195
196
  --[[
196
197
  Function to recursively move from waitingChildren to failed.
197
198
  ]]
199
+ -- Includes
200
+ --[[
201
+ Validate and move parent to active if needed.
202
+ ]]
203
+ -- Includes
204
+ --[[
205
+ Add delay marker if needed.
206
+ ]]
207
+ -- Includes
208
+ local function addDelayMarkerIfNeeded(targetKey, delayedKey)
209
+ if rcall("LLEN", targetKey) == 0 then
210
+ local nextTimestamp = getNextDelayedTimestamp(delayedKey)
211
+ if nextTimestamp ~= nil then
212
+ rcall("LPUSH", targetKey, "0:" .. nextTimestamp)
213
+ end
214
+ end
215
+ end
216
+ --[[
217
+ Function to add job considering priority.
218
+ ]]
219
+ -- Includes
220
+ --[[
221
+ Function priority marker to wait if needed
222
+ in order to wake up our workers and to respect priority
223
+ order as much as possible
224
+ ]]
225
+ local function addPriorityMarkerIfNeeded(waitKey)
226
+ local waitLen = rcall("LLEN", waitKey)
227
+ if waitLen == 0 then
228
+ rcall("LPUSH", waitKey, "0:0")
229
+ end
230
+ end
231
+ local function addJobWithPriority(waitKey, prioritizedKey, priority, paused, jobId, priorityCounterKey)
232
+ local prioCounter = rcall("INCR", priorityCounterKey)
233
+ local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
234
+ rcall("ZADD", prioritizedKey, score, jobId)
235
+ if not paused then
236
+ addPriorityMarkerIfNeeded(waitKey)
237
+ end
238
+ end
239
+ --[[
240
+ Function to check for the meta.paused key to decide if we are paused or not
241
+ (since an empty list and !EXISTS are not really the same).
242
+ ]]
243
+ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
244
+ if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
245
+ return waitKey, false
246
+ else
247
+ return pausedKey, true
248
+ end
249
+ end
250
+ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
251
+ local isParentActive = rcall("ZSCORE", parentQueueKey .. ":waiting-children", parentId)
252
+ if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
253
+ rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
254
+ local parentWaitKey = parentQueueKey .. ":wait"
255
+ local parentTarget, paused = getTargetQueueList(parentQueueKey .. ":meta", parentWaitKey,
256
+ parentQueueKey .. ":paused")
257
+ local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
258
+ local priority = tonumber(jobAttributes[1]) or 0
259
+ local delay = tonumber(jobAttributes[2]) or 0
260
+ if delay > 0 then
261
+ local delayedTimestamp = tonumber(timestamp) + delay
262
+ local score = delayedTimestamp * 0x1000
263
+ local parentDelayedKey = parentQueueKey .. ":delayed"
264
+ rcall("ZADD", parentDelayedKey, score, parentId)
265
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId,
266
+ "delay", delayedTimestamp)
267
+ addDelayMarkerIfNeeded(parentTarget, parentDelayedKey)
268
+ else
269
+ if priority == 0 then
270
+ rcall("RPUSH", parentTarget, parentId)
271
+ else
272
+ addJobWithPriority(parentWaitKey, parentQueueKey .. ":prioritized", priority, paused,
273
+ parentId, parentQueueKey .. ":pc")
274
+ end
275
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId,
276
+ "prev", "waiting-children")
277
+ end
278
+ end
279
+ end
198
280
  local function moveParentFromWaitingChildrenToFailed( parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
199
281
  if rcall("ZREM", parentQueueKey .. ":waiting-children", parentId) == 1 then
200
282
  rcall("ZADD", parentQueueKey .. ":failed", timestamp, parentId)
@@ -213,6 +295,13 @@ local function moveParentFromWaitingChildrenToFailed( parentQueueKey, parentKey,
213
295
  parentKey,
214
296
  timestamp
215
297
  )
298
+ elseif parentData['rdof'] then
299
+ local grandParentKey = parentData['queueKey'] .. ':' .. parentData['id']
300
+ local grandParentDependenciesSet = grandParentKey .. ":dependencies"
301
+ if rcall("SREM", grandParentDependenciesSet, parentKey) == 1 then
302
+ moveParentToWaitIfNeeded(parentData['queueKey'], grandParentDependenciesSet,
303
+ grandParentKey, parentData['id'], timestamp)
304
+ end
216
305
  end
217
306
  end
218
307
  end
@@ -224,29 +313,6 @@ end
224
313
  'waiting'
225
314
  ]]
226
315
  -- Includes
227
- --[[
228
- Function to add job considering priority.
229
- ]]
230
- -- Includes
231
- --[[
232
- Function priority marker to wait if needed
233
- in order to wake up our workers and to respect priority
234
- order as much as possible
235
- ]]
236
- local function addPriorityMarkerIfNeeded(waitKey)
237
- local waitLen = rcall("LLEN", waitKey)
238
- if waitLen == 0 then
239
- rcall("LPUSH", waitKey, "0:0")
240
- end
241
- end
242
- local function addJobWithPriority(waitKey, prioritizedKey, priority, paused, jobId, priorityCounterKey)
243
- local prioCounter = rcall("INCR", priorityCounterKey)
244
- local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
245
- rcall("ZADD", prioritizedKey, score, jobId)
246
- if not paused then
247
- addPriorityMarkerIfNeeded(waitKey)
248
- end
249
- end
250
316
  -- Try to get as much as 1000 jobs at once
251
317
  local function promoteDelayedJobs(delayedKey, waitKey, targetKey, prioritizedKey,
252
318
  eventStreamKey, prefix, timestamp, paused, priorityCounterKey)
@@ -294,17 +360,6 @@ end
294
360
  local getJobKeyPrefix = function (jobKey, jobId)
295
361
  return string.sub(jobKey, 0, #jobKey - #jobId)
296
362
  end
297
- --[[
298
- Function to check for the meta.paused key to decide if we are paused or not
299
- (since an empty list and !EXISTS are not really the same).
300
- ]]
301
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
302
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
303
- return waitKey, false
304
- else
305
- return pausedKey, true
306
- end
307
- end
308
363
  local function moveParentToWait(parentPrefix, parentId, emitEvent)
309
364
  local parentTarget = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "wait", parentPrefix .. "paused")
310
365
  rcall("RPUSH", parentTarget, parentId)
@@ -408,49 +463,11 @@ end
408
463
  Validate and move or add dependencies to parent.
409
464
  ]]
410
465
  -- Includes
411
- --[[
412
- Add delay marker if needed.
413
- ]]
414
- -- Includes
415
- local function addDelayMarkerIfNeeded(targetKey, delayedKey)
416
- if rcall("LLEN", targetKey) == 0 then
417
- local nextTimestamp = getNextDelayedTimestamp(delayedKey)
418
- if nextTimestamp ~= nil then
419
- rcall("LPUSH", targetKey, "0:" .. nextTimestamp)
420
- end
421
- end
422
- end
423
466
  local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
424
467
  parentId, jobIdKey, returnvalue, timestamp )
425
468
  local processedSet = parentKey .. ":processed"
426
469
  rcall("HSET", processedSet, jobIdKey, returnvalue)
427
- local activeParent = rcall("ZSCORE", parentQueueKey .. ":waiting-children", parentId)
428
- if rcall("SCARD", parentDependenciesKey) == 0 and activeParent then
429
- rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
430
- local parentWaitKey = parentQueueKey .. ":wait"
431
- local parentTarget, paused = getTargetQueueList(parentQueueKey .. ":meta", parentWaitKey,
432
- parentQueueKey .. ":paused")
433
- local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
434
- local priority = tonumber(jobAttributes[1]) or 0
435
- local delay = tonumber(jobAttributes[2]) or 0
436
- if delay > 0 then
437
- local delayedTimestamp = tonumber(timestamp) + delay
438
- local score = delayedTimestamp * 0x1000
439
- local parentDelayedKey = parentQueueKey .. ":delayed"
440
- rcall("ZADD", parentDelayedKey, score, parentId)
441
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId,
442
- "delay", delayedTimestamp)
443
- addDelayMarkerIfNeeded(parentTarget, parentDelayedKey)
444
- else
445
- if priority == 0 then
446
- rcall("RPUSH", parentTarget, parentId)
447
- else
448
- addJobWithPriority(parentWaitKey, parentQueueKey .. ":prioritized", priority, paused,
449
- parentId, parentQueueKey .. ":pc")
450
- end
451
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
452
- end
453
- end
470
+ moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
454
471
  end
455
472
  local function getRateLimitTTL(maxJobs, rateLimiterKey)
456
473
  if maxJobs then
@@ -528,9 +545,17 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
528
545
  dependenciesSet, parentId, jobIdKey,
529
546
  ARGV[4], timestamp)
530
547
  end
531
- elseif opts['fpof'] then
532
- moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey,
533
- parentId, jobIdKey, timestamp)
548
+ else
549
+ if opts['fpof'] then
550
+ moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey,
551
+ parentId, jobIdKey, timestamp)
552
+ elseif opts['rdof'] then
553
+ local dependenciesSet = parentKey .. ":dependencies"
554
+ if rcall("SREM", dependenciesSet, jobIdKey) == 1 then
555
+ moveParentToWaitIfNeeded(parentQueueKey, dependenciesSet,
556
+ parentKey, parentId, timestamp)
557
+ end
558
+ end
534
559
  end
535
560
  end
536
561
  -- Remove job?
@@ -1 +1 @@
1
- {"version":3,"file":"moveToFinished-13.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-13.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwmBf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
1
+ {"version":3,"file":"moveToFinished-13.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-13.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAioBf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
@@ -7,6 +7,7 @@ const content = `--[[
7
7
  Input:
8
8
  KEYS[1] queue prefix
9
9
  ARGV[1] jobId
10
+ ARGV[2] remove children
10
11
  Events:
11
12
  'removed'
12
13
  ]]
@@ -28,21 +29,23 @@ end
28
29
  returns:
29
30
  boolean
30
31
  ]]
31
- local function isLocked( prefix, jobId)
32
+ local function isLocked( prefix, jobId, removeChildren)
32
33
  local jobKey = prefix .. jobId;
33
34
  -- Check if this job is locked
34
35
  local lockKey = jobKey .. ':lock'
35
36
  local lock = rcall("GET", lockKey)
36
37
  if not lock then
37
- local dependencies = rcall("SMEMBERS", jobKey .. ":dependencies")
38
- if (#dependencies > 0) then
39
- for i, childJobKey in ipairs(dependencies) do
40
- -- We need to get the jobId for this job.
41
- local childJobId = getJobIdFromKey(childJobKey)
42
- local childJobPrefix = getJobKeyPrefix(childJobKey, childJobId)
43
- local result = isLocked( childJobPrefix, childJobId )
44
- if result then
45
- return true
38
+ if removeChildren == "1" then
39
+ local dependencies = rcall("SMEMBERS", jobKey .. ":dependencies")
40
+ if (#dependencies > 0) then
41
+ for i, childJobKey in ipairs(dependencies) do
42
+ -- We need to get the jobId for this job.
43
+ local childJobId = getJobIdFromKey(childJobKey)
44
+ local childJobPrefix = getJobKeyPrefix(childJobKey, childJobId)
45
+ local result = isLocked( childJobPrefix, childJobId, removeChildren )
46
+ if result then
47
+ return true
48
+ end
46
49
  end
47
50
  end
48
51
  end
@@ -160,28 +163,30 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey)
160
163
  end
161
164
  end
162
165
  end
163
- local function removeJob( prefix, jobId, parentKey)
166
+ local function removeJob( prefix, jobId, parentKey, removeChildren)
164
167
  local jobKey = prefix .. jobId;
165
168
  removeParentDependencyKey(jobKey, false, parentKey)
166
- -- Check if this job has children
167
- -- If so, we are going to try to remove the children recursively in deep first way because
168
- -- if some job is locked we must exit with and error.
169
- --local countProcessed = rcall("HLEN", jobKey .. ":processed")
170
- local processed = rcall("HGETALL", jobKey .. ":processed")
171
- if (#processed > 0) then
172
- for i = 1, #processed, 2 do
173
- local childJobId = getJobIdFromKey(processed[i])
174
- local childJobPrefix = getJobKeyPrefix(processed[i], childJobId)
175
- removeJob( childJobPrefix, childJobId, jobKey )
169
+ if removeChildren == "1" then
170
+ -- Check if this job has children
171
+ -- If so, we are going to try to remove the children recursively in deep first way because
172
+ -- if some job is locked we must exit with and error.
173
+ --local countProcessed = rcall("HLEN", jobKey .. ":processed")
174
+ local processed = rcall("HGETALL", jobKey .. ":processed")
175
+ if (#processed > 0) then
176
+ for i = 1, #processed, 2 do
177
+ local childJobId = getJobIdFromKey(processed[i])
178
+ local childJobPrefix = getJobKeyPrefix(processed[i], childJobId)
179
+ removeJob( childJobPrefix, childJobId, jobKey, removeChildren )
180
+ end
176
181
  end
177
- end
178
- local dependencies = rcall("SMEMBERS", jobKey .. ":dependencies")
179
- if (#dependencies > 0) then
180
- for i, childJobKey in ipairs(dependencies) do
181
- -- We need to get the jobId for this job.
182
- local childJobId = getJobIdFromKey(childJobKey)
183
- local childJobPrefix = getJobKeyPrefix(childJobKey, childJobId)
184
- removeJob( childJobPrefix, childJobId, jobKey )
182
+ local dependencies = rcall("SMEMBERS", jobKey .. ":dependencies")
183
+ if (#dependencies > 0) then
184
+ for i, childJobKey in ipairs(dependencies) do
185
+ -- We need to get the jobId for this job.
186
+ local childJobId = getJobIdFromKey(childJobKey)
187
+ local childJobPrefix = getJobKeyPrefix(childJobKey, childJobId)
188
+ removeJob( childJobPrefix, childJobId, jobKey, removeChildren )
189
+ end
185
190
  end
186
191
  end
187
192
  local prev = removeJobFromAnyState(prefix, jobId)
@@ -196,8 +201,8 @@ local function removeJob( prefix, jobId, parentKey)
196
201
  rcall("XADD", prefix .. "events", "*", "event", "removed", "jobId", jobId, "prev", prev);
197
202
  end
198
203
  local prefix = KEYS[1]
199
- if not isLocked(prefix, ARGV[1]) then
200
- removeJob(prefix, ARGV[1])
204
+ if not isLocked(prefix, ARGV[1], ARGV[2]) then
205
+ removeJob(prefix, ARGV[1], nil, ARGV[2])
201
206
  return 1
202
207
  end
203
208
  return 0
@@ -1 +1 @@
1
- {"version":3,"file":"removeJob-1.js","sourceRoot":"","sources":["../../../src/scripts/removeJob-1.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwMf,CAAC;AACW,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"removeJob-1.js","sourceRoot":"","sources":["../../../src/scripts/removeJob-1.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6Mf,CAAC;AACW,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}