bullmq 3.13.4 → 3.14.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 (82) hide show
  1. package/dist/cjs/classes/job.js +1 -1
  2. package/dist/cjs/classes/worker.js.map +1 -1
  3. package/dist/cjs/commands/addJob-8.lua +2 -2
  4. package/dist/cjs/commands/changeDelay-3.lua +2 -3
  5. package/dist/cjs/commands/getRanges-1.lua +1 -1
  6. package/dist/cjs/commands/includes/cleanSet.lua +2 -2
  7. package/dist/cjs/commands/includes/getRateLimitTTL.lua +1 -1
  8. package/dist/cjs/commands/includes/updateParentDepsIfNeeded.lua +0 -1
  9. package/dist/cjs/commands/isFinished-3.lua +3 -3
  10. package/dist/cjs/commands/moveToActive-9.lua +46 -44
  11. package/dist/cjs/commands/moveToDelayed-8.lua +22 -23
  12. package/dist/cjs/commands/pause-4.lua +8 -8
  13. package/dist/cjs/commands/promote-6.lua +7 -3
  14. package/dist/cjs/commands/removeRepeatable-2.lua +3 -0
  15. package/dist/cjs/commands/reprocessJob-6.lua +1 -1
  16. package/dist/cjs/commands/retryJob-8.lua +2 -2
  17. package/dist/cjs/commands/saveStacktrace-1.lua +2 -3
  18. package/dist/cjs/commands/updateData-1.lua +6 -2
  19. package/dist/cjs/commands/updateProgress-2.lua +6 -2
  20. package/dist/cjs/scripts/addJob-8.js +2 -2
  21. package/dist/cjs/scripts/changeDelay-3.js +2 -2
  22. package/dist/cjs/scripts/getRanges-1.js +1 -1
  23. package/dist/cjs/scripts/isFinished-3.js +3 -3
  24. package/dist/cjs/scripts/moveToActive-9.js +47 -45
  25. package/dist/cjs/scripts/moveToActive-9.js.map +1 -1
  26. package/dist/cjs/scripts/moveToDelayed-8.js +22 -22
  27. package/dist/cjs/scripts/moveToFinished-12.js +1 -1
  28. package/dist/cjs/scripts/pause-4.js +8 -8
  29. package/dist/cjs/scripts/promote-6.js +6 -3
  30. package/dist/cjs/scripts/promote-6.js.map +1 -1
  31. package/dist/cjs/scripts/removeRepeatable-2.js +2 -0
  32. package/dist/cjs/scripts/removeRepeatable-2.js.map +1 -1
  33. package/dist/cjs/scripts/reprocessJob-6.js +1 -1
  34. package/dist/cjs/scripts/retryJob-8.js +1 -1
  35. package/dist/cjs/scripts/saveStacktrace-1.js +1 -1
  36. package/dist/cjs/scripts/updateData-1.js +4 -1
  37. package/dist/cjs/scripts/updateData-1.js.map +1 -1
  38. package/dist/cjs/scripts/updateProgress-2.js +3 -0
  39. package/dist/cjs/scripts/updateProgress-2.js.map +1 -1
  40. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  41. package/dist/esm/classes/job.js +1 -1
  42. package/dist/esm/classes/worker.d.ts +1 -1
  43. package/dist/esm/classes/worker.js.map +1 -1
  44. package/dist/esm/commands/addJob-8.lua +2 -2
  45. package/dist/esm/commands/changeDelay-3.lua +2 -3
  46. package/dist/esm/commands/getRanges-1.lua +1 -1
  47. package/dist/esm/commands/includes/cleanSet.lua +2 -2
  48. package/dist/esm/commands/includes/getRateLimitTTL.lua +1 -1
  49. package/dist/esm/commands/includes/updateParentDepsIfNeeded.lua +0 -1
  50. package/dist/esm/commands/isFinished-3.lua +3 -3
  51. package/dist/esm/commands/moveToActive-9.lua +46 -44
  52. package/dist/esm/commands/moveToDelayed-8.lua +22 -23
  53. package/dist/esm/commands/pause-4.lua +8 -8
  54. package/dist/esm/commands/promote-6.lua +7 -3
  55. package/dist/esm/commands/removeRepeatable-2.lua +3 -0
  56. package/dist/esm/commands/reprocessJob-6.lua +1 -1
  57. package/dist/esm/commands/retryJob-8.lua +2 -2
  58. package/dist/esm/commands/saveStacktrace-1.lua +2 -3
  59. package/dist/esm/commands/updateData-1.lua +6 -2
  60. package/dist/esm/commands/updateProgress-2.lua +6 -2
  61. package/dist/esm/scripts/addJob-8.js +2 -2
  62. package/dist/esm/scripts/changeDelay-3.js +2 -2
  63. package/dist/esm/scripts/getRanges-1.js +1 -1
  64. package/dist/esm/scripts/isFinished-3.js +3 -3
  65. package/dist/esm/scripts/moveToActive-9.js +47 -45
  66. package/dist/esm/scripts/moveToActive-9.js.map +1 -1
  67. package/dist/esm/scripts/moveToDelayed-8.js +22 -22
  68. package/dist/esm/scripts/moveToFinished-12.js +1 -1
  69. package/dist/esm/scripts/pause-4.js +8 -8
  70. package/dist/esm/scripts/promote-6.js +6 -3
  71. package/dist/esm/scripts/promote-6.js.map +1 -1
  72. package/dist/esm/scripts/removeRepeatable-2.js +2 -0
  73. package/dist/esm/scripts/removeRepeatable-2.js.map +1 -1
  74. package/dist/esm/scripts/reprocessJob-6.js +1 -1
  75. package/dist/esm/scripts/retryJob-8.js +1 -1
  76. package/dist/esm/scripts/saveStacktrace-1.js +1 -1
  77. package/dist/esm/scripts/updateData-1.js +4 -1
  78. package/dist/esm/scripts/updateData-1.js.map +1 -1
  79. package/dist/esm/scripts/updateProgress-2.js +3 -0
  80. package/dist/esm/scripts/updateProgress-2.js.map +1 -1
  81. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  82. package/package.json +1 -1
