bullmq 3.13.4 → 3.14.1

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 (92) 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/addDelayMarkerIfNeeded.lua +3 -3
  7. package/dist/cjs/commands/includes/cleanSet.lua +2 -2
  8. package/dist/cjs/commands/includes/getRateLimitTTL.lua +1 -1
  9. package/dist/cjs/commands/includes/promoteDelayedJobs.lua +4 -9
  10. package/dist/cjs/commands/includes/updateParentDepsIfNeeded.lua +0 -1
  11. package/dist/cjs/commands/isFinished-3.lua +3 -3
  12. package/dist/cjs/commands/moveToActive-9.lua +51 -46
  13. package/dist/cjs/commands/moveToDelayed-8.lua +22 -23
  14. package/dist/cjs/commands/moveToFinished-12.lua +3 -1
  15. package/dist/cjs/commands/pause-4.lua +8 -8
  16. package/dist/cjs/commands/promote-6.lua +7 -3
  17. package/dist/cjs/commands/removeRepeatable-2.lua +3 -0
  18. package/dist/cjs/commands/reprocessJob-6.lua +1 -1
  19. package/dist/cjs/commands/retryJob-8.lua +4 -5
  20. package/dist/cjs/commands/saveStacktrace-1.lua +2 -3
  21. package/dist/cjs/commands/updateData-1.lua +6 -2
  22. package/dist/cjs/commands/updateProgress-2.lua +6 -2
  23. package/dist/cjs/scripts/addJob-8.js +5 -5
  24. package/dist/cjs/scripts/changeDelay-3.js +2 -2
  25. package/dist/cjs/scripts/getRanges-1.js +1 -1
  26. package/dist/cjs/scripts/isFinished-3.js +3 -3
  27. package/dist/cjs/scripts/moveToActive-9.js +76 -76
  28. package/dist/cjs/scripts/moveToDelayed-8.js +29 -32
  29. package/dist/cjs/scripts/moveToDelayed-8.js.map +1 -1
  30. package/dist/cjs/scripts/moveToFinished-12.js +21 -23
  31. package/dist/cjs/scripts/moveToFinished-12.js.map +1 -1
  32. package/dist/cjs/scripts/pause-4.js +8 -8
  33. package/dist/cjs/scripts/promote-6.js +6 -3
  34. package/dist/cjs/scripts/promote-6.js.map +1 -1
  35. package/dist/cjs/scripts/removeRepeatable-2.js +2 -0
  36. package/dist/cjs/scripts/removeRepeatable-2.js.map +1 -1
  37. package/dist/cjs/scripts/reprocessJob-6.js +1 -1
  38. package/dist/cjs/scripts/retryJob-8.js +7 -10
  39. package/dist/cjs/scripts/retryJob-8.js.map +1 -1
  40. package/dist/cjs/scripts/saveStacktrace-1.js +1 -1
  41. package/dist/cjs/scripts/updateData-1.js +4 -1
  42. package/dist/cjs/scripts/updateData-1.js.map +1 -1
  43. package/dist/cjs/scripts/updateProgress-2.js +3 -0
  44. package/dist/cjs/scripts/updateProgress-2.js.map +1 -1
  45. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  46. package/dist/esm/classes/job.js +1 -1
  47. package/dist/esm/classes/worker.d.ts +2 -2
  48. package/dist/esm/classes/worker.js.map +1 -1
  49. package/dist/esm/commands/addJob-8.lua +2 -2
  50. package/dist/esm/commands/changeDelay-3.lua +2 -3
  51. package/dist/esm/commands/getRanges-1.lua +1 -1
  52. package/dist/esm/commands/includes/addDelayMarkerIfNeeded.lua +3 -3
  53. package/dist/esm/commands/includes/cleanSet.lua +2 -2
  54. package/dist/esm/commands/includes/getRateLimitTTL.lua +1 -1
  55. package/dist/esm/commands/includes/promoteDelayedJobs.lua +4 -9
  56. package/dist/esm/commands/includes/updateParentDepsIfNeeded.lua +0 -1
  57. package/dist/esm/commands/isFinished-3.lua +3 -3
  58. package/dist/esm/commands/moveToActive-9.lua +51 -46
  59. package/dist/esm/commands/moveToDelayed-8.lua +22 -23
  60. package/dist/esm/commands/moveToFinished-12.lua +3 -1
  61. package/dist/esm/commands/pause-4.lua +8 -8
  62. package/dist/esm/commands/promote-6.lua +7 -3
  63. package/dist/esm/commands/removeRepeatable-2.lua +3 -0
  64. package/dist/esm/commands/reprocessJob-6.lua +1 -1
  65. package/dist/esm/commands/retryJob-8.lua +4 -5
  66. package/dist/esm/commands/saveStacktrace-1.lua +2 -3
  67. package/dist/esm/commands/updateData-1.lua +6 -2
  68. package/dist/esm/commands/updateProgress-2.lua +6 -2
  69. package/dist/esm/scripts/addJob-8.js +5 -5
  70. package/dist/esm/scripts/changeDelay-3.js +2 -2
  71. package/dist/esm/scripts/getRanges-1.js +1 -1
  72. package/dist/esm/scripts/isFinished-3.js +3 -3
  73. package/dist/esm/scripts/moveToActive-9.js +76 -76
  74. package/dist/esm/scripts/moveToDelayed-8.js +29 -32
  75. package/dist/esm/scripts/moveToDelayed-8.js.map +1 -1
  76. package/dist/esm/scripts/moveToFinished-12.js +21 -23
  77. package/dist/esm/scripts/moveToFinished-12.js.map +1 -1
  78. package/dist/esm/scripts/pause-4.js +8 -8
  79. package/dist/esm/scripts/promote-6.js +6 -3
  80. package/dist/esm/scripts/promote-6.js.map +1 -1
  81. package/dist/esm/scripts/removeRepeatable-2.js +2 -0
  82. package/dist/esm/scripts/removeRepeatable-2.js.map +1 -1
  83. package/dist/esm/scripts/reprocessJob-6.js +1 -1
  84. package/dist/esm/scripts/retryJob-8.js +7 -10
  85. package/dist/esm/scripts/retryJob-8.js.map +1 -1
  86. package/dist/esm/scripts/saveStacktrace-1.js +1 -1
  87. package/dist/esm/scripts/updateData-1.js +4 -1
  88. package/dist/esm/scripts/updateData-1.js.map +1 -1
  89. package/dist/esm/scripts/updateProgress-2.js +3 -0
  90. package/dist/esm/scripts/updateProgress-2.js.map +1 -1
  91. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  92. package/package.json +1 -1
