bullmq 3.1.1 → 3.1.3

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 (65) hide show
  1. package/dist/cjs/classes/job.js +4 -0
  2. package/dist/cjs/classes/job.js.map +1 -1
  3. package/dist/cjs/classes/queue-getters.js +1 -1
  4. package/dist/cjs/classes/queue-getters.js.map +1 -1
  5. package/dist/cjs/classes/queue.d.ts +1 -7
  6. package/dist/cjs/classes/queue.js +3 -0
  7. package/dist/cjs/classes/queue.js.map +1 -1
  8. package/dist/cjs/classes/repeat.js +5 -0
  9. package/dist/cjs/classes/repeat.js.map +1 -1
  10. package/dist/cjs/classes/worker.js +14 -6
  11. package/dist/cjs/classes/worker.js.map +1 -1
  12. package/dist/cjs/commands/addJob-8.lua +6 -5
  13. package/dist/cjs/commands/includes/checkStalledJobs.lua +22 -21
  14. package/dist/cjs/commands/includes/promoteDelayedJobs.lua +1 -2
  15. package/dist/cjs/commands/moveToActive-9.lua +13 -7
  16. package/dist/cjs/commands/moveToDelayed-8.lua +31 -23
  17. package/dist/cjs/commands/moveToFinished-12.lua +9 -5
  18. package/dist/cjs/commands/promote-6.lua +2 -1
  19. package/dist/cjs/scripts/addJob-8.js +6 -5
  20. package/dist/cjs/scripts/addJob-8.js.map +1 -1
  21. package/dist/cjs/scripts/moveStalledJobsToWait-8.js +22 -21
  22. package/dist/cjs/scripts/moveStalledJobsToWait-8.js.map +1 -1
  23. package/dist/cjs/scripts/moveToActive-9.js +13 -9
  24. package/dist/cjs/scripts/moveToActive-9.js.map +1 -1
  25. package/dist/cjs/scripts/moveToDelayed-8.js +43 -22
  26. package/dist/cjs/scripts/moveToDelayed-8.js.map +1 -1
  27. package/dist/cjs/scripts/moveToFinished-12.js +10 -7
  28. package/dist/cjs/scripts/moveToFinished-12.js.map +1 -1
  29. package/dist/cjs/scripts/promote-6.js +2 -1
  30. package/dist/cjs/scripts/promote-6.js.map +1 -1
  31. package/dist/cjs/scripts/retryJob-8.js +1 -2
  32. package/dist/cjs/scripts/retryJob-8.js.map +1 -1
  33. package/dist/esm/classes/job.js +4 -0
  34. package/dist/esm/classes/job.js.map +1 -1
  35. package/dist/esm/classes/queue-getters.js +1 -1
  36. package/dist/esm/classes/queue-getters.js.map +1 -1
  37. package/dist/esm/classes/queue.d.ts +1 -7
  38. package/dist/esm/classes/queue.js +3 -0
  39. package/dist/esm/classes/queue.js.map +1 -1
  40. package/dist/esm/classes/repeat.js +5 -0
  41. package/dist/esm/classes/repeat.js.map +1 -1
  42. package/dist/esm/classes/worker.js +14 -6
  43. package/dist/esm/classes/worker.js.map +1 -1
  44. package/dist/esm/commands/addJob-8.lua +6 -5
  45. package/dist/esm/commands/includes/checkStalledJobs.lua +22 -21
  46. package/dist/esm/commands/includes/promoteDelayedJobs.lua +1 -2
  47. package/dist/esm/commands/moveToActive-9.lua +13 -7
  48. package/dist/esm/commands/moveToDelayed-8.lua +31 -23
  49. package/dist/esm/commands/moveToFinished-12.lua +9 -5
  50. package/dist/esm/commands/promote-6.lua +2 -1
  51. package/dist/esm/scripts/addJob-8.js +6 -5
  52. package/dist/esm/scripts/addJob-8.js.map +1 -1
  53. package/dist/esm/scripts/moveStalledJobsToWait-8.js +22 -21
  54. package/dist/esm/scripts/moveStalledJobsToWait-8.js.map +1 -1
  55. package/dist/esm/scripts/moveToActive-9.js +13 -9
  56. package/dist/esm/scripts/moveToActive-9.js.map +1 -1
  57. package/dist/esm/scripts/moveToDelayed-8.js +43 -22
  58. package/dist/esm/scripts/moveToDelayed-8.js.map +1 -1
  59. package/dist/esm/scripts/moveToFinished-12.js +10 -7
  60. package/dist/esm/scripts/moveToFinished-12.js.map +1 -1
  61. package/dist/esm/scripts/promote-6.js +2 -1
  62. package/dist/esm/scripts/promote-6.js.map +1 -1
  63. package/dist/esm/scripts/retryJob-8.js +1 -2
  64. package/dist/esm/scripts/retryJob-8.js.map +1 -1
  65. package/package.json +1 -1