@@ -5,25 +5,25 @@ const content = `--[[
5
5
  expiration time. The worker is responsible of keeping the lock fresh
6
6
  so that no other worker picks this job again.
7
7
  Input:
8
- KEYS[1] wait key
9
- KEYS[2] active key
10
- KEYS[3] priority key
11
- KEYS[4] stream events key
12
- KEYS[5] stalled key
13
- -- Rate limiting
14
- KEYS[6] rate limiter key
15
- KEYS[7] delayed key
16
- -- Promote delayed jobs
17
- KEYS[8] paused key
18
- KEYS[9] meta key
19
- -- Arguments
20
- ARGV[1] key prefix
21
- ARGV[2] timestamp
22
- ARGV[3] optional job ID
23
- ARGV[4] opts
24
- opts - token - lock token
25
- opts - lockDuration
26
- opts - limiter
8
+ KEYS[1] wait key
9
+ KEYS[2] active key
10
+ KEYS[3] priority key
11
+ KEYS[4] stream events key
12
+ KEYS[5] stalled key
13
+ -- Rate limiting
14
+ KEYS[6] rate limiter key
15
+ KEYS[7] delayed key
16
+ -- Promote delayed jobs
17
+ KEYS[8] paused key
18
+ KEYS[9] meta key
19
+ -- Arguments
20
+ ARGV[1] key prefix
21
+ ARGV[2] timestamp
22
+ ARGV[3] optional job ID
23
+ ARGV[4] opts
24
+ opts - token - lock token
25
+ opts - lockDuration
26
+ opts - limiter
27
27
  ]]
28
28
  local jobId
29
29
  local rcall = redis.call
@@ -157,7 +157,7 @@ local function getRateLimitTTL(opts, limiterKey)
157
157
  if jobCounter ~= nil and jobCounter >= maxJobs then
158
158
  local pttl = rcall("PTTL", limiterKey)
159
159
  if pttl > 0 then
160
- return pttl
160
+ return pttl
161
161
  end
162
162
  end
163
163
  end
@@ -167,35 +167,37 @@ end
167
167
  promoteDelayedJobs(KEYS[7], KEYS[1], KEYS[3], KEYS[8], KEYS[9], KEYS[4], ARGV[1], ARGV[2])
168
168
  local opts
169
169
  if (ARGV[3] ~= "") then
170
- jobId = ARGV[3]
171
- -- clean stalled key
172
- rcall("SREM", KEYS[5], jobId)
170
+ jobId = ARGV[3]
171
+ -- clean stalled key
172
+ rcall("SREM", KEYS[5], jobId)
173
173
  else
174
- -- Check if we are rate limited first.
175
- opts = cmsgpack.unpack(ARGV[4])
176
- local pttl = getRateLimitTTL(opts, KEYS[6])
177
- if pttl > 0 then
178
- return { 0, 0, pttl }
179
- end
180
- -- no job ID, try non-blocking move from wait to active
181
- jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
174
+ -- Check if we are rate limited first.
175
+ opts = cmsgpack.unpack(ARGV[4])
176
+ local pttl = getRateLimitTTL(opts, KEYS[6])
177
+ if pttl > 0 then
178
+ return { 0, 0, pttl }
179
+ end
180
+ -- no job ID, try non-blocking move from wait to active
181
+ jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
182
182
  end
183
183
  -- If jobId is special ID 0:delay, then there is no job to process
184
- if jobId then
185
- if string.sub(jobId, 1, 2) == "0:" then
186
- rcall("LREM", KEYS[2], 1, jobId)
187
- -- Move again since we just got the marker job.
188
- jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
189
- if jobId and string.sub(jobId, 1, 2) == "0:" then
190
- rcall("LREM", KEYS[2], 1, jobId)
191
- jobId = nil
192
- end
193
- end
194
- if jobId then
195
- opts = opts or cmsgpack.unpack(ARGV[4])
196
- -- this script is not really moving, it is preparing the job for processing
197
- return moveJobFromWaitToActive(KEYS, ARGV[1], jobId, ARGV[2], opts)
184
+ if jobId then
185
+ if string.sub(jobId, 1, 2) == "0:" then
186
+ rcall("LREM", KEYS[2], 1, jobId)
187
+ -- Move again since we just got the marker job.
188
+ jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
189
+ -- Since it is possible that between a call to BRPOPLPUSH and moveToActive
190
+ -- another script puts a new maker in wait, we need to check again.
191
+ if jobId and string.sub(jobId, 1, 2) == "0:" then
192
+ rcall("LREM", KEYS[2], 1, jobId)
193
+ jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
198
194
  end
195
+ end
196
+ if jobId then
197
+ opts = opts or cmsgpack.unpack(ARGV[4])
198
+ -- this script is not really moving, it is preparing the job for processing
199
+ return moveJobFromWaitToActive(KEYS, ARGV[1], jobId, ARGV[2], opts)
200
+ end
199
201
  end
200
202
  -- Return the timestamp for the next delayed job if any.
201
203
  local nextTimestamp = getNextDelayedTimestamp(KEYS[7])
@@ -1 +1 @@
1
- {"version":3,"file":"moveToActive-9.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Mf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"moveToActive-9.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Mf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -107,30 +107,30 @@ local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
107
107
  end
108
108
  local jobKey = KEYS[5]
109
109
  if rcall("EXISTS", jobKey) == 1 then
110
- local delayedKey = KEYS[4]
111
- if ARGV[5] ~= "0" then
112
- local lockKey = jobKey .. ':lock'
113
- if rcall("GET", lockKey) == ARGV[5] then
114
- rcall("DEL", lockKey)
115
- else
116
- return -2
117
- end
118
- end
119
- local jobId = ARGV[4]
120
- local score = tonumber(ARGV[3])
121
- local delayedTimestamp = (score / 0x1000)
122
- local numRemovedElements = rcall("LREM", KEYS[2], -1, jobId)
123
- if (numRemovedElements < 1) then
124
- return -3
110
+ local delayedKey = KEYS[4]
111
+ if ARGV[5] ~= "0" then
112
+ local lockKey = jobKey .. ':lock'
113
+ if rcall("GET", lockKey) == ARGV[5] then
114
+ rcall("DEL", lockKey)
115
+ else
116
+ return -2
125
117
  end
126
- rcall("ZADD", delayedKey, score, jobId)
127
- rcall("XADD", KEYS[6], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp)
128
- -- Check if we need to push a marker job to wake up sleeping workers.
129
- local target = getTargetQueueList(KEYS[8], KEYS[1], KEYS[7])
130
- addDelayMarkerIfNeeded(target, delayedKey)
131
- return 0
118
+ end
119
+ local jobId = ARGV[4]
120
+ local score = tonumber(ARGV[3])
121
+ local delayedTimestamp = (score / 0x1000)
122
+ local numRemovedElements = rcall("LREM", KEYS[2], -1, jobId)
123
+ if numRemovedElements < 1 then
124
+ return -3
125
+ end
126
+ rcall("ZADD", delayedKey, score, jobId)
127
+ rcall("XADD", KEYS[6], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp)
128
+ -- Check if we need to push a marker job to wake up sleeping workers.
129
+ local target = getTargetQueueList(KEYS[8], KEYS[1], KEYS[7])
130
+ addDelayMarkerIfNeeded(target, delayedKey)
131
+ return 0
132
132
  else
133
- return -1
133
+ return -1
134
134
  end
135
135
  `;
