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
@@ -36,13 +36,12 @@ local timestamp = ARGV[3]
36
36
  local jobId = ARGV[4]
37
37
 
38
38
  --- Includes
39
- --- @include "includes/moveParentFromWaitingChildrenToFailed"
40
- --- @include "includes/moveParentToWaitIfNeeded"
41
- --- @include "includes/removeDeduplicationKeyIfNeeded"
39
+ --- @include "includes/moveChildFromDependenciesIfNeeded"
40
+ --- @include "includes/removeDeduplicationKeyIfNeededOnFinalization"
42
41
  --- @include "includes/removeJobsOnFail"
43
42
  --- @include "includes/removeLock"
44
43
 
45
- local function moveToWaitingChildren (activeKey, waitingChildrenKey, jobId,
44
+ local function moveToWaitingChildren(activeKey, waitingChildrenKey, jobId,
46
45
  timestamp)
47
46
  local score = tonumber(timestamp)
48
47
 
@@ -62,7 +61,7 @@ if rcall("EXISTS", jobKey) == 1 then
62
61
  -- TODO: refactor this logic in an include later
63
62
  local jobAttributes = rcall("HMGET", jobKey, "parent", "deid", "opts")
64
63
 
65
- removeDeduplicationKeyIfNeeded(ARGV[5], jobAttributes[2])
64
+ removeDeduplicationKeyIfNeededOnFinalization(ARGV[5], jobAttributes[2], jobId)
66
65
 
67
66
  local failedReason = "children are failed"
68
67
  rcall("ZADD", failedKey, timestamp, jobId)
@@ -74,33 +73,7 @@ if rcall("EXISTS", jobKey) == 1 then
74
73
  local rawOpts = jobAttributes[3]
75
74
  local opts = cjson.decode(rawOpts)
76
75
 
77
- if rawParentData ~= false then
78
- if opts['fpof'] then
79
- local parentData = cjson.decode(rawParentData)
80
- local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
81
- local parentUnsuccesssful = parentKey .. ":unsuccessful"
82
- rcall("ZADD", parentUnsuccesssful, timestamp, jobKey)
83
- moveParentFromWaitingChildrenToFailed(
84
- parentData['queueKey'],
85
- parentData['queueKey'] .. ':' .. parentData['id'],
86
- parentData['id'],
87
- jobKey,
88
- timestamp
89
- )
90
- elseif opts['idof'] or opts['rdof'] then
91
- local parentData = cjson.decode(rawParentData)
92
- local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
93
- local dependenciesSet = parentKey .. ":dependencies"
94
- if rcall("SREM", dependenciesSet, jobKey) == 1 then
95
- moveParentToWaitIfNeeded(parentData['queueKey'], dependenciesSet,
96
- parentKey, parentData['id'], timestamp)
97
- if opts['idof'] then
98
- local failedSet = parentKey .. ":failed"
99
- rcall("HSET", failedSet, jobKey, failedReason)
100
- end
101
- end
102
- end
103
- end
76
+ moveChildFromDependenciesIfNeeded(rawParentData, jobKey, failedReason, timestamp)
104
77
 
105
78
  removeJobsOnFail(ARGV[5], failedKey, jobId, opts, timestamp)
106
79
 
@@ -1,14 +1,15 @@
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
12
13
 
13
14
  Events:
14
15
  'removed'
@@ -17,80 +18,15 @@
17
18
  local rcall = redis.call
18
19
 
19
20
  -- Includes
20
- --- @include "includes/destructureJobKey"
21
- --- @include "includes/getOrSetMaxEvents"
22
21
  --- @include "includes/isJobSchedulerJob"
23
22
  --- @include "includes/isLocked"
24
- --- @include "includes/removeDeduplicationKey"
25
- --- @include "includes/removeJobFromAnyState"
26
- --- @include "includes/removeJobKeys"
27
- --- @include "includes/removeParentDependencyKey"
23
+ --- @include "includes/removeJobWithChildren"
28
24
 
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")
60
-
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
25
  local jobId = ARGV[1]
92
26
  local shouldRemoveChildren = ARGV[2]
93
- local jobKey = prefix .. jobId
27
+ local prefix = ARGV[3]
28
+ local jobKey = KEYS[1]
29
+ local meta = KEYS[2]
94
30
  local repeatKey = KEYS[3]
95
31
 
96
32
  if isJobSchedulerJob(jobId, jobKey, repeatKey) then
@@ -98,7 +34,13 @@ if isJobSchedulerJob(jobId, jobKey, repeatKey) then
98
34
  end
99
35
 
100
36
  if not isLocked(prefix, jobId, shouldRemoveChildren) then
101
- removeJob(prefix, jobId, nil, shouldRemoveChildren)
37
+ local options = {
38
+ removeChildren = shouldRemoveChildren == "1",
39
+ ignoreProcessed = false,
40
+ ignoreLocked = false
41
+ }
42
+
43
+ removeJobWithChildren(prefix, meta, jobId, nil, options)
102
44
  return 1
103
45
  end
104
46
  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)