@@ -126,8 +126,7 @@ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
126
126
  return pausedKey
127
127
  end
128
128
  end
129
- -- Try to get as much as 1000 jobs at once, and returns the nextTimestamp if
130
- -- there are more delayed jobs to process.
129
+ -- Try to get as much as 1000 jobs at once
131
130
  local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
132
131
  metaKey, eventStreamKey, prefix, timestamp)
133
132
  local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000, "LIMIT", 0, 1000)
@@ -181,13 +180,18 @@ else
181
180
  -- no job ID, try non-blocking move from wait to active
182
181
  jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
183
182
  end
184
- -- If jobId is special ID 0, then there is no job to process
185
- if jobId == "0" then
186
- rcall("LREM", KEYS[2], 1, 0)
187
- elseif jobId then
188
- opts = opts or cmsgpack.unpack(ARGV[4])
189
- -- this script is not really moving, it is preparing the job for processing
190
- return moveJobFromWaitToActive(KEYS, ARGV[1], jobId, ARGV[2], opts)
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
+ end
190
+ if jobId then
191
+ opts = opts or cmsgpack.unpack(ARGV[4])
192
+ -- this script is not really moving, it is preparing the job for processing
193
+ return moveJobFromWaitToActive(KEYS, ARGV[1], jobId, ARGV[2], opts)
194
+ end
191
195
  end
192
196
  -- Return the timestamp for the next delayed job if any.
193
197
  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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoMf,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwMf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -56,8 +56,7 @@ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
56
56
  return pausedKey
57
57
  end
58
58
  end
59
- -- Try to get as much as 1000 jobs at once, and returns the nextTimestamp if
60
- -- there are more delayed jobs to process.
59
+ -- Try to get as much as 1000 jobs at once
61
60
  local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
62
61
  metaKey, eventStreamKey, prefix, timestamp)
63
62
  local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000, "LIMIT", 0, 1000)
@@ -81,28 +80,50 @@ local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
81
80
  end
82
81
  end
83
82
  end
84
- promoteDelayedJobs(KEYS[4], KEYS[1], KEYS[3], KEYS[7], KEYS[8], KEYS[6], ARGV[1], ARGV[2])
85
- if rcall("EXISTS", KEYS[5]) == 1 then
86
- if ARGV[5] ~= "0" then
87
- local lockKey = KEYS[5] .. ':lock'
88
- if rcall("GET", lockKey) == ARGV[5] then
89
- rcall("DEL", lockKey)
90
- else
91
- return -2
83
+ --[[
84
+ Function to return the next delayed job timestamp.
85
+ ]]
86
+ local function getNextDelayedTimestamp(delayedKey)
87
+ local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
88
+ if #result then
89
+ local nextTimestamp = tonumber(result[2])
90
+ if (nextTimestamp ~= nil) then
91
+ nextTimestamp = nextTimestamp / 0x1000
92
+ end
93
+ return nextTimestamp
92
94
  end
93
- end
94
- local jobId = ARGV[4]
95
- local score = tonumber(ARGV[3])
96
- local delayedTimestamp = (score / 0x1000)
97
- local numRemovedElements = rcall("LREM", KEYS[2], -1, jobId)
98
- if(numRemovedElements < 1) then
99
- return -3
100
- end
101
- rcall("ZADD", KEYS[4], score, jobId)
102
- rcall("XADD", KEYS[6], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp);
103
- return 0
95
+ end
96
+ local jobKey = KEYS[5]
97
+ if rcall("EXISTS", jobKey) == 1 then
98
+ local delayedKey = KEYS[4]
99
+ if ARGV[5] ~= "0" then
100
+ local lockKey = jobKey .. ':lock'
101
+ if rcall("GET", lockKey) == ARGV[5] then
102
+ rcall("DEL", lockKey)
103
+ else
104
+ return -2
105
+ end
106
+ end
107
+ local jobId = ARGV[4]
108
+ local score = tonumber(ARGV[3])
109
+ local delayedTimestamp = (score / 0x1000)
110
+ local numRemovedElements = rcall("LREM", KEYS[2], -1, jobId)
111
+ if (numRemovedElements < 1) then
112
+ return -3
113
+ end
114
+ -- Check if we need to push a marker job to wake up sleeping workers.
115
+ local target = getTargetQueueList(KEYS[8], KEYS[1], KEYS[7])
116
+ if rcall("LLEN", target) == 0 then
117
+ local nextTimestamp = getNextDelayedTimestamp(delayedKey)
118
+ if not nextTimestamp or (delayedTimestamp < nextTimestamp) then
119
+ rcall("LPUSH", target, "0:" .. delayedTimestamp - tonumber(ARGV[2]))
120
+ end
121
+ end
122
+ rcall("ZADD", delayedKey, score, jobId)
123
+ rcall("XADD", KEYS[6], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp)
124
+ return 0
104
125
  else