136
136
  export const moveToDelayed = {
@@ -418,7 +418,7 @@ local function getRateLimitTTL(opts, limiterKey)
418
418
  if jobCounter ~= nil and jobCounter >= maxJobs then
419
419
  local pttl = rcall("PTTL", limiterKey)
420
420
  if pttl > 0 then
421
- return pttl
421
+ return pttl
422
422
  end
423
423
  end
424
424
  end
@@ -1,13 +1,13 @@
1
1
  const content = `--[[
2
2
  Pauses or resumes a queue globably.
3
- Input:
4
- KEYS[1] 'wait' or 'paused''
5
- KEYS[2] 'paused' or 'wait'
6
- KEYS[3] 'meta'
7
- KEYS[4] events stream key
8
- ARGV[1] 'paused' or 'resumed'
9
- Event:
10
- publish paused or resumed event.
3
+ Input:
4
+ KEYS[1] 'wait' or 'paused''
5
+ KEYS[2] 'paused' or 'wait'
6
+ KEYS[3] 'meta'
7
+ KEYS[4] events stream key
8
+ ARGV[1] 'paused' or 'resumed'
9
+ Event:
10
+ publish paused or resumed event.
11
11
  ]]
12
12
  local rcall = redis.call
13
13
  if rcall("EXISTS", KEYS[1]) == 1 then
@@ -1,6 +1,6 @@
1
1
  const content = `--[[
2
2
  Promotes a job that is currently "delayed" to the "waiting" state
3
- Input:
3
+ Input:
4
4
  KEYS[1] 'delayed'
5
5
  KEYS[2] 'wait'
6
6
  KEYS[3] 'paused'
@@ -9,10 +9,13 @@ const content = `--[[
9
9
  KEYS[6] 'event stream'
10
10
  ARGV[1] queue.toKey('')
11
11
  ARGV[2] jobId
12
- Events:
12
+ Output:
13
+ 0 - OK
14
+ -3 - Job not in delayed zset.
15
+ Events:
13
16
  'waiting'
14
17
  ]]
15
- local rcall = redis.call;
18
+ local rcall = redis.call
16
19
  local jobId = ARGV[2]
17
20
  -- Includes
18
21
  --[[
@@ -1 +1 @@
1
- {"version":3,"file":"promote-6.js","sourceRoot":"","sources":["../../../src/scripts/promote-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgEZ,CAAC;AACL,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,IAAI,EAAE,SAAS;IACf,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"promote-6.js","sourceRoot":"","sources":["../../../src/scripts/promote-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAmEZ,CAAC;AACL,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,IAAI,EAAE,SAAS;IACf,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -9,6 +9,8 @@ const content = `--[[
9
9
  Output:
10
10
  0 - OK
11
11
  1 - Missing repeat job
12
+ Events:
13
+ 'removed'
12
14
  ]]
13
15
  local rcall = redis.call
14
16
  local millis = rcall("ZSCORE", KEYS[1], ARGV[2])
@@ -1 +1 @@
1
- {"version":3,"file":"removeRepeatable-2.js","sourceRoot":"","sources":["../../../src/scripts/removeRepeatable-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Bf,CAAC;AACF,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,kBAAkB;IACxB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"removeRepeatable-2.js","sourceRoot":"","sources":["../../../src/scripts/removeRepeatable-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Bf,CAAC;AACF,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,kBAAkB;IACxB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -12,7 +12,7 @@ const content = `--[[
12
12
  ARGV[3] propVal - failedReason/returnvalue
13
13
  ARGV[4] prev state - failed/completed
14
14
  Output:
15
- 1 means the operation was a success
15
+ 1 means the operation was a success
16
16
  -1 means the job does not exist
17
17
  -3 means the job was not found in the expected set.
18
18
  ]]
@@ -94,7 +94,7 @@ if rcall("EXISTS", KEYS[4]) == 1 then
94
94
  rcall("LREM", KEYS[1], 0, ARGV[4])
95
95
  rcall(ARGV[3], target, ARGV[4])
96
96
  -- Emit waiting event
97
- rcall("XADD", KEYS[6], "*", "event", "waiting", "jobId", ARGV[4], "prev", "failed");
97
+ rcall("XADD", KEYS[6], "*", "event", "waiting", "jobId", ARGV[4], "prev", "failed")
98
98
  return 0
99
99
  else
100
100
  return -1
@@ -5,7 +5,7 @@ const content = `--[[
5
5
  ARGV[1] stacktrace
6
6
  ARGV[2] failedReason
7
7
  Output:
8
- 0 - OK
8
+ 0 - OK
9
9
  -1 - Missing key
10
10
  ]]
11
11
  local rcall = redis.call
@@ -2,7 +2,10 @@ const content = `--[[
2
2
  Update job data
3
3
  Input:
4
4
  KEYS[1] Job id key
5
- ARGV[1] data
5
+ ARGV[1] data
6
+ Output:
7
+ 0 - OK
8
+ -1 - Missing job.
6
9
  ]]
7
10
  local rcall = redis.call
8
11
  if rcall("EXISTS",KEYS[1]) == 1 then -- // Make sure job exists
@@ -1 +1 @@
1
- {"version":3,"file":"updateData-1.js","sourceRoot":"","sources":["../../../src/scripts/updateData-1.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;CAaf,CAAC;AACF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,YAAY;IAClB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"updateData-1.js","sourceRoot":"","sources":["../../../src/scripts/updateData-1.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;CAgBf,CAAC;AACF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,YAAY;IAClB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -5,6 +5,9 @@ const content = `--[[
5
5
  KEYS[2] event stream key
6
6
  ARGV[1] id
7
7
  ARGV[2] progress
8
+ Output:
9
+ 0 - OK
10
+ -1 - Missing job.
8
11
  Event:
9
12
  progress(jobId, progress)
10
13
  ]]
@@ -1 +1 @@
1
- {"version":3,"file":"updateProgress-2.js","sourceRoot":"","sources":["../../../src/scripts/updateProgress-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;CAkBf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"updateProgress-2.js","sourceRoot":"","sources":["../../../src/scripts/updateProgress-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;CAqBf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}