@@ -23,12 +23,12 @@ if rcall("EXISTS", KEYS[2]) == 1 then
23
23
  local score = tonumber(ARGV[2])
24
24
  local delayedTimestamp = (score / 0x1000)
25
25
  local numRemovedElements = rcall("ZREM", KEYS[1], jobId)
26
- if (numRemovedElements < 1) then
26
+ if numRemovedElements < 1 then
27
27
  return -3
28
28
  end
29
29
  rcall("HSET", KEYS[2], "delay", tonumber(ARGV[1]))
30
30
  rcall("ZADD", KEYS[1], score, jobId)
31
- rcall("XADD", KEYS[3], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp);
31
+ rcall("XADD", KEYS[3], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp)
32
32
  return 0
33
33
  else
34
34
  return -1
@@ -10,7 +10,7 @@ const content = `--[[
10
10
  ARGV[3] asc
11
11
  ARGV[4...] types
12
12
  ]]
13
- local rcall = redis.call;
13
+ local rcall = redis.call
14
14
  local prefix = KEYS[1]
15
15
  local rangeStart = tonumber(ARGV[1])
16
16
  local rangeEnd = tonumber(ARGV[2])
@@ -13,14 +13,14 @@ const content = `--[[
13
13
  0 - Not finished.
14
14
  1 - Completed.
15
15
  2 - Failed.
16
- -5 - Missing job.
16
+ -1 - Missing job.
17
17
  ]]
18
18
  local rcall = redis.call
19
19
  if rcall("EXISTS", KEYS[3]) ~= 1 then
20
20
  if ARGV[2] == "1" then
21
- return {-5,"Missing key for job " .. KEYS[3] .. ". isFinished"}
21
+ return {-1,"Missing key for job " .. KEYS[3] .. ". isFinished"}
22
22
  end
