bullmq 3.2.2 → 3.2.4
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.
- package/dist/cjs/classes/job.d.ts +1 -1
- package/dist/cjs/classes/queue-getters.d.ts +21 -22
- package/dist/cjs/classes/queue-getters.js +21 -22
- package/dist/cjs/classes/queue-getters.js.map +1 -1
- package/dist/cjs/classes/queue-keys.d.ts +1 -1
- package/dist/cjs/classes/queue.d.ts +4 -5
- package/dist/cjs/classes/queue.js +4 -5
- package/dist/cjs/classes/queue.js.map +1 -1
- package/dist/cjs/classes/scripts.d.ts +3 -3
- package/dist/cjs/classes/worker.js +3 -3
- package/dist/cjs/classes/worker.js.map +1 -1
- package/dist/cjs/commands/addJob-8.lua +42 -41
- package/dist/cjs/commands/includes/getNextDelayedTimestamp.lua +7 -7
- package/dist/cjs/commands/includes/getRateLimitTTL.lua +10 -10
- package/dist/cjs/commands/includes/getTimestamp.lua +1 -1
- package/dist/cjs/commands/includes/isLocked.lua +12 -12
- package/dist/cjs/commands/includes/moveJobFromWaitToActive.lua +4 -0
- package/dist/cjs/interfaces/connection.d.ts +1 -1
- package/dist/cjs/interfaces/flow-job.d.ts +3 -3
- package/dist/cjs/interfaces/redis-options.d.ts +3 -3
- package/dist/cjs/interfaces/redis-streams.d.ts +4 -4
- package/dist/cjs/interfaces/sandboxed-job-processor.d.ts +1 -1
- package/dist/cjs/interfaces/worker-options.d.ts +1 -1
- package/dist/cjs/scripts/addJob-8.js +47 -47
- package/dist/cjs/scripts/moveToActive-9.js +19 -17
- package/dist/cjs/scripts/moveToActive-9.js.map +1 -1
- package/dist/cjs/scripts/moveToDelayed-8.js +7 -7
- package/dist/cjs/scripts/moveToFinished-12.js +19 -17
- package/dist/cjs/scripts/moveToFinished-12.js.map +1 -1
- package/dist/cjs/scripts/removeJob-1.js +12 -12
- package/dist/cjs/types/backoff-strategy.d.ts +1 -1
- package/dist/cjs/types/finished-status.d.ts +2 -2
- package/dist/cjs/types/job-json-sandbox.d.ts +1 -1
- package/dist/cjs/types/job-options.d.ts +2 -2
- package/dist/cjs/types/job-type.d.ts +2 -2
- package/dist/cjs/types/repeat-strategy.d.ts +1 -1
- package/dist/esm/classes/job.d.ts +1 -1
- package/dist/esm/classes/queue-getters.d.ts +21 -22
- package/dist/esm/classes/queue-getters.js +21 -22
- package/dist/esm/classes/queue-getters.js.map +1 -1
- package/dist/esm/classes/queue-keys.d.ts +1 -1
- package/dist/esm/classes/queue.d.ts +4 -5
- package/dist/esm/classes/queue.js +4 -5
- package/dist/esm/classes/queue.js.map +1 -1
- package/dist/esm/classes/scripts.d.ts +3 -3
- package/dist/esm/classes/worker.js +3 -3
- package/dist/esm/classes/worker.js.map +1 -1
- package/dist/esm/commands/addJob-8.lua +42 -41
- package/dist/esm/commands/includes/getNextDelayedTimestamp.lua +7 -7
- package/dist/esm/commands/includes/getRateLimitTTL.lua +10 -10
- package/dist/esm/commands/includes/getTimestamp.lua +1 -1
- package/dist/esm/commands/includes/isLocked.lua +12 -12
- package/dist/esm/commands/includes/moveJobFromWaitToActive.lua +4 -0
- package/dist/esm/interfaces/connection.d.ts +1 -1
- package/dist/esm/interfaces/flow-job.d.ts +3 -3
- package/dist/esm/interfaces/redis-options.d.ts +3 -3
- package/dist/esm/interfaces/redis-streams.d.ts +4 -4
- package/dist/esm/interfaces/sandboxed-job-processor.d.ts +1 -1
- package/dist/esm/interfaces/worker-options.d.ts +1 -1
- package/dist/esm/scripts/addJob-8.js +47 -47
- package/dist/esm/scripts/moveToActive-9.js +19 -17
- package/dist/esm/scripts/moveToActive-9.js.map +1 -1
- package/dist/esm/scripts/moveToDelayed-8.js +7 -7
- package/dist/esm/scripts/moveToFinished-12.js +19 -17
- package/dist/esm/scripts/moveToFinished-12.js.map +1 -1
- package/dist/esm/scripts/removeJob-1.js +12 -12
- package/dist/esm/types/backoff-strategy.d.ts +1 -1
- package/dist/esm/types/finished-status.d.ts +2 -2
- package/dist/esm/types/job-json-sandbox.d.ts +1 -1
- package/dist/esm/types/job-options.d.ts +2 -2
- package/dist/esm/types/job-type.d.ts +2 -2
- package/dist/esm/types/repeat-strategy.d.ts +1 -1
- package/package.json +1 -1
@@ -88,14 +88,14 @@ end
|
|
88
88
|
Function to return the next delayed job timestamp.
|
89
89
|
]]
|
90
90
|
local function getNextDelayedTimestamp(delayedKey)
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
97
|
-
return nextTimestamp
|
91
|
+
local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
|
92
|
+
if #result then
|
93
|
+
local nextTimestamp = tonumber(result[2])
|
94
|
+
if (nextTimestamp ~= nil) then
|
95
|
+
nextTimestamp = nextTimestamp / 0x1000
|
98
96
|
end
|
97
|
+
return nextTimestamp
|
98
|
+
end
|
99
99
|
end
|
100
100
|
if parentKey ~= nil then
|
101
101
|
if rcall("EXISTS", parentKey) ~= 1 then
|
@@ -151,21 +151,21 @@ if args[2] == "" then
|
|
151
151
|
else
|
152
152
|
jobId = args[2]
|
153
153
|
jobIdKey = args[1] .. jobId
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
154
|
+
end
|
155
|
+
if rcall("EXISTS", jobIdKey) == 1 then
|
156
|
+
if parentKey ~= nil then
|
157
|
+
if rcall("ZSCORE", KEYS[7], jobId) ~= false then
|
158
|
+
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
159
|
+
updateParentDepsIfNeeded(parentKey, parent['queueKey'], parentDependenciesKey,
|
160
|
+
parent['id'], jobIdKey, returnvalue, timestamp)
|
161
|
+
else
|
162
|
+
if parentDependenciesKey ~= nil then
|
163
|
+
rcall("SADD", parentDependenciesKey, jobIdKey)
|
164
164
|
end
|
165
|
-
rcall("HMSET", jobIdKey, "parentKey", parentKey, "parent", parentData)
|
166
165
|
end
|
167
|
-
|
166
|
+
rcall("HMSET", jobIdKey, "parentKey", parentKey, "parent", parentData)
|
168
167
|
end
|
168
|
+
return jobId .. "" -- convert to string
|
169
169
|
end
|
170
170
|
-- Store the job.
|
171
171
|
local jsonOpts = cjson.encode(opts)
|
@@ -190,42 +190,42 @@ local delayedTimestamp = (delay > 0 and (timestamp + delay)) or 0
|
|
190
190
|
-- Check if job is a parent, if so add to the parents set
|
191
191
|
local waitChildrenKey = args[6]
|
192
192
|
if waitChildrenKey ~= nil then
|
193
|
-
|
194
|
-
|
193
|
+
rcall("ZADD", waitChildrenKey, timestamp, jobId)
|
194
|
+
rcall("XADD", KEYS[8], "*", "event", "waiting-children", "jobId", jobId)
|
195
195
|
elseif (delayedTimestamp ~= 0) then
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
end
|
196
|
+
local score = delayedTimestamp * 0x1000 + bit.band(jobCounter, 0xfff)
|
197
|
+
rcall("ZADD", KEYS[5], score, jobId)
|
198
|
+
rcall("XADD", KEYS[8], "*", "event", "delayed", "jobId", jobId, "delay",
|
199
|
+
delayedTimestamp)
|
200
|
+
-- If wait list is empty, and this delayed job is the next one to be processed,
|
201
|
+
-- then we need to signal the workers by adding a dummy job (jobId 0:delay) to the wait list.
|
202
|
+
local target = getTargetQueueList(KEYS[3], KEYS[1], KEYS[2])
|
203
|
+
if rcall("LLEN", target) == 0 then
|
204
|
+
local nextTimestamp = getNextDelayedTimestamp(KEYS[5])
|
205
|
+
if not nextTimestamp or (delayedTimestamp < nextTimestamp) then
|
206
|
+
local delay = delayedTimestamp - tonumber(timestamp)
|
207
|
+
rcall("LPUSH", target, "0:" .. delay)
|
209
208
|
end
|
209
|
+
end
|
210
210
|
else
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
211
|
+
local target = getTargetQueueList(KEYS[3], KEYS[1], KEYS[2])
|
212
|
+
-- Standard or priority add
|
213
|
+
if priority == 0 then
|
214
|
+
-- LIFO or FIFO
|
215
|
+
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH';
|
216
|
+
rcall(pushCmd, target, jobId)
|
217
|
+
else
|
218
|
+
-- Priority add
|
219
|
+
addJobWithPriority(KEYS[6], priority, target, jobId)
|
220
|
+
end
|
221
|
+
-- Emit waiting event
|
222
|
+
rcall("XADD", KEYS[8], "*", "event", "waiting", "jobId", jobId)
|
223
223
|
end
|
224
224
|
-- Check if this job is a child of another job, if so add it to the parents dependencies
|
225
225
|
-- TODO: Should not be possible to add a child job to a parent that is not in the "waiting-children" status.
|
226
226
|
-- fail in this case.
|
227
227
|
if parentDependenciesKey ~= nil then
|
228
|
-
|
228
|
+
rcall("SADD", parentDependenciesKey, jobIdKey)
|
229
229
|
end
|
230
230
|
return jobId .. "" -- convert to string
|
231
231
|
`;
|
@@ -49,6 +49,8 @@ local function moveJobFromWaitToActive(keys, keyPrefix, jobId, processedOn, opts
|
|
49
49
|
local expireTime
|
50
50
|
if(maxJobs) then
|
51
51
|
local rateLimiterKey = keys[6];
|
52
|
+
expireTime = tonumber(rcall("PTTL", rateLimiterKey))
|
53
|
+
if expireTime == 0 then rcall("DEL", rateLimiterKey) end
|
52
54
|
local jobCounter = tonumber(rcall("INCR", rateLimiterKey))
|
53
55
|
if jobCounter == 1 then
|
54
56
|
local limiterDuration = opts['limiter'] and opts['limiter']['duration']
|
@@ -84,14 +86,14 @@ end
|
|
84
86
|
Function to return the next delayed job timestamp.
|
85
87
|
]]
|
86
88
|
local function getNextDelayedTimestamp(delayedKey)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
93
|
-
return nextTimestamp
|
89
|
+
local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
|
90
|
+
if #result then
|
91
|
+
local nextTimestamp = tonumber(result[2])
|
92
|
+
if (nextTimestamp ~= nil) then
|
93
|
+
nextTimestamp = nextTimestamp / 0x1000
|
94
94
|
end
|
95
|
+
return nextTimestamp
|
96
|
+
end
|
95
97
|
end
|
96
98
|
--[[
|
97
99
|
Updates the delay set, by moving delayed jobs that should
|
@@ -151,17 +153,17 @@ local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
|
|
151
153
|
end
|
152
154
|
end
|
153
155
|
local function getRateLimitTTL(opts, limiterKey)
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
end
|
156
|
+
local maxJobs = tonumber(opts['limiter'] and opts['limiter']['max'])
|
157
|
+
if maxJobs then
|
158
|
+
local jobCounter = tonumber(rcall("GET", limiterKey))
|
159
|
+
if jobCounter ~= nil and jobCounter >= maxJobs then
|
160
|
+
local pttl = rcall("PTTL", KEYS[6])
|
161
|
+
if pttl > 0 then
|
162
|
+
return pttl
|
163
|
+
end
|
163
164
|
end
|
164
|
-
|
165
|
+
end
|
166
|
+
return 0
|
165
167
|
end
|
166
168
|
-- Check if there are delayed jobs that we can move to wait.
|
167
169
|
promoteDelayedJobs(KEYS[7], KEYS[1], KEYS[3], KEYS[8], KEYS[9], KEYS[4], ARGV[1], ARGV[2])
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"moveToActive-9.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"moveToActive-9.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Mf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -84,14 +84,14 @@ end
|
|
84
84
|
Function to return the next delayed job timestamp.
|
85
85
|
]]
|
86
86
|
local function getNextDelayedTimestamp(delayedKey)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
93
|
-
return nextTimestamp
|
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
|
94
92
|
end
|
93
|
+
return nextTimestamp
|
94
|
+
end
|
95
95
|
end
|
96
96
|
local jobKey = KEYS[5]
|
97
97
|
if rcall("EXISTS", jobKey) == 1 then
|
@@ -105,14 +105,14 @@ end
|
|
105
105
|
Function to return the next delayed job timestamp.
|
106
106
|
]]
|
107
107
|
local function getNextDelayedTimestamp(delayedKey)
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
114
|
-
return nextTimestamp
|
108
|
+
local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
|
109
|
+
if #result then
|
110
|
+
local nextTimestamp = tonumber(result[2])
|
111
|
+
if (nextTimestamp ~= nil) then
|
112
|
+
nextTimestamp = nextTimestamp / 0x1000
|
115
113
|
end
|
114
|
+
return nextTimestamp
|
115
|
+
end
|
116
116
|
end
|
117
117
|
--[[
|
118
118
|
Function to move job from wait state to active.
|
@@ -135,6 +135,8 @@ local function moveJobFromWaitToActive(keys, keyPrefix, jobId, processedOn, opts
|
|
135
135
|
local expireTime
|
136
136
|
if(maxJobs) then
|
137
137
|
local rateLimiterKey = keys[6];
|
138
|
+
expireTime = tonumber(rcall("PTTL", rateLimiterKey))
|
139
|
+
if expireTime == 0 then rcall("DEL", rateLimiterKey) end
|
138
140
|
local jobCounter = tonumber(rcall("INCR", rateLimiterKey))
|
139
141
|
if jobCounter == 1 then
|
140
142
|
local limiterDuration = opts['limiter'] and opts['limiter']['duration']
|
@@ -411,17 +413,17 @@ local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDepende
|
|
411
413
|
end
|
412
414
|
end
|
413
415
|
local function getRateLimitTTL(opts, limiterKey)
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
end
|
416
|
+
local maxJobs = tonumber(opts['limiter'] and opts['limiter']['max'])
|
417
|
+
if maxJobs then
|
418
|
+
local jobCounter = tonumber(rcall("GET", limiterKey))
|
419
|
+
if jobCounter ~= nil and jobCounter >= maxJobs then
|
420
|
+
local pttl = rcall("PTTL", KEYS[6])
|
421
|
+
if pttl > 0 then
|
422
|
+
return pttl
|
423
|
+
end
|
423
424
|
end
|
424
|
-
|
425
|
+
end
|
426
|
+
return 0
|
425
427
|
end
|
426
428
|
local jobIdKey = KEYS[10]
|
427
429
|
if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"moveToFinished-12.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-12.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"moveToFinished-12.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-12.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4iBf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
|
@@ -31,19 +31,19 @@ local function isLocked( prefix, jobId)
|
|
31
31
|
local lockKey = jobKey .. ':lock'
|
32
32
|
local lock = rcall("GET", lockKey)
|
33
33
|
if not lock then
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
34
|
+
local dependencies = rcall("SMEMBERS", jobKey .. ":dependencies")
|
35
|
+
if (#dependencies > 0) then
|
36
|
+
for i, childJobKey in ipairs(dependencies) do
|
37
|
+
-- We need to get the jobId for this job.
|
38
|
+
local childJobId = getJobIdFromKey(childJobKey)
|
39
|
+
local childJobPrefix = getJobKeyPrefix(childJobKey, childJobId)
|
40
|
+
local result = isLocked( childJobPrefix, childJobId )
|
41
|
+
if result then
|
42
|
+
return true
|
43
|
+
end
|
45
44
|
end
|
46
|
-
|
45
|
+
end
|
46
|
+
return false
|
47
47
|
end
|
48
48
|
return true
|
49
49
|
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
import { Job } from '../classes/job';
|
2
|
-
export
|
2
|
+
export type BackoffStrategy = (attemptsMade?: number, type?: string, err?: Error, job?: Job) => Promise<number> | number;
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export
|
2
|
-
export
|
1
|
+
export type FinishedStatus = 'completed' | 'failed';
|
2
|
+
export type FinishedPropValAttribute = 'returnvalue' | 'failedReason';
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { BaseJobOptions } from '../interfaces';
|
2
|
-
export
|
2
|
+
export type JobsOptions = BaseJobOptions & {
|
3
3
|
/**
|
4
4
|
* If true, moves parent to failed.
|
5
5
|
*/
|
@@ -8,7 +8,7 @@ export declare type JobsOptions = BaseJobOptions & {
|
|
8
8
|
/**
|
9
9
|
* These fields are the ones stored in Redis with smaller keys for compactness.
|
10
10
|
*/
|
11
|
-
export
|
11
|
+
export type RedisJobOptions = BaseJobOptions & {
|
12
12
|
/**
|
13
13
|
* If true, moves parent to failed.
|
14
14
|
*/
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import { FinishedStatus } from './finished-status';
|
2
|
-
export
|
3
|
-
export
|
2
|
+
export type JobState = FinishedStatus | 'active' | 'delayed' | 'waiting' | 'waiting-children';
|
3
|
+
export type JobType = JobState | 'paused' | 'repeat' | 'wait';
|
@@ -1,2 +1,2 @@
|
|
1
1
|
import { RepeatOptions } from '../interfaces/repeat-options';
|
2
|
-
export
|
2
|
+
export type RepeatStrategy = (millis: number, opts: RepeatOptions, name?: string) => number;
|