bullmq 5.47.2 → 5.48.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 (58) hide show
  1. package/dist/cjs/classes/async-fifo-queue.js.map +1 -1
  2. package/dist/cjs/classes/child.js.map +1 -1
  3. package/dist/cjs/classes/job-scheduler.js +1 -1
  4. package/dist/cjs/classes/job-scheduler.js.map +1 -1
  5. package/dist/cjs/classes/job.js +11 -0
  6. package/dist/cjs/classes/job.js.map +1 -1
  7. package/dist/cjs/classes/queue-base.js.map +1 -1
  8. package/dist/cjs/classes/queue-keys.js.map +1 -1
  9. package/dist/cjs/classes/repeat.js +1 -1
  10. package/dist/cjs/classes/repeat.js.map +1 -1
  11. package/dist/cjs/classes/scripts.js +12 -2
  12. package/dist/cjs/classes/scripts.js.map +1 -1
  13. package/dist/cjs/classes/worker.js.map +1 -1
  14. package/dist/cjs/commands/includes/isLocked.lua +1 -0
  15. package/dist/cjs/commands/includes/removeJobWithChildren.lua +93 -0
  16. package/dist/cjs/commands/removeJob-3.lua +15 -72
  17. package/dist/cjs/commands/removeUnprocessedChildren-2.lua +31 -0
  18. package/dist/cjs/scripts/index.js +1 -0
  19. package/dist/cjs/scripts/index.js.map +1 -1
  20. package/dist/cjs/scripts/removeJob-3.js +83 -55
  21. package/dist/cjs/scripts/removeJob-3.js.map +1 -1
  22. package/dist/cjs/scripts/removeUnprocessedChildren-2.js +332 -0
  23. package/dist/cjs/scripts/removeUnprocessedChildren-2.js.map +1 -0
  24. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  25. package/dist/cjs/version.js +1 -1
  26. package/dist/esm/classes/async-fifo-queue.js.map +1 -1
  27. package/dist/esm/classes/child.js.map +1 -1
  28. package/dist/esm/classes/job-scheduler.js +1 -1
  29. package/dist/esm/classes/job-scheduler.js.map +1 -1
  30. package/dist/esm/classes/job.d.ts +9 -1
  31. package/dist/esm/classes/job.js +11 -0
  32. package/dist/esm/classes/job.js.map +1 -1
  33. package/dist/esm/classes/queue-base.js.map +1 -1
  34. package/dist/esm/classes/queue-keys.js.map +1 -1
  35. package/dist/esm/classes/repeat.js +1 -1
  36. package/dist/esm/classes/repeat.js.map +1 -1
  37. package/dist/esm/classes/scripts.d.ts +1 -0
  38. package/dist/esm/classes/scripts.js +12 -2
  39. package/dist/esm/classes/scripts.js.map +1 -1
  40. package/dist/esm/classes/worker.js.map +1 -1
  41. package/dist/esm/commands/includes/isLocked.lua +1 -0
  42. package/dist/esm/commands/includes/removeJobWithChildren.lua +93 -0
  43. package/dist/esm/commands/removeJob-3.lua +15 -72
  44. package/dist/esm/commands/removeUnprocessedChildren-2.lua +31 -0
  45. package/dist/esm/interfaces/queue-options.d.ts +1 -1
  46. package/dist/esm/interfaces/repeat-options.d.ts +1 -1
  47. package/dist/esm/scripts/index.d.ts +1 -0
  48. package/dist/esm/scripts/index.js +1 -0
  49. package/dist/esm/scripts/index.js.map +1 -1
  50. package/dist/esm/scripts/removeJob-3.js +83 -55
  51. package/dist/esm/scripts/removeJob-3.js.map +1 -1
  52. package/dist/esm/scripts/removeUnprocessedChildren-2.d.ts +5 -0
  53. package/dist/esm/scripts/removeUnprocessedChildren-2.js +329 -0
  54. package/dist/esm/scripts/removeUnprocessedChildren-2.js.map +1 -0
  55. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  56. package/dist/esm/version.d.ts +1 -1
  57. package/dist/esm/version.js +1 -1
  58. package/package.json +1 -1