23
- return -5
23
+ return -1
24
24
  end
25
25
  if rcall("ZSCORE", KEYS[1], ARGV[1]) ~= false then
26
26
  if ARGV[2] == "1" then
@@ -8,25 +8,25 @@ const content = `--[[
8
8
  expiration time. The worker is responsible of keeping the lock fresh
9
9
  so that no other worker picks this job again.
10
10
  Input:
11
- KEYS[1] wait key
12
- KEYS[2] active key
13
- KEYS[3] priority key
14
- KEYS[4] stream events key
15
- KEYS[5] stalled key
16
- -- Rate limiting
17
- KEYS[6] rate limiter key
18
- KEYS[7] delayed key
19
- -- Promote delayed jobs
20
- KEYS[8] paused key
21
- KEYS[9] meta key
22
- -- Arguments
23
- ARGV[1] key prefix
24
- ARGV[2] timestamp
25
- ARGV[3] optional job ID
26
- ARGV[4] opts
27
- opts - token - lock token
28
- opts - lockDuration
29
- opts - limiter
11
+ KEYS[1] wait key
12
+ KEYS[2] active key
13
+ KEYS[3] priority key
14
+ KEYS[4] stream events key
15
+ KEYS[5] stalled key
16
+ -- Rate limiting
17
+ KEYS[6] rate limiter key
18
+ KEYS[7] delayed key
19
+ -- Promote delayed jobs
20
+ KEYS[8] paused key
21
+ KEYS[9] meta key
22
+ -- Arguments
23
+ ARGV[1] key prefix
24
+ ARGV[2] timestamp
25
+ ARGV[3] optional job ID
26
+ ARGV[4] opts
27
+ opts - token - lock token
28
+ opts - lockDuration
29
+ opts - limiter
30
30
  ]]
31
31
  local jobId
32
32
  local rcall = redis.call
@@ -96,13 +96,36 @@ local function getNextDelayedTimestamp(delayedKey)
96
96
  return nextTimestamp
97
97
  end
98
98
  end
99
+ local function getRateLimitTTL(opts, limiterKey)
100
+ local maxJobs = tonumber(opts['limiter'] and opts['limiter']['max'])
101
+ if maxJobs then
102
+ local jobCounter = tonumber(rcall("GET", limiterKey))
103
+ if jobCounter ~= nil and jobCounter >= maxJobs then
104
+ local pttl = rcall("PTTL", limiterKey)
105
+ if pttl > 0 then
106
+ return pttl
107
+ end
108
+ end
109
+ end
110
+ return 0
111
+ end
112
+ --[[
113
+ Function to check for the meta.paused key to decide if we are paused or not
114
+ (since an empty list and !EXISTS are not really the same).
115
+ ]]
116
+ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
117
+ if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
118
+ return waitKey
119
+ else
120
+ return pausedKey
121
+ end
122
+ end
99
123
  --[[
100
124
  Updates the delay set, by moving delayed jobs that should
101
125
  be processed now to "wait".
102
126
  Events:
103
127
  'waiting'
104
128
  ]]
105
- local rcall = redis.call
106
129
  -- Includes
107
130
  --[[
108
131
  Function to add job considering priority.
@@ -118,33 +141,20 @@ local function addJobWithPriority(priorityKey, priority, targetKey, jobId)
118
141
  rcall("RPUSH", targetKey, jobId)
119
142
  end
120
143
  end
121
- --[[
122
- Function to check for the meta.paused key to decide if we are paused or not
123
- (since an empty list and !EXISTS are not really the same).
124
- ]]
125
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
126
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
127
- return waitKey
128
- else
129
- return pausedKey
130
- end
131
- end
132
144
  -- Try to get as much as 1000 jobs at once
133
- local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
134
- metaKey, eventStreamKey, prefix, timestamp)
145
+ local function promoteDelayedJobs(delayedKey, targetKey, priorityKey,
146
+ eventStreamKey, prefix, timestamp)
135
147
  local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000, "LIMIT", 0, 1000)
136
148
  if (#jobs > 0) then
137
149
  rcall("ZREM", delayedKey, unpack(jobs))
138
- -- check if we need to use push in paused instead of waiting
139
- local target = getTargetQueueList(metaKey, waitKey, pausedKey)
140
150
  for _, jobId in ipairs(jobs) do
141
151
  local priority =
142
152
  tonumber(rcall("HGET", prefix .. jobId, "priority")) or 0
143
153
  if priority == 0 then
144
154
  -- LIFO or FIFO
145
- rcall("LPUSH", target, jobId)
155
+ rcall("LPUSH", targetKey, jobId)
146
156
  else
147
- addJobWithPriority(priorityKey, priority, target, jobId)
157
+ addJobWithPriority(priorityKey, priority, targetKey, jobId)
148
158
  end
149
159
  -- Emit waiting event
150
160
  rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId",
@@ -153,52 +163,42 @@ local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
153
163
  end
154
164
  end
155
165
  end
156
- local function getRateLimitTTL(opts, limiterKey)
157
- local maxJobs = tonumber(opts['limiter'] and opts['limiter']['max'])
158
- if maxJobs then
159
- local jobCounter = tonumber(rcall("GET", limiterKey))
160
- if jobCounter ~= nil and jobCounter >= maxJobs then
161
- local pttl = rcall("PTTL", limiterKey)
162
- if pttl > 0 then
163
- return pttl
164
- end
165
- end
166
- end
167
- return 0
168
- end
166
+ local target = getTargetQueueList(KEYS[9], KEYS[1], KEYS[8])
169
167
  -- Check if there are delayed jobs that we can move to wait.
170
- promoteDelayedJobs(KEYS[7], KEYS[1], KEYS[3], KEYS[8], KEYS[9], KEYS[4], ARGV[1], ARGV[2])
168
+ promoteDelayedJobs(KEYS[7], target, KEYS[3], KEYS[4], ARGV[1], ARGV[2])
171
169
  local opts
172
170
  if (ARGV[3] ~= "") then
173
- jobId = ARGV[3]
174
- -- clean stalled key
175
- rcall("SREM", KEYS[5], jobId)
171
+ jobId = ARGV[3]
172
+ -- clean stalled key
173
+ rcall("SREM", KEYS[5], jobId)
176
174
  else
177
- -- Check if we are rate limited first.
178
- opts = cmsgpack.unpack(ARGV[4])
179
- local pttl = getRateLimitTTL(opts, KEYS[6])
180
- if pttl > 0 then
181
- return { 0, 0, pttl }
182
- end
183
- -- no job ID, try non-blocking move from wait to active
184
- jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
175
+ -- Check if we are rate limited first.
176
+ opts = cmsgpack.unpack(ARGV[4])
177
+ local pttl = getRateLimitTTL(opts, KEYS[6])
178
+ if pttl > 0 then
179
+ return { 0, 0, pttl }
180
+ end
181
+ -- no job ID, try non-blocking move from wait to active
182
+ jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
185
183
  end
186
184
  -- If jobId is special ID 0:delay, then there is no job to process
187
- if jobId then
188
- if string.sub(jobId, 1, 2) == "0:" then
189
- rcall("LREM", KEYS[2], 1, jobId)
190
- -- Move again since we just got the marker job.
191
- jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
192
- if jobId and string.sub(jobId, 1, 2) == "0:" then
193
- rcall("LREM", KEYS[2], 1, jobId)
194
- jobId = nil
195
- end
196
- end
197
- if jobId then
198
- opts = opts or cmsgpack.unpack(ARGV[4])
199
- -- this script is not really moving, it is preparing the job for processing
200
- return moveJobFromWaitToActive(KEYS, ARGV[1], jobId, ARGV[2], opts)
185
+ if jobId then
186
+ if string.sub(jobId, 1, 2) == "0:" then
187
+ rcall("LREM", KEYS[2], 1, jobId)
188
+ -- Move again since we just got the marker job.
189
+ jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
190
+ -- Since it is possible that between a call to BRPOPLPUSH and moveToActive
191
+ -- another script puts a new maker in wait, we need to check again.
192
+ if jobId and string.sub(jobId, 1, 2) == "0:" then
193
+ rcall("LREM", KEYS[2], 1, jobId)
194
+ jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
201
195
  end
196
+ end
197
+ if jobId then
198
+ opts = opts or cmsgpack.unpack(ARGV[4])
199
+ -- this script is not really moving, it is preparing the job for processing
200
+ return moveJobFromWaitToActive(KEYS, ARGV[1], jobId, ARGV[2], opts)
201
+ end
202
202
  end
203
203
  -- Return the timestamp for the next delayed job if any.
204
204
  local nextTimestamp = getNextDelayedTimestamp(KEYS[7])
@@ -43,11 +43,11 @@ local function getNextDelayedTimestamp(delayedKey)
43
43
  return nextTimestamp
44
44
  end
45
45
  end
46
- local function addDelayMarkerIfNeeded(target, delayedKey)
47
- if rcall("LLEN", target) == 0 then
46
+ local function addDelayMarkerIfNeeded(targetKey, delayedKey)
47
+ if rcall("LLEN", targetKey) == 0 then
48
48
  local nextTimestamp = getNextDelayedTimestamp(delayedKey)
49
49
  if nextTimestamp ~= nil then
50
- rcall("LPUSH", target, "0:" .. nextTimestamp)
50
+ rcall("LPUSH", targetKey, "0:" .. nextTimestamp)
51
51
  end
52
52
  end
53
53
  end
@@ -68,7 +68,6 @@ end
68
68
  Events:
69
69
  'waiting'
70
70
  ]]
71
- local rcall = redis.call
72
71
  -- Includes
73
72
  --[[
74
73
  Function to add job considering priority.
@@ -85,21 +84,19 @@ local function addJobWithPriority(priorityKey, priority, targetKey, jobId)
85
84
  end
86
85
  end
87
86
  -- Try to get as much as 1000 jobs at once
88
- local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
89
- metaKey, eventStreamKey, prefix, timestamp)
87
+ local function promoteDelayedJobs(delayedKey, targetKey, priorityKey,
88
+ eventStreamKey, prefix, timestamp)
90
89
  local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000, "LIMIT", 0, 1000)
91
90
  if (#jobs > 0) then
92
91
  rcall("ZREM", delayedKey, unpack(jobs))
93
- -- check if we need to use push in paused instead of waiting
94
- local target = getTargetQueueList(metaKey, waitKey, pausedKey)
95
92
  for _, jobId in ipairs(jobs) do
96
93
  local priority =
97
94
  tonumber(rcall("HGET", prefix .. jobId, "priority")) or 0
98
95
  if priority == 0 then
99
96
  -- LIFO or FIFO
100
- rcall("LPUSH", target, jobId)
97
+ rcall("LPUSH", targetKey, jobId)
101
98
  else
102
- addJobWithPriority(priorityKey, priority, target, jobId)
99
+ addJobWithPriority(priorityKey, priority, targetKey, jobId)
103
100
  end
104
101
  -- Emit waiting event
105
102
  rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId",
@@ -110,30 +107,30 @@ local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
110
107
  end
111
108
  local jobKey = KEYS[5]
112
109
  if rcall("EXISTS", jobKey) == 1 then
113
- local delayedKey = KEYS[4]
114
- if ARGV[5] ~= "0" then
115
- local lockKey = jobKey .. ':lock'
116
- if rcall("GET", lockKey) == ARGV[5] then
117
- rcall("DEL", lockKey)
118
- else
119
- return -2
120
- end
121
- end
122
- local jobId = ARGV[4]
123
- local score = tonumber(ARGV[3])
124
- local delayedTimestamp = (score / 0x1000)
125
- local numRemovedElements = rcall("LREM", KEYS[2], -1, jobId)
126
- if (numRemovedElements < 1) then
127
- 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
128
117
  end
129
- rcall("ZADD", delayedKey, score, jobId)
130
- rcall("XADD", KEYS[6], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp)
131
- -- Check if we need to push a marker job to wake up sleeping workers.
132
- local target = getTargetQueueList(KEYS[8], KEYS[1], KEYS[7])
133
- addDelayMarkerIfNeeded(target, delayedKey)
134
- 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
135
132
  else
136
- return -1
133
+ return -1
137
134
  end
138
135
  `;