105
- return -1
126
+ return -1
106
127
  end
107
128
  `;
108
129
  export const moveToDelayed = {
@@ -1 +1 @@
1
- {"version":3,"file":"moveToDelayed-8.js","sourceRoot":"","sources":["../../../src/scripts/moveToDelayed-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Gf,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"moveToDelayed-8.js","sourceRoot":"","sources":["../../../src/scripts/moveToDelayed-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Hf,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -224,8 +224,7 @@ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
224
224
  return pausedKey
225
225
  end
226
226
  end
227
- -- Try to get as much as 1000 jobs at once, and returns the nextTimestamp if
228
- -- there are more delayed jobs to process.
227
+ -- Try to get as much as 1000 jobs at once
229
228
  local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
230
229
  metaKey, eventStreamKey, prefix, timestamp)
231
230
  local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000, "LIMIT", 0, 1000)
@@ -512,11 +511,15 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
512
511
  local pttl = getRateLimitTTL(opts, KEYS[6])
513
512
  if pttl > 0 then return {0, 0, pttl} end
514
513
  jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
515
- if jobId == "0" then
516
- rcall("LREM", KEYS[2], 1, 0)
517
- elseif jobId then
518
- return
519
- moveJobFromWaitToActive(KEYS, ARGV[8], jobId, timestamp, opts)
514
+ -- If jobId is special ID 0:delay, then there is no job to process
515
+ if jobId then
516
+ if string.sub(jobId, 1, 2) == "0:" then
517
+ rcall("LREM", KEYS[2], 1, jobId)
518
+ else
519
+ opts = opts or cmsgpack.unpack(ARGV[4])
520
+ -- this script is not really moving, it is preparing the job for processing
521
+ return moveJobFromWaitToActive(KEYS, ARGV[8], jobId, timestamp, opts)
522
+ end
520
523
  end
521
524
  -- Return the timestamp for the next delayed job if any.
522
525
  local nextTimestamp = getNextDelayedTimestamp(KEYS[7])
@@ -1 +1 @@
1
- {"version":3,"file":"moveToFinished-12.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-12.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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E,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
@@ -45,7 +45,8 @@ if rcall("ZREM", KEYS[1], jobId) == 1 then
45
45
  local target = getTargetQueueList(KEYS[4], KEYS[2], KEYS[3])
46
46
  -- Remove delayed "marker" from the wait list if there is any.
47
47
  -- Since we are adding a job we do not need the marker anymore.
48
- if rcall("LINDEX", target, 0) == "0" then
48
+ local marker = rcall("LINDEX", target, 0)
49
+ if marker and string.sub(marker, 1, 2) == "0:" then
49
50
  rcall("LPOP", target)
50
51
  end
51
52
  if priority == 0 then
@@ -1 +1 @@
1
- {"version":3,"file":"promote-6.js","sourceRoot":"","sources":["../../../src/scripts/promote-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA+DZ,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgEZ,CAAC;AACL,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,IAAI,EAAE,SAAS;IACf,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -56,8 +56,7 @@ local function addJobWithPriority(priorityKey, priority, targetKey, jobId)
56
56
  rcall("RPUSH", targetKey, jobId)
57
57
  end
58
58
  end
59
- -- Try to get as much as 1000 jobs at once, and returns the nextTimestamp if
60
- -- there are more delayed jobs to process.
59
+ -- Try to get as much as 1000 jobs at once
61
60
  local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
62
61
  metaKey, eventStreamKey, prefix, timestamp)
63
62
  local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000, "LIMIT", 0, 1000)
@@ -1 +1 @@
1
- {"version":3,"file":"retryJob-8.js","sourceRoot":"","sources":["../../../src/scripts/retryJob-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsGf,CAAC;AACF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,UAAU;IAChB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"retryJob-8.js","sourceRoot":"","sources":["../../../src/scripts/retryJob-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqGf,CAAC;AACF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,UAAU;IAChB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bullmq",
3
- "version": "3.1.1",
3
+ "version": "3.1.3",
4
4
  "description": "Queue for messages and jobs based on Redis",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",