@@ -25,7 +25,8 @@
25
25
 
26
26
  Output:
27
27
  next delayed job id - OK
28
- ]] local rcall = redis.call
28
+ ]]
29
+ local rcall = redis.call
29
30
  local repeatKey = KEYS[1]
30
31
  local delayedKey = KEYS[2]
31
32
  local waitKey = KEYS[3]
@@ -48,37 +49,42 @@ local nextDelayedJobKey = schedulerKey .. ":" .. nextMillis
48
49
 
49
50
  -- Validate that scheduler exists.
50
51
  local prevMillis = rcall("ZSCORE", repeatKey, jobSchedulerId)
51
- if prevMillis ~= false then
52
+ if prevMillis then
52
53
  local currentDelayedJobId = "repeat:" .. jobSchedulerId .. ":" .. prevMillis
53
54
 
54
- if producerId == currentDelayedJobId and rcall("EXISTS", nextDelayedJobKey) ~= 1 then
55
- local schedulerAttributes = rcall("HMGET", schedulerKey, "name", "data")
56
-
57
- rcall("ZADD", repeatKey, nextMillis, jobSchedulerId)
58
- rcall("HINCRBY", schedulerKey, "ic", 1)
59
-
55
+ if producerId == currentDelayedJobId then
60
56
  local eventsKey = KEYS[9]
61
57
  local maxEvents = getOrSetMaxEvents(metaKey)
62
58
 
63
- rcall("INCR", KEYS[8])
59
+ if rcall("EXISTS", nextDelayedJobKey) ~= 1 then
60
+ local schedulerAttributes = rcall("HMGET", schedulerKey, "name", "data")
64
61
 
65
- -- TODO: remove this workaround in next breaking change,
66
- -- all job-schedulers must save job data
67
- local templateData = schedulerAttributes[2] or ARGV[3]
62
+ rcall("ZADD", repeatKey, nextMillis, jobSchedulerId)
63
+ rcall("HINCRBY", schedulerKey, "ic", 1)
68
64
 
69
- if templateData and templateData ~= '{}' then
70
- rcall("HSET", schedulerKey, "data", templateData)
71
- end
65
+ rcall("INCR", KEYS[8])
72
66
 
73
- addJobFromScheduler(nextDelayedJobKey, nextDelayedJobId, ARGV[4], waitKey, pausedKey,
74
- KEYS[12], metaKey, prioritizedKey, KEYS[10], delayedKey, KEYS[7], eventsKey,
75
- schedulerAttributes[1], maxEvents, ARGV[5], templateData or '{}', jobSchedulerId)
67
+ -- TODO: remove this workaround in next breaking change,
68
+ -- all job-schedulers must save job data
69
+ local templateData = schedulerAttributes[2] or ARGV[3]
76
70
 
77
- -- TODO: remove this workaround in next breaking change
78
- if KEYS[11] ~= "" then
79
- rcall("HSET", KEYS[11], "nrjid", nextDelayedJobId)
80
- end
71
+ if templateData and templateData ~= '{}' then
72
+ rcall("HSET", schedulerKey, "data", templateData)
73
+ end
81
74
 