139
136
  exports.moveToDelayed = {
@@ -1 +1 @@
1
- {"version":3,"file":"moveToDelayed-8.js","sourceRoot":"","sources":["../../../src/scripts/moveToDelayed-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsIf,CAAC;AACW,QAAA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmIf,CAAC;AACW,QAAA,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -198,7 +198,6 @@ end
198
198
  Events:
199
199
  'waiting'
200
200
  ]]
201
- local rcall = redis.call
202
201
  -- Includes
203
202
  --[[
204
203
  Function to add job considering priority.
@@ -214,33 +213,20 @@ local function addJobWithPriority(priorityKey, priority, targetKey, jobId)
214
213
  rcall("RPUSH", targetKey, jobId)
215
214
  end
216
215
  end
217
- --[[
218
- Function to check for the meta.paused key to decide if we are paused or not
219
- (since an empty list and !EXISTS are not really the same).
220
- ]]
221
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
222
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
223
- return waitKey
224
- else
225
- return pausedKey
226
- end
227
- end
228
216
  -- Try to get as much as 1000 jobs at once
229
- local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
230
- metaKey, eventStreamKey, prefix, timestamp)
217
+ local function promoteDelayedJobs(delayedKey, targetKey, priorityKey,
218
+ eventStreamKey, prefix, timestamp)
231
219
  local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000, "LIMIT", 0, 1000)
232
220
  if (#jobs > 0) then
233
221
  rcall("ZREM", delayedKey, unpack(jobs))
234
- -- check if we need to use push in paused instead of waiting
235
- local target = getTargetQueueList(metaKey, waitKey, pausedKey)
236
222
  for _, jobId in ipairs(jobs) do
237
223
  local priority =
238
224
  tonumber(rcall("HGET", prefix .. jobId, "priority")) or 0
239
225
  if priority == 0 then
240
226
  -- LIFO or FIFO
241
- rcall("LPUSH", target, jobId)
227
+ rcall("LPUSH", targetKey, jobId)
242
228
  else
243
- addJobWithPriority(priorityKey, priority, target, jobId)
229
+ addJobWithPriority(priorityKey, priority, targetKey, jobId)
244
230
  end
245
231
  -- Emit waiting event
246
232
  rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId",
@@ -272,6 +258,17 @@ end
272
258
  local getJobKeyPrefix = function (jobKey, jobId)
273
259
  return string.sub(jobKey, 0, #jobKey - #jobId)
274
260
  end
261
+ --[[
262
+ Function to check for the meta.paused key to decide if we are paused or not
263
+ (since an empty list and !EXISTS are not really the same).
264
+ ]]
265
+ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
266
+ if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
267
+ return waitKey
268
+ else
269
+ return pausedKey
270
+ end
271
+ end
275
272
  local function moveParentToWait(parentPrefix, parentId, emitEvent)
276
273
  local parentTarget = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "wait", parentPrefix .. "paused")
277
274
  rcall("RPUSH", parentTarget, parentId)
@@ -379,11 +376,11 @@ end
379
376
  Add delay marker if needed.
380
377
  ]]