@@ -0,0 +1,93 @@
1
+ --[[
2
+ Remove a job from all the statuses it may be in as well as all its data,
3
+ including its children. Active children can be ignored.
4
+
5
+ Events:
6
+ 'removed'
7
+ ]]
8
+
9
+ local rcall = redis.call
10
+
11
+ -- Includes
12
+ --- @include "destructureJobKey"
13
+ --- @include "getOrSetMaxEvents"
14
+ --- @include "isJobSchedulerJob"
15
+ --- @include "removeDeduplicationKey"
16
+ --- @include "removeJobFromAnyState"
17
+ --- @include "removeJobKeys"
18
+ --- @include "removeParentDependencyKey"
19
+ --- @include "isLocked"
20
+
21
+ local removeJobChildren
22
+ local removeJobWithChildren
23
+
24
+ removeJobChildren = function(prefix, meta, jobKey, options)
25
+ -- Check if this job has children
26
+ -- If so, we are going to try to remove the children recursively in a depth-first way
27
+ -- because if some job is locked, we must exit with an error.
28
+
29
+ if not options.ignoreProcessed then
30
+ local processed = rcall("HGETALL", jobKey .. ":processed")
31
+ if #processed > 0 then
32
+ for i = 1, #processed, 2 do
33
+ local childJobId = getJobIdFromKey(processed[i])
34
+ local childJobPrefix = getJobKeyPrefix(processed[i], childJobId)
35
+ removeJobWithChildren(childJobPrefix, meta, childJobId, jobKey, options)
36
+ end
37
+ end
38
+
39
+ local failed = rcall("HGETALL", jobKey .. ":failed")
40
+ if #failed > 0 then
41
+ for i = 1, #failed, 2 do
42
+ local childJobId = getJobIdFromKey(failed[i])
43
+ local childJobPrefix = getJobKeyPrefix(failed[i], childJobId)
44
+ removeJobWithChildren(childJobPrefix, meta, childJobId, jobKey, options)
45
+ end
46
+ end
47
+
48
+ local unsuccessful = rcall("ZRANGE", jobKey .. ":unsuccessful", 0, -1)
49
+ if #unsuccessful > 0 then
50
+ for i = 1, #unsuccessful, 1 do
51
+ local childJobId = getJobIdFromKey(unsuccessful[i])
52
+ local childJobPrefix = getJobKeyPrefix(unsuccessful[i], childJobId)
53
+ removeJobWithChildren(childJobPrefix, meta, childJobId, jobKey, options)
54
+ end
55
+ end
56
+ end
57
+
58
+ local dependencies = rcall("SMEMBERS", jobKey .. ":dependencies")
59
+ if #dependencies > 0 then
60
+ for i, childJobKey in ipairs(dependencies) do
61
+ local childJobId = getJobIdFromKey(childJobKey)
62
+ local childJobPrefix = getJobKeyPrefix(childJobKey, childJobId)
63
+ removeJobWithChildren(childJobPrefix, meta, childJobId, jobKey, options)
64
+ end
65
+ end
66
+ end
67
+
68
+ removeJobWithChildren = function(prefix, meta, jobId, parentKey, options)
69
+ local jobKey = prefix .. jobId
70
+
71
+ if options.ignoreLocked then
72
+ if isLocked(prefix, jobId) then
73
+ return
74
+ end
75
+ end
76
+
77
+ -- Check if job is in the failed zset
78
+ local failedSet = prefix .. "failed"
79
+ if not (options.ignoreProcessed and rcall("ZSCORE", failedSet, jobId)) then
80
+ removeParentDependencyKey(jobKey, false, parentKey, nil)
81
+
82
+ if options.removeChildren then
83
+ removeJobChildren(prefix, meta, jobKey, options)
84
+ end
85
+
86
+ local prev = removeJobFromAnyState(prefix, jobId)
87
+ removeDeduplicationKey(prefix, jobKey)
88
+ if removeJobKeys(jobKey) > 0 then
89
+ local maxEvents = getOrSetMaxEvents(meta)
90
+ rcall("XADD", prefix .. "events", "MAXLEN", "~", maxEvents, "*", "event", "removed", "jobId", jobId, "prev", prev)
91
+ end
92
+ end
93
+ end
@@ -1,14 +1,16 @@
1
1
  --[[
2
- Remove a job from all the queues it may be in as well as all its data.
2
+ Remove a job from all the statuses it may be in as well as all its data.
3
3
  In order to be able to remove a job, it cannot be active.
4
4
 
5
5
  Input:
6
- KEYS[1] queue prefix
6
+ KEYS[1] jobKey
7
7
  KEYS[2] meta key
8
8
  KEYS[3] repeat key
9
9
 
10
10
  ARGV[1] jobId
11
11
  ARGV[2] remove children
12
+ ARGV[3] queue prefix
13
+
12
14
 
13
15
  Events:
14
16
  'removed'
@@ -17,80 +19,15 @@
17
19
  local rcall = redis.call
18
20
 
19
21
  -- Includes
20
- --- @include "includes/destructureJobKey"
21
- --- @include "includes/getOrSetMaxEvents"
22
22
  --- @include "includes/isJobSchedulerJob"
23
23
  --- @include "includes/isLocked"
24
- --- @include "includes/removeDeduplicationKey"
25
- --- @include "includes/removeJobFromAnyState"
26
- --- @include "includes/removeJobKeys"
27
- --- @include "includes/removeParentDependencyKey"
28
-
29
- local function removeJob(prefix, jobId, parentKey, removeChildren)
30
- local jobKey = prefix .. jobId;
31
-
32
- removeParentDependencyKey(jobKey, false, parentKey, nil)
33
-
34
- if removeChildren == "1" then
35
- -- Check if this job has children
36
- -- If so, we are going to try to remove the children recursively in deep first way because
37
- -- if some job is locked we must exit with and error.
38
- -- local countProcessed = rcall("HLEN", jobKey .. ":processed")
39
- local processed = rcall("HGETALL", jobKey .. ":processed")
40
-
41
- if (#processed > 0) then
42
- for i = 1, #processed, 2 do
43
- local childJobId = getJobIdFromKey(processed[i])
44
- local childJobPrefix = getJobKeyPrefix(processed[i], childJobId)
45
- removeJob(childJobPrefix, childJobId, jobKey, removeChildren)
46
- end
47
- end
48
-
49
- local dependencies = rcall("SMEMBERS", jobKey .. ":dependencies")
50
- if (#dependencies > 0) then
51
- for i, childJobKey in ipairs(dependencies) do
52
- -- We need to get the jobId for this job.
53
- local childJobId = getJobIdFromKey(childJobKey)
54
- local childJobPrefix = getJobKeyPrefix(childJobKey, childJobId)
55
- removeJob(childJobPrefix, childJobId, jobKey, removeChildren)
56
- end
57
- end
58
-
59
- local failed = rcall("HGETALL", jobKey .. ":failed")
24
+ --- @include "includes/removeJobWithChildren"
60
25
 
61
- if (#failed > 0) then
62
- for i = 1, #failed, 2 do
63
- local childJobId = getJobIdFromKey(failed[i])
64
- local childJobPrefix = getJobKeyPrefix(failed[i], childJobId)
65
- removeJob(childJobPrefix, childJobId, jobKey, removeChildren)
66
- end
67
- end
68
-
69
- local unsuccessful = rcall("ZRANGE", jobKey .. ":unsuccessful", 0, -1)
70
-
71
- if (#unsuccessful > 0) then
72
- for i = 1, #unsuccessful, 1 do
73
- local childJobId = getJobIdFromKey(unsuccessful[i])
74
- local childJobPrefix = getJobKeyPrefix(unsuccessful[i], childJobId)
75
- removeJob(childJobPrefix, childJobId, jobKey, removeChildren)
76
- end
77
- end
78
- end
79
-
80
- local prev = removeJobFromAnyState(prefix, jobId)
81
-
82
- removeDeduplicationKey(prefix, jobKey)
83
- if removeJobKeys(jobKey) > 0 then
84
- local maxEvents = getOrSetMaxEvents(KEYS[2])
85
- rcall("XADD", prefix .. "events", "MAXLEN", "~", maxEvents, "*", "event", "removed", "jobId", jobId, "prev",
86
- prev)
87
- end
88
- end
89
-
90
- local prefix = KEYS[1]
91
26
  local jobId = ARGV[1]
92
27
  local shouldRemoveChildren = ARGV[2]
93
- local jobKey = prefix .. jobId
28
+ local prefix = ARGV[3]
29
+ local jobKey = KEYS[1]
30
+ local meta = KEYS[2]
94
31
  local repeatKey = KEYS[3]
95
32
 
96
33
  if isJobSchedulerJob(jobId, jobKey, repeatKey) then
@@ -98,7 +35,13 @@ if isJobSchedulerJob(jobId, jobKey, repeatKey) then
98
35
  end
99
36
 
100
37
  if not isLocked(prefix, jobId, shouldRemoveChildren) then
101
- removeJob(prefix, jobId, nil, shouldRemoveChildren)
38
+ local options = {
39
+ removeChildren = shouldRemoveChildren == "1",
40
+ ignoreProcessed = false,
41
+ ignoreLocked = false
42
+ }
43
+
44
+ removeJobWithChildren(prefix, meta, jobId, nil, options)
102
45
  return 1
103
46
  end
104
47
  return 0
@@ -0,0 +1,31 @@
1
+ --[[
2
+ Remove a job from all the statuses it may be in as well as all its data.
3
+ In order to be able to remove a job, it cannot be active.
4
+
5
+ Input:
6
+ KEYS[1] jobKey
7
+ KEYS[2] meta key
8
+
9
+ ARGV[1] prefix
10
+ ARGV[2] jobId
11
+
12
+ Events:
13
+ 'removed' for every children removed
14
+ ]]
15
+
16
+ -- Includes
17
+ --- @include "includes/removeJobWithChildren"
18
+
19
+ local prefix = ARGV[1]
20
+ local jobId = ARGV[2]
21
+
22
+ local jobKey = KEYS[1]
23
+ local metaKey = KEYS[2]
24
+
25
+ local options = {
26
+ removeChildren = "1",
27
+ ignoreProcessed = true,
28
+ ignoreLocked = true
29
+ }
30
+
31
+ removeJobChildren(prefix, metaKey, jobKey, options)
@@ -16,7 +16,7 @@ export interface QueueBaseOptions {
16
16
  connection: ConnectionOptions;
17
17
  /**
18
18
  * Denotes commands should retry indefinitely.
19
- * @deprecated
19
+ * @deprecated not in use anymore.
20
20
  */
21
21
  blockingConnection?: boolean;
22
22
  /**
@@ -45,7 +45,7 @@ export interface RepeatOptions extends Omit<ParserOptions, 'iterator'> {
45
45
  prevMillis?: number;
46
46
  /**
47
47
  * Internal property to store de job id
48
- * @deprecated
48
+ * @deprecated not in use anymore
49
49
  */
50
50
  jobId?: string;
51
51
  }
@@ -38,6 +38,7 @@ export * from './removeChildDependency-1';
38
38
  export * from './removeJob-3';
39
39
  export * from './removeJobScheduler-3';
40
40
  export * from './removeRepeatable-3';
41
+ export * from './removeUnprocessedChildren-2';
41
42
  export * from './reprocessJob-8';
42
43
  export * from './retryJob-11';
43
44
  export * from './saveStacktrace-1';
@@ -38,6 +38,7 @@ export * from './removeChildDependency-1';
38
38
  export * from './removeJob-3';
39
39
  export * from './removeJobScheduler-3';
40
40
  export * from './removeRepeatable-3';
41
+ export * from './removeUnprocessedChildren-2';
41
42
  export * from './reprocessJob-8';
42
43
  export * from './retryJob-11';
43
44
  export * from './saveStacktrace-1';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC"}
@@ -1,38 +1,18 @@
1
1
  const content = `--[[
2
- Remove a job from all the queues it may be in as well as all its data.
2
+ Remove a job from all the statuses it may be in as well as all its data.
3
3
  In order to be able to remove a job, it cannot be active.
4
4
  Input:
5
- KEYS[1] queue prefix
5
+ KEYS[1] jobKey
6
6
  KEYS[2] meta key
7
7
  KEYS[3] repeat key
8
8
  ARGV[1] jobId
9
9
  ARGV[2] remove children
10
+ ARGV[3] queue prefix
10
11
  Events:
11
12
  'removed'
12
13
  ]]
13
14
  local rcall = redis.call
14
15
  -- Includes
15
- --[[
16
- Functions to destructure job key.
17
- Just a bit of warning, these functions may be a bit slow and affect performance significantly.
18
- ]]
19
- local getJobIdFromKey = function (jobKey)
20
- return string.match(jobKey, ".*:(.*)")
21
- end
22
- local getJobKeyPrefix = function (jobKey, jobId)
23
- return string.sub(jobKey, 0, #jobKey - #jobId)
24
- end
25
- --[[
26
- Function to get max events value or set by default 10000.
27
- ]]
28
- local function getOrSetMaxEvents(metaKey)
29
- local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
30
- if not maxEvents then
31
- maxEvents = 10000
32
- rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
33
- end
34
- return maxEvents
35
- end
36
16
  --[[
37
17
  Function to check if the job belongs to a job scheduler and
38
18
  current delayed job matches with jobId
@@ -54,6 +34,16 @@ end
54
34
  returns:
55
35
  boolean
56
36
  ]]
37
+ --[[
38
+ Functions to destructure job key.
39
+ Just a bit of warning, these functions may be a bit slow and affect performance significantly.
40
+ ]]
41
+ local getJobIdFromKey = function (jobKey)
42
+ return string.match(jobKey, ".*:(.*)")
43
+ end
44
+ local getJobKeyPrefix = function (jobKey, jobId)
45
+ return string.sub(jobKey, 0, #jobKey - #jobId)
46
+ end
57
47
  local function isLocked( prefix, jobId, removeChildren)
58
48
  local jobKey = prefix .. jobId;
59
49
  -- Check if this job is locked
@@ -78,6 +68,25 @@ local function isLocked( prefix, jobId, removeChildren)
78
68
  end
79
69
  return true
80
70
  end
71
+ --[[
72
+ Remove a job from all the statuses it may be in as well as all its data,
73
+ including its children. Active children can be ignored.
74
+ Events:
75
+ 'removed'
76
+ ]]
77
+ local rcall = redis.call
78
+ -- Includes
79
+ --[[
80
+ Function to get max events value or set by default 10000.
81
+ ]]
82
+ local function getOrSetMaxEvents(metaKey)
83
+ local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
84
+ if not maxEvents then
85
+ maxEvents = 10000
86
+ rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
87
+ end
88
+ return maxEvents
89
+ end
81
90
  --[[
82
91
  Function to remove deduplication key.
83
92
  ]]
@@ -241,66 +250,85 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
241
250
  end
242
251
  return false
243
252
  end
244
- local function removeJob(prefix, jobId, parentKey, removeChildren)
245
- local jobKey = prefix .. jobId;
246
- removeParentDependencyKey(jobKey, false, parentKey, nil)
247
- if removeChildren == "1" then
248
- -- Check if this job has children
249
- -- If so, we are going to try to remove the children recursively in deep first way because
250
- -- if some job is locked we must exit with and error.
251
- -- local countProcessed = rcall("HLEN", jobKey .. ":processed")
253
+ local removeJobChildren
254
+ local removeJobWithChildren
255
+ removeJobChildren = function(prefix, meta, jobKey, options)
256
+ -- Check if this job has children
257
+ -- If so, we are going to try to remove the children recursively in a depth-first way
258
+ -- because if some job is locked, we must exit with an error.
259
+ if not options.ignoreProcessed then
252
260
  local processed = rcall("HGETALL", jobKey .. ":processed")
253
- if (#processed > 0) then
261
+ if #processed > 0 then
254
262
  for i = 1, #processed, 2 do
255
263
  local childJobId = getJobIdFromKey(processed[i])
256
264
  local childJobPrefix = getJobKeyPrefix(processed[i], childJobId)
257
- removeJob(childJobPrefix, childJobId, jobKey, removeChildren)
258
- end
259
- end
260
- local dependencies = rcall("SMEMBERS", jobKey .. ":dependencies")
261
- if (#dependencies > 0) then
262
- for i, childJobKey in ipairs(dependencies) do
263
- -- We need to get the jobId for this job.
264
- local childJobId = getJobIdFromKey(childJobKey)
265
- local childJobPrefix = getJobKeyPrefix(childJobKey, childJobId)
266
- removeJob(childJobPrefix, childJobId, jobKey, removeChildren)
265
+ removeJobWithChildren(childJobPrefix, meta, childJobId, jobKey, options)
267
266
  end
268
267
  end
269
268
  local failed = rcall("HGETALL", jobKey .. ":failed")
270
- if (#failed > 0) then
269
+ if #failed > 0 then
271
270
  for i = 1, #failed, 2 do
272
271
  local childJobId = getJobIdFromKey(failed[i])
273
272
  local childJobPrefix = getJobKeyPrefix(failed[i], childJobId)
274
- removeJob(childJobPrefix, childJobId, jobKey, removeChildren)
273
+ removeJobWithChildren(childJobPrefix, meta, childJobId, jobKey, options)
275
274
  end
276
275
  end
277
276
  local unsuccessful = rcall("ZRANGE", jobKey .. ":unsuccessful", 0, -1)
278
- if (#unsuccessful > 0) then
277
+ if #unsuccessful > 0 then
279
278
  for i = 1, #unsuccessful, 1 do
280
279
  local childJobId = getJobIdFromKey(unsuccessful[i])
281
280
  local childJobPrefix = getJobKeyPrefix(unsuccessful[i], childJobId)
282
- removeJob(childJobPrefix, childJobId, jobKey, removeChildren)
281
+ removeJobWithChildren(childJobPrefix, meta, childJobId, jobKey, options)
283
282
  end
284
283
  end
285
284
  end
286
- local prev = removeJobFromAnyState(prefix, jobId)
287
- removeDeduplicationKey(prefix, jobKey)
288
- if removeJobKeys(jobKey) > 0 then
289
- local maxEvents = getOrSetMaxEvents(KEYS[2])
290
- rcall("XADD", prefix .. "events", "MAXLEN", "~", maxEvents, "*", "event", "removed", "jobId", jobId, "prev",
291
- prev)
285
+ local dependencies = rcall("SMEMBERS", jobKey .. ":dependencies")
286
+ if #dependencies > 0 then
287
+ for i, childJobKey in ipairs(dependencies) do
288
+ local childJobId = getJobIdFromKey(childJobKey)
289
+ local childJobPrefix = getJobKeyPrefix(childJobKey, childJobId)
290
+ removeJobWithChildren(childJobPrefix, meta, childJobId, jobKey, options)
291
+ end
292
+ end
293
+ end
294
+ removeJobWithChildren = function(prefix, meta, jobId, parentKey, options)
295
+ local jobKey = prefix .. jobId
296
+ if options.ignoreLocked then
297
+ if isLocked(prefix, jobId) then
298
+ return
299
+ end
300
+ end
301
+ -- Check if job is in the failed zset
302
+ local failedSet = prefix .. "failed"
303
+ if not (options.ignoreProcessed and rcall("ZSCORE", failedSet, jobId)) then
304
+ removeParentDependencyKey(jobKey, false, parentKey, nil)
305
+ if options.removeChildren then
306
+ removeJobChildren(prefix, meta, jobKey, options)
307
+ end
308
+ local prev = removeJobFromAnyState(prefix, jobId)
309
+ removeDeduplicationKey(prefix, jobKey)
310
+ if removeJobKeys(jobKey) > 0 then
311
+ local maxEvents = getOrSetMaxEvents(meta)
312
+ rcall("XADD", prefix .. "events", "MAXLEN", "~", maxEvents, "*", "event", "removed", "jobId", jobId, "prev", prev)
313
+ end
292
314
  end
293
315
  end
294
- local prefix = KEYS[1]
295
316
  local jobId = ARGV[1]
296
317
  local shouldRemoveChildren = ARGV[2]
297
- local jobKey = prefix .. jobId
318
+ local prefix = ARGV[3]
319
+ local jobKey = KEYS[1]
320
+ local meta = KEYS[2]
298
321
  local repeatKey = KEYS[3]
299
322
  if isJobSchedulerJob(jobId, jobKey, repeatKey) then
300
323
  return -8
301
324
  end
302
325
  if not isLocked(prefix, jobId, shouldRemoveChildren) then
303
- removeJob(prefix, jobId, nil, shouldRemoveChildren)
326
+ local options = {
327
+ removeChildren = shouldRemoveChildren == "1",
328
+ ignoreProcessed = false,
329
+ ignoreLocked = false
330
+ }
331
+ removeJobWithChildren(prefix, meta, jobId, nil, options)
304
332
  return 1
305
333
  end
306
334
  return 0
@@ -1 +1 @@
1
- {"version":3,"file":"removeJob-3.js","sourceRoot":"","sources":["../../../src/scripts/removeJob-3.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkTf,CAAC;AACF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"removeJob-3.js","sourceRoot":"","sources":["../../../src/scripts/removeJob-3.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Uf,CAAC;AACF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const removeUnprocessedChildren: {
2
+ name: string;
3
+ content: string;
4
+ keys: number;
5
+ };