82
- return nextDelayedJobId .. "" -- convert to string
75
+ addJobFromScheduler(nextDelayedJobKey, nextDelayedJobId, ARGV[4], waitKey, pausedKey,
76
+ KEYS[12], metaKey, prioritizedKey, KEYS[10], delayedKey, KEYS[7], eventsKey,
77
+ schedulerAttributes[1], maxEvents, ARGV[5], templateData or '{}', jobSchedulerId)
78
+
79
+ -- TODO: remove this workaround in next breaking change
80
+ if KEYS[11] ~= "" then
81
+ rcall("HSET", KEYS[11], "nrjid", nextDelayedJobId)
82
+ end
83
+
84
+ return nextDelayedJobId .. "" -- convert to string
85
+ else
86
+ rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
87
+ "duplicated", "jobId", nextDelayedJobId)
88
+ end
83
89
  end
84
90
  end
@@ -1,11 +1,11 @@
1
- import { RedisJobOptions } from '../types';
1
+ import { JobProgress, RedisJobOptions } from '../types';
2
2
  import { ParentKeys } from './parent';
3
3
  export interface JobJson {
4
4
  id: string;
5
5
  name: string;
6
6
  data: string;
7
7
  opts: RedisJobOptions;
8
- progress: number | object;
8
+ progress: JobProgress;
9
9
  attemptsMade: number;
10
10
  attemptsStarted: number;
11
11
  finishedOn?: number;
@@ -21,6 +21,7 @@ export interface JobJson {
21
21
  debounceId?: string;
22
22
  deduplicationId?: string;
23
23
  processedBy?: string;
24
+ stalledCounter: number;
24
25
  }
25
26
  export interface JobJsonRaw {
26
27
  id: string;
@@ -43,6 +44,8 @@ export interface JobJsonRaw {
43
44
  rjk?: string;
44
45
  nrjid?: string;
45
46
  atm?: string;
47
+ defa?: string;
48
+ stc?: string;
46
49
  ats?: string;
47
50
  pb?: string;
48
51
  }
@@ -1,4 +1,4 @@
1
- import { JobsOptions, JobJsonSandbox } from '../types';
1
+ import { JobsOptions, JobJsonSandbox, JobProgress } from '../types';
2
2
  import { JobJson } from './job-json';
3
3
  import { ParentKeys } from './parent';
4
4
  export type BulkJobOptions = Omit<JobsOptions, 'repeat'>;
@@ -15,15 +15,33 @@ export interface MoveToWaitingChildrenOpts {
15
15
  queue: string;
16
16
  };
17
17
  }
18
+ export interface DependencyOpts {
19
+ /**
20
+ * Cursor value to be passed for pagination
21
+ */
22
+ cursor?: number;
23
+ /**
24
+ * Max quantity of jobs to be retrieved
25
+ */
26
+ count?: number;
27
+ }
18
28
  export interface DependenciesOpts {
19
- processed?: {
20
- cursor?: number;
21
- count?: number;
22
- };
23
- unprocessed?: {
24
- cursor?: number;
25
- count?: number;
26
- };
29
+ /**
30
+ * Options for failed child pagination
31
+ */
32
+ failed?: DependencyOpts;
33
+ /**
34
+ * Options for ignored child pagination
35
+ */
36
+ ignored?: DependencyOpts;
37
+ /**
38
+ * Options for processed child pagination
39
+ */
40
+ processed?: DependencyOpts;
41
+ /**
42
+ * Options for unprocessed child pagination
43
+ */
44
+ unprocessed?: DependencyOpts;
27
45
  }
28
46
  /**
29
47
  * MinimalJob
@@ -46,7 +64,7 @@ export interface MinimalJob<DataType = any, ReturnType = any, NameType extends s
46
64
  * The progress a job has performed so far.
47
65
  * @defaultValue 0
48
66
  */
49
- progress: number | object;
67
+ progress: JobProgress;
50
68
  /**
51
69
  * The value returned by the processor when processing this job.
52
70
  * @defaultValue null
@@ -116,7 +134,7 @@ export interface MinimalJob<DataType = any, ReturnType = any, NameType extends s
116
134
  *
117
135
  * @param progress - number or object to be saved as progress.
118
136
  */
119
- updateProgress(progress: number | object): Promise<void>;
137
+ updateProgress(progress: JobProgress): Promise<void>;
120
138
  /**
121
139
  * Logs one row of log data.
122
140
  *
@@ -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
  /**
@@ -84,7 +84,7 @@ export interface RepeatBaseOptions extends QueueBaseOptions {
84
84
  /**
85
85
  * Options for QueueEvents
86
86
  */
87
- export interface QueueEventsOptions extends QueueBaseOptions {
87
+ export interface QueueEventsOptions extends Omit<QueueBaseOptions, 'telemetry'> {
88
88
  /**
89
89
  * Condition to start listening to events at instance creation.
90
90
  */
@@ -100,3 +100,7 @@ export interface QueueEventsOptions extends QueueBaseOptions {
100
100
  */
101
101
  blockingTimeout?: number;
102
102
  }
103
+ /**
104
+ * Options for QueueEventsProducer
105
+ */
106
+ export type QueueEventsProducerOptions = Omit<QueueBaseOptions, 'telemetry'>;
@@ -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
  }
@@ -1,4 +1,4 @@
1
- import { JobJsonSandbox, JobsOptions } from '../types';
1
+ import { JobJsonSandbox, JobProgress, JobsOptions } from '../types';
2
2
  /**
3
3
  * @see {@link https://docs.bullmq.io/guide/workers/sandboxed-processors}
4
4
  */
@@ -8,6 +8,6 @@ export interface SandboxedJob<T = any, R = any> extends Omit<JobJsonSandbox, 'da
8
8
  moveToDelayed: (timestamp: number, token?: string) => Promise<void>;
9
9
  log: (row: any) => void;
10
10
  updateData: (data: any) => Promise<void>;
11
- updateProgress: (value: object | number) => Promise<void>;
11
+ updateProgress: (value: JobProgress) => Promise<void>;
12
12
  returnValue: R;
13
13
  }
@@ -8,7 +8,7 @@ export interface SandboxedOptions {
8
8
  * Note: This option can only be used when specifying
9
9
  * a file for the processor argument.
10
10
  *
11
- * @default false
11
+ * @defaultValue false
12
12
  */
13
13
  useWorkerThreads?: boolean;
14
14
  /**
@@ -33,8 +33,8 @@ export interface ContextManager<Context = any> {
33
33
  /**
34
34
  * Creates a new context and sets it as active for the fn passed as last argument
35
35
  *
36
- * @param context -
37
- * @param fn -
36
+ * @param context - the context to set as active
37
+ * @param fn - the function to execute with the context
38
38
  */
39
39
  with<A extends (...args: any[]) => any>(context: Context, fn: A): ReturnType<A>;
40
40
  /**
@@ -46,15 +46,15 @@ export interface ContextManager<Context = any> {
46
46
  * is the mechanism used to propagate the context across a distributed
47
47
  * application.
48
48
  *
49
- * @param context -
49
+ * @param context - the current context
50
50
  */
51
51
  getMetadata(context: Context): string;
52
52
  /**
53
53
  * Creates a new context from a serialized version effectively
54
54
  * linking the new context to the parent context.
55
55
  *
56
- * @param activeContext -
57
- * @param metadata -
56
+ * @param activeContext - the current active context
57
+ * @param metadata - the serialized version of the context
58
58
  */
59
59
  fromMetadata(activeContext: Context, metadata: string): Context;
60
60
  }
@@ -68,9 +68,10 @@ export interface Tracer<Context = any> {
68
68
  * context. If the context is not provided, the current active context should be
69
69
  * used.
70
70
  *
71
- * @param name -
72
- * @param options -
73
- * @param context -
71
+ * @param name - span name
72
+ * @param options - span options
73
+ * @param context - optional context
74
+ * @returns - the created span
74
75
  */
75
76
  startSpan(name: string, options?: SpanOptions, context?: Context): Span;
76
77
  }
@@ -85,33 +86,35 @@ export interface Span<Context = any> {
85
86
  * setSpanOnContext sets the span on the context. This is useful when you want
86
87
  * to propagate the span across the application.
87
88
  *
88
- * @param ctx
89
+ * @param ctx - context to set the span on
90
+ * @returns - the context with the span set on it
89
91
  */
90
92
  setSpanOnContext(ctx: Context): Context;
91
93
  /**
92
94
  * setAttribute sets an attribute on the span.
93
95
  *
94
- * @param ctx
96
+ * @param key - attribute key
97
+ * @param value - attribute value
95
98
  */
96
99
  setAttribute(key: string, value: AttributeValue): void;
97
100
  /**
98
101
  * setAttributes sets multiple attributes on the span.
99
102
  *
100
- * @param attributes
103
+ * @param attributes - attributes to set
101
104
  */
102
105
  setAttributes(attributes: Attributes): void;
103
106
  /**
104
107
  * addEvent adds an event to the span.
105
108
  *
106
- * @param name
107
- * @param attributes
109
+ * @param name - event name
110
+ * @param attributes - event attributes
108
111
  */
109
112
  addEvent(name: string, attributes?: Attributes): void;
110
113
  /**
111
114
  * recordException records an exception on the span.
112
115
  *
113
- * @param exception
114
- * @param time
116
+ * @param exception - exception to record
117
+ * @param time - time to record the exception
115
118
  */
116
119
  recordException(exception: Exception, time?: Time): void;
117
120
  /**
@@ -20,14 +20,14 @@ export interface WorkerOptions extends QueueBaseOptions, SandboxedOptions {
20
20
  /**
21
21
  * Condition to start processor at instance creation.
22
22
  *
23
- * @default true
23
+ * @defaultValue true
24
24
  */
25
25
  autorun?: boolean;
26
26
  /**
27
27
  * Amount of jobs that a single worker is allowed to work on
28
28
  * in parallel.
29
29
  *
30
- * @default 1
30
+ * @defaultValue 1
31
31
  * @see {@link https://docs.bullmq.io/guide/workers/concurrency}
32
32
  */
33
33
  concurrency?: number;
@@ -46,13 +46,13 @@ export interface WorkerOptions extends QueueBaseOptions, SandboxedOptions {
46
46
  * to the `wait` state. If this is exceeded, the job is moved
47
47
  * to `failed`.
48
48
  *
49
- * @default 1
49
+ * @defaultValue 1
50
50
  */
51
51
  maxStalledCount?: number;
52
52
  /**
53
53
  * Number of milliseconds between stallness checks.
54
54
  *
55
- * @default 30000
55
+ * @defaultValue 30000
56
56
  */
57
57
  stalledInterval?: number;
58
58
  /**
@@ -72,7 +72,7 @@ export interface WorkerOptions extends QueueBaseOptions, SandboxedOptions {
72
72
  * perform stalled checkd and move jobs back to wait for jobs being processed
73
73
  * by this worker.
74
74
  *
75
- * @default false
75
+ * @defaultValue false
76
76
  */
77
77
  skipStalledCheck?: boolean;
78
78
  /**
@@ -80,13 +80,13 @@ export interface WorkerOptions extends QueueBaseOptions, SandboxedOptions {
80
80
  * after lockDuration and moved back to the wait queue (if the stalled check is
81
81
  * not disabled)
82
82
  *
83
- * @default false
83
+ * @defaultValue false
84
84
  */
85
85
  skipLockRenewal?: boolean;
86
86
  /**
87
87
  * Number of seconds to long poll for jobs when the queue is empty.
88
88
  *
89
- * @default 5
89
+ * @defaultValue 5
90
90
  */
91
91
  drainDelay?: number;
92
92
  /**
@@ -95,7 +95,7 @@ export interface WorkerOptions extends QueueBaseOptions, SandboxedOptions {
95
95
  * be picked up by the stalled checker and move back to wait so that another worker
96
96
  * can process it again.
97
97
  *
98
- * @default 30000
98
+ * @defaultValue 30000
99
99
  */
100
100
  lockDuration?: number;
101
101
  /**
@@ -108,7 +108,7 @@ export interface WorkerOptions extends QueueBaseOptions, SandboxedOptions {
108
108
  /**
109
109
  * This is an internal option that should not be modified.
110
110
  *
111
- * @default 15000
111
+ * @defaultValue 15000
112
112
  */
113
113
  runRetryDelay?: number;
114
114
  /**
@@ -120,7 +120,7 @@ export interface WorkerOptions extends QueueBaseOptions, SandboxedOptions {
120
120
  * Note: This option can only be used when specifying
121
121
  * a file for the processor argument.
122
122
  *
123
- * @default false
123
+ * @defaultValue false
124
124
  */
125
125
  useWorkerThreads?: boolean;
126
126
  /**