381
378
  -- Includes
382
- local function addDelayMarkerIfNeeded(target, delayedKey)
383
- if rcall("LLEN", target) == 0 then
379
+ local function addDelayMarkerIfNeeded(targetKey, delayedKey)
380
+ if rcall("LLEN", targetKey) == 0 then
384
381
  local nextTimestamp = getNextDelayedTimestamp(delayedKey)
385
382
  if nextTimestamp ~= nil then
386
- rcall("LPUSH", target, "0:" .. nextTimestamp)
383
+ rcall("LPUSH", targetKey, "0:" .. nextTimestamp)
387
384
  end
388
385
  end
389
386
  end
@@ -421,7 +418,7 @@ local function getRateLimitTTL(opts, limiterKey)
421
418
  if jobCounter ~= nil and jobCounter >= maxJobs then
422
419
  local pttl = rcall("PTTL", limiterKey)
423
420
  if pttl > 0 then
424
- return pttl
421
+ return pttl
425
422
  end
426
423
  end
427
424
  end
@@ -529,8 +526,9 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
529
526
  -- Try to get next job to avoid an extra roundtrip if the queue is not closing,
530
527
  -- and not rate limited.
531
528
  if (ARGV[7] == "1") then
529
+ local target = getTargetQueueList(KEYS[11], KEYS[1], KEYS[8])
532
530
  -- Check if there are delayed jobs that can be promoted
533
- promoteDelayedJobs(KEYS[7], KEYS[1], KEYS[3], KEYS[8], KEYS[11],
531
+ promoteDelayedJobs(KEYS[7], target, KEYS[3],
534
532
  KEYS[4], ARGV[8], timestamp)
535
533
  -- Check if we are rate limited first.
536
534
  local pttl = getRateLimitTTL(opts, KEYS[6])
@@ -1 +1 @@
1
- {"version":3,"file":"moveToFinished-12.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-12.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAojBf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
1
+ {"version":3,"file":"moveToFinished-12.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-12.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkjBf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pause = void 0;
4
4
  const content = `--[[
5
5
  Pauses or resumes a queue globably.
6
- Input:
7
- KEYS[1] 'wait' or 'paused''
8
- KEYS[2] 'paused' or 'wait'
9
- KEYS[3] 'meta'
10
- KEYS[4] events stream key
11
- ARGV[1] 'paused' or 'resumed'
12
- Event:
13
- publish paused or resumed event.
6
+ Input:
7
+ KEYS[1] 'wait' or 'paused''
8
+ KEYS[2] 'paused' or 'wait'
9
+ KEYS[3] 'meta'
10
+ KEYS[4] events stream key
11
+ ARGV[1] 'paused' or 'resumed'
12
+ Event:
13
+ publish paused or resumed event.
14
14
  ]]
15
15
  local rcall = redis.call
16
16
  if rcall("EXISTS", KEYS[1]) == 1 then
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.promote = void 0;
4
4
  const content = `--[[
5
5
  Promotes a job that is currently "delayed" to the "waiting" state
6
- Input:
6
+ Input:
7
7
  KEYS[1] 'delayed'
8
8
  KEYS[2] 'wait'
9
9
  KEYS[3] 'paused'
@@ -12,10 +12,13 @@ const content = `--[[
12
12
  KEYS[6] 'event stream'
13
13
  ARGV[1] queue.toKey('')
14
14
  ARGV[2] jobId
15
- Events:
15
+ Output:
16
+ 0 - OK
17
+ -3 - Job not in delayed zset.
18
+ Events:
16
19
  'waiting'
17
20
  ]]
18
- local rcall = redis.call;
21
+ local rcall = redis.call
19
22
  local jobId = ARGV[2]
20
23
  -- Includes
21
24
  --[[
@@ -1 +1 @@
1
- {"version":3,"file":"promote-6.js","sourceRoot":"","sources":["../../../src/scripts/promote-6.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgEZ,CAAC;AACQ,QAAA,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;AACQ,QAAA,OAAO,GAAG;IACrB,IAAI,EAAE,SAAS;IACf,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -12,6 +12,8 @@ const content = `--[[
12
12
  Output:
13
13
  0 - OK
14
14
  1 - Missing repeat job
15
+ Events:
16
+ 'removed'
15
17
  ]]
16
18
  local rcall = redis.call
17
19
  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;AACW,QAAA,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;AACW,QAAA,gBAAgB,GAAG;IAC9B,IAAI,EAAE,kBAAkB;IACxB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -15,7 +15,7 @@ const content = `--[[
15
15
  ARGV[3] propVal - failedReason/returnvalue
16
16
  ARGV[4] prev state - failed/completed
17
17
  Output:
18
- 1 means the operation was a success
18
+ 1 means the operation was a success
19
19
  -1 means the job does not exist
20
20
  -3 means the job was not found in the expected set.
21
21
  ]]
@@ -43,7 +43,6 @@ end
43
43
  Events:
44
44
  'waiting'
45
45
  ]]
46
- local rcall = redis.call
47
46
  -- Includes
48
47
  --[[
49
48
  Function to add job considering priority.
@@ -60,21 +59,19 @@ local function addJobWithPriority(priorityKey, priority, targetKey, jobId)
60
59
  end
61
60
  end
62
61
  -- Try to get as much as 1000 jobs at once
63
- local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
64
- metaKey, eventStreamKey, prefix, timestamp)
62
+ local function promoteDelayedJobs(delayedKey, targetKey, priorityKey,
63
+ eventStreamKey, prefix, timestamp)
65
64
  local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000, "LIMIT", 0, 1000)
66
65
  if (#jobs > 0) then
67
66
  rcall("ZREM", delayedKey, unpack(jobs))
68
- -- check if we need to use push in paused instead of waiting
69
- local target = getTargetQueueList(metaKey, waitKey, pausedKey)
70
67
  for _, jobId in ipairs(jobs) do
71
68
  local priority =
72
69
  tonumber(rcall("HGET", prefix .. jobId, "priority")) or 0
73
70
  if priority == 0 then
74
71
  -- LIFO or FIFO
75
- rcall("LPUSH", target, jobId)
72
+ rcall("LPUSH", targetKey, jobId)
76
73
  else
77
- addJobWithPriority(priorityKey, priority, target, jobId)
74
+ addJobWithPriority(priorityKey, priority, targetKey, jobId)
78
75
  end
79
76
  -- Emit waiting event
80
77
  rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId",
@@ -83,7 +80,8 @@ local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
83
80
  end
84
81
  end
85
82
  end
86
- promoteDelayedJobs(KEYS[7], KEYS[2], KEYS[8], KEYS[3], KEYS[5], KEYS[6], ARGV[1], ARGV[2])
83
+ local target = getTargetQueueList(KEYS[5], KEYS[2], KEYS[3])
84
+ promoteDelayedJobs(KEYS[7], target, KEYS[8], KEYS[6], ARGV[1], ARGV[2])
87
85
  if rcall("EXISTS", KEYS[4]) == 1 then
88
86
  if ARGV[5] ~= "0" then
89
87
  local lockKey = KEYS[4] .. ':lock'
@@ -93,11 +91,10 @@ if rcall("EXISTS", KEYS[4]) == 1 then
93
91
  return -2
94
92
  end
95
93
  end
96
- local target = getTargetQueueList(KEYS[5], KEYS[2], KEYS[3])
97
94
  rcall("LREM", KEYS[1], 0, ARGV[4])
98
95
  rcall(ARGV[3], target, ARGV[4])
99
96
  -- Emit waiting event
100
- rcall("XADD", KEYS[6], "*", "event", "waiting", "jobId", ARGV[4], "prev", "failed");
97
+ rcall("XADD", KEYS[6], "*", "event", "waiting", "jobId", ARGV[4], "prev", "failed")
101
98
  return 0
102
99
  else
103
100
  return -1
@@ -1 +1 @@
1
- {"version":3,"file":"retryJob-8.js","sourceRoot":"","sources":["../../../src/scripts/retryJob-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqGf,CAAC;AACW,QAAA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkGf,CAAC;AACW,QAAA,QAAQ,GAAG;IACtB,IAAI,EAAE,UAAU;IAChB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -8,7 +8,7 @@ const content = `--[[
8
8
  ARGV[1] stacktrace
9
9
  ARGV[2] failedReason
10
10
  Output:
11
- 0 - OK
11
+ 0 - OK
12
12
  -1 - Missing key
13
13
  ]]
14
14
  local rcall = redis.call
@@ -5,7 +5,10 @@ const content = `--[[
5
5
  Update job data
6
6
  Input:
7
7
  KEYS[1] Job id key
8
- ARGV[1] data
8
+ ARGV[1] data
9
+ Output:
10
+ 0 - OK
11
+ -1 - Missing job.
9
12
  ]]
10
13
  local rcall = redis.call
11
14
  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;AACW,QAAA,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;AACW,QAAA,UAAU,GAAG;IACxB,IAAI,EAAE,YAAY;IAClB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -8,6 +8,9 @@ const content = `--[[
8
8
  KEYS[2] event stream key
9
9
  ARGV[1] id
10
10
  ARGV[2] progress
11
+ Output:
12
+ 0 - OK
13
+ -1 - Missing job.
11
14
  Event:
12
15
  progress(jobId, progress)
13
16
  ]]
@@ -1 +1 @@
1
- {"version":3,"file":"updateProgress-2.js","sourceRoot":"","sources":["../../../src/scripts/updateProgress-2.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;CAkBf,CAAC;AACW,QAAA,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;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}