bullmq 5.41.7 → 5.41.9
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-scheduler.js +11 -18
- package/dist/cjs/classes/job-scheduler.js.map +1 -1
- package/dist/cjs/classes/job.js +1 -0
- package/dist/cjs/classes/job.js.map +1 -1
- package/dist/cjs/classes/scripts.js +28 -2
- package/dist/cjs/classes/scripts.js.map +1 -1
- package/dist/cjs/commands/addJobScheduler-10.lua +9 -37
- package/dist/cjs/commands/addRepeatableJob-2.lua +2 -2
- package/dist/cjs/commands/getState-8.lua +5 -5
- package/dist/cjs/commands/getStateV2-8.lua +8 -8
- package/dist/cjs/commands/includes/addJobFromScheduler.lua +41 -0
- package/dist/cjs/commands/includes/isJobSchedulerJob.lua +1 -1
- package/dist/cjs/commands/includes/trimEvents.lua +1 -1
- package/dist/cjs/commands/includes/updateExistingJobsParent.lua +1 -1
- package/dist/cjs/commands/isFinished-3.lua +2 -2
- package/dist/cjs/commands/{updateJobScheduler-7.lua → updateJobScheduler-11.lua} +28 -21
- package/dist/cjs/commands/updateRepeatableJobMillis-1.lua +1 -1
- package/dist/cjs/scripts/addDelayedJob-6.js +1 -1
- package/dist/cjs/scripts/addJobScheduler-10.js +94 -84
- package/dist/cjs/scripts/addJobScheduler-10.js.map +1 -1
- package/dist/cjs/scripts/addParentJob-4.js +1 -1
- package/dist/cjs/scripts/addPrioritizedJob-8.js +1 -1
- package/dist/cjs/scripts/addRepeatableJob-2.js +2 -2
- package/dist/cjs/scripts/addStandardJob-8.js +1 -1
- package/dist/cjs/scripts/cleanJobsInSet-3.js +1 -1
- package/dist/cjs/scripts/getState-8.js +5 -5
- package/dist/cjs/scripts/getStateV2-8.js +8 -8
- package/dist/cjs/scripts/index.js +1 -1
- package/dist/cjs/scripts/index.js.map +1 -1
- package/dist/cjs/scripts/isFinished-3.js +2 -2
- package/dist/cjs/scripts/moveStalledJobsToWait-9.js +1 -1
- package/dist/cjs/scripts/moveToFinished-14.js +1 -1
- package/dist/cjs/scripts/removeJob-3.js +1 -1
- package/dist/cjs/scripts/updateJobScheduler-11.js +246 -0
- package/dist/cjs/scripts/updateJobScheduler-11.js.map +1 -0
- package/dist/cjs/scripts/updateRepeatableJobMillis-1.js +1 -1
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/classes/job-scheduler.js +11 -18
- package/dist/esm/classes/job-scheduler.js.map +1 -1
- package/dist/esm/classes/job.js +1 -0
- package/dist/esm/classes/job.js.map +1 -1
- package/dist/esm/classes/scripts.d.ts +1 -1
- package/dist/esm/classes/scripts.js +28 -2
- package/dist/esm/classes/scripts.js.map +1 -1
- package/dist/esm/commands/addJobScheduler-10.lua +9 -37
- package/dist/esm/commands/addRepeatableJob-2.lua +2 -2
- package/dist/esm/commands/getState-8.lua +5 -5
- package/dist/esm/commands/getStateV2-8.lua +8 -8
- package/dist/esm/commands/includes/addJobFromScheduler.lua +41 -0
- package/dist/esm/commands/includes/isJobSchedulerJob.lua +1 -1
- package/dist/esm/commands/includes/trimEvents.lua +1 -1
- package/dist/esm/commands/includes/updateExistingJobsParent.lua +1 -1
- package/dist/esm/commands/isFinished-3.lua +2 -2
- package/dist/esm/commands/{updateJobScheduler-7.lua → updateJobScheduler-11.lua} +28 -21
- package/dist/esm/commands/updateRepeatableJobMillis-1.lua +1 -1
- package/dist/esm/interfaces/job-json.d.ts +1 -0
- package/dist/esm/scripts/addDelayedJob-6.js +1 -1
- package/dist/esm/scripts/addJobScheduler-10.js +94 -84
- package/dist/esm/scripts/addJobScheduler-10.js.map +1 -1
- package/dist/esm/scripts/addParentJob-4.js +1 -1
- package/dist/esm/scripts/addPrioritizedJob-8.js +1 -1
- package/dist/esm/scripts/addRepeatableJob-2.js +2 -2
- package/dist/esm/scripts/addStandardJob-8.js +1 -1
- package/dist/esm/scripts/cleanJobsInSet-3.js +1 -1
- package/dist/esm/scripts/getState-8.js +5 -5
- package/dist/esm/scripts/getStateV2-8.js +8 -8
- package/dist/esm/scripts/index.d.ts +1 -1
- package/dist/esm/scripts/index.js +1 -1
- package/dist/esm/scripts/index.js.map +1 -1
- package/dist/esm/scripts/isFinished-3.js +2 -2
- package/dist/esm/scripts/moveStalledJobsToWait-9.js +1 -1
- package/dist/esm/scripts/moveToFinished-14.js +1 -1
- package/dist/esm/scripts/removeJob-3.js +1 -1
- package/dist/esm/scripts/updateJobScheduler-11.js +243 -0
- package/dist/esm/scripts/updateJobScheduler-11.js.map +1 -0
- package/dist/esm/scripts/updateRepeatableJobMillis-1.js +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/scripts/updateJobScheduler-7.js +0 -144
- package/dist/cjs/scripts/updateJobScheduler-7.js.map +0 -1
- package/dist/esm/scripts/updateJobScheduler-7.js +0 -141
- package/dist/esm/scripts/updateJobScheduler-7.js.map +0 -1
- /package/dist/esm/scripts/{updateJobScheduler-7.d.ts → updateJobScheduler-11.d.ts} +0 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
--[[
|
2
|
+
Add delay marker if needed.
|
3
|
+
]]
|
4
|
+
|
5
|
+
-- Includes
|
6
|
+
--- @include "addDelayedJob"
|
7
|
+
--- @include "addJobWithPriority"
|
8
|
+
--- @include "isQueuePaused"
|
9
|
+
--- @include "storeJob"
|
10
|
+
|
11
|
+
local function addJobFromScheduler(jobKey, jobId, rawOpts, waitKey, pausedKey, metaKey, prioritizedKey,
|
12
|
+
priorityCounter, delayedKey, markerKey, eventsKey, name, maxEvents, timestamp, data, jobSchedulerId)
|
13
|
+
local opts = cmsgpack.unpack(rawOpts)
|
14
|
+
|
15
|
+
local delay, priority = storeJob(eventsKey, jobKey, jobId, name, data,
|
16
|
+
opts, timestamp, nil, nil, jobSchedulerId)
|
17
|
+
|
18
|
+
if delay ~= 0 then
|
19
|
+
addDelayedJob(jobId, delayedKey, eventsKey, timestamp, maxEvents, markerKey, delay)
|
20
|
+
else
|
21
|
+
local isPaused = isQueuePaused(metaKey)
|
22
|
+
|
23
|
+
-- Standard or priority add
|
24
|
+
if priority == 0 then
|
25
|
+
if isPaused then
|
26
|
+
-- LIFO or FIFO
|
27
|
+
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
28
|
+
rcall(pushCmd, pausedKey, jobId)
|
29
|
+
else
|
30
|
+
-- LIFO or FIFO
|
31
|
+
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
32
|
+
rcall(pushCmd, waitKey, jobId)
|
33
|
+
end
|
34
|
+
else
|
35
|
+
-- Priority add
|
36
|
+
addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounter, isPaused)
|
37
|
+
end
|
38
|
+
-- Emit waiting event
|
39
|
+
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting", "jobId", jobId)
|
40
|
+
end
|
41
|
+
end
|
@@ -6,7 +6,7 @@ local function isJobSchedulerJob(jobId, jobKey, jobSchedulersKey)
|
|
6
6
|
local repeatJobKey = rcall("HGET", jobKey, "rjk")
|
7
7
|
if repeatJobKey then
|
8
8
|
local prevMillis = rcall("ZSCORE", jobSchedulersKey, repeatJobKey)
|
9
|
-
if prevMillis
|
9
|
+
if prevMillis then
|
10
10
|
local currentDelayedJobId = "repeat:" .. repeatJobKey .. ":" .. prevMillis
|
11
11
|
return jobId == currentDelayedJobId
|
12
12
|
end
|
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
local function trimEvents(metaKey, eventStreamKey)
|
9
9
|
local maxEvents = getOrSetMaxEvents(metaKey)
|
10
|
-
if maxEvents
|
10
|
+
if maxEvents then
|
11
11
|
rcall("XTRIM", eventStreamKey, "MAXLEN", "~", maxEvents)
|
12
12
|
else
|
13
13
|
rcall("XTRIM", eventStreamKey, "MAXLEN", "~", 10000)
|
@@ -12,7 +12,7 @@ local function updateExistingJobsParent(parentKey, parent, parentData,
|
|
12
12
|
parentDependenciesKey, completedKey,
|
13
13
|
jobIdKey, jobId, timestamp)
|
14
14
|
if parentKey ~= nil then
|
15
|
-
if rcall("ZSCORE", completedKey, jobId)
|
15
|
+
if rcall("ZSCORE", completedKey, jobId) then
|
16
16
|
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
17
17
|
updateParentDepsIfNeeded(parentKey, parent['queueKey'],
|
18
18
|
parentDependenciesKey, parent['id'],
|
@@ -23,7 +23,7 @@ if rcall("EXISTS", KEYS[3]) ~= 1 then
|
|
23
23
|
return -1
|
24
24
|
end
|
25
25
|
|
26
|
-
if rcall("ZSCORE", KEYS[1], ARGV[1])
|
26
|
+
if rcall("ZSCORE", KEYS[1], ARGV[1]) then
|
27
27
|
if ARGV[2] == "1" then
|
28
28
|
local returnValue = rcall("HGET", KEYS[3], "returnvalue")
|
29
29
|
|
@@ -32,7 +32,7 @@ if rcall("ZSCORE", KEYS[1], ARGV[1]) ~= false then
|
|
32
32
|
return 1
|
33
33
|
end
|
34
34
|
|
35
|
-
if rcall("ZSCORE", KEYS[2], ARGV[1])
|
35
|
+
if rcall("ZSCORE", KEYS[2], ARGV[1]) then
|
36
36
|
if ARGV[2] == "1" then
|
37
37
|
local failedReason = rcall("HGET", KEYS[3], "failedReason")
|
38
38
|
|
@@ -2,13 +2,17 @@
|
|
2
2
|
Updates a job scheduler and adds next delayed job
|
3
3
|
|
4
4
|
Input:
|
5
|
-
KEYS[1]
|
6
|
-
KEYS[2]
|
7
|
-
KEYS[3]
|
8
|
-
KEYS[4]
|
9
|
-
KEYS[5]
|
10
|
-
KEYS[6]
|
11
|
-
KEYS[7]
|
5
|
+
KEYS[1] 'repeat' key
|
6
|
+
KEYS[2] 'delayed'
|
7
|
+
KEYS[3] 'wait' key
|
8
|
+
KEYS[4] 'paused' key
|
9
|
+
KEYS[5] 'meta'
|
10
|
+
KEYS[6] 'prioritized' key
|
11
|
+
KEYS[7] 'marker',
|
12
|
+
KEYS[8] 'id'
|
13
|
+
KEYS[9] events stream key
|
14
|
+
KEYS[10] 'pc' priority counter
|
15
|
+
KEYS[11] producer key
|
12
16
|
|
13
17
|
ARGV[1] next milliseconds
|
14
18
|
ARGV[2] jobs scheduler id
|
@@ -22,8 +26,12 @@
|
|
22
26
|
next delayed job id - OK
|
23
27
|
]]
|
24
28
|
local rcall = redis.call
|
25
|
-
local repeatKey = KEYS[
|
26
|
-
local delayedKey = KEYS[
|
29
|
+
local repeatKey = KEYS[1]
|
30
|
+
local delayedKey = KEYS[2]
|
31
|
+
local waitKey = KEYS[3]
|
32
|
+
local pausedKey = KEYS[4]
|
33
|
+
local metaKey = KEYS[5]
|
34
|
+
local prioritizedKey = KEYS[6]
|
27
35
|
local nextMillis = ARGV[1]
|
28
36
|
local jobSchedulerId = ARGV[2]
|
29
37
|
local timestamp = ARGV[5]
|
@@ -31,7 +39,7 @@ local prefixKey = ARGV[6]
|
|
31
39
|
local producerId = ARGV[7]
|
32
40
|
|
33
41
|
-- Includes
|
34
|
-
--- @include "includes/
|
42
|
+
--- @include "includes/addJobFromScheduler"
|
35
43
|
--- @include "includes/getOrSetMaxEvents"
|
36
44
|
|
37
45
|
local schedulerKey = repeatKey .. ":" .. jobSchedulerId
|
@@ -43,19 +51,16 @@ local prevMillis = rcall("ZSCORE", repeatKey, jobSchedulerId)
|
|
43
51
|
if prevMillis ~= false then
|
44
52
|
local currentDelayedJobId = "repeat:" .. jobSchedulerId .. ":" .. prevMillis
|
45
53
|
|
46
|
-
if producerId == currentDelayedJobId then
|
54
|
+
if producerId == currentDelayedJobId and rcall("EXISTS", nextDelayedJobKey) ~= 1 then
|
47
55
|
local schedulerAttributes = rcall("HMGET", schedulerKey, "name", "data")
|
48
56
|
|
49
57
|
rcall("ZADD", repeatKey, nextMillis, jobSchedulerId)
|
50
58
|
rcall("HINCRBY", schedulerKey, "ic", 1)
|
51
59
|
|
52
|
-
local eventsKey = KEYS[
|
53
|
-
local metaKey = KEYS[2]
|
60
|
+
local eventsKey = KEYS[9]
|
54
61
|
local maxEvents = getOrSetMaxEvents(metaKey)
|
55
62
|
|
56
|
-
rcall("INCR", KEYS[
|
57
|
-
|
58
|
-
local delayedOpts = cmsgpack.unpack(ARGV[4])
|
63
|
+
rcall("INCR", KEYS[8])
|
59
64
|
|
60
65
|
-- TODO: remove this workaround in next breaking change,
|
61
66
|
-- all job-schedulers must save job data
|
@@ -65,11 +70,13 @@ if prevMillis ~= false then
|
|
65
70
|
rcall("HSET", schedulerKey, "data", templateData)
|
66
71
|
end
|
67
72
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
+
addJobFromScheduler(nextDelayedJobKey, nextDelayedJobId, ARGV[4], waitKey, pausedKey, metaKey, prioritizedKey,
|
74
|
+
KEYS[10], delayedKey, KEYS[7], eventsKey, schedulerAttributes[1], maxEvents, ARGV[5],
|
75
|
+
templateData or '{}', jobSchedulerId)
|
76
|
+
|
77
|
+
-- TODO: remove this workaround in next breaking change
|
78
|
+
if KEYS[11] ~= "" then
|
79
|
+
rcall("HSET", KEYS[11], "nrjid", nextDelayedJobId)
|
73
80
|
end
|
74
81
|
|
75
82
|
return nextDelayedJobId .. "" -- convert to string
|
@@ -17,7 +17,7 @@ local nextMillis = ARGV[1]
|
|
17
17
|
local customKey = ARGV[2]
|
18
18
|
local legacyCustomKey = ARGV[3]
|
19
19
|
|
20
|
-
if rcall("ZSCORE", repeatKey, customKey)
|
20
|
+
if rcall("ZSCORE", repeatKey, customKey) then
|
21
21
|
rcall("ZADD", repeatKey, nextMillis, customKey)
|
22
22
|
return customKey
|
23
23
|
elseif rcall("ZSCORE", repeatKey, legacyCustomKey) ~= false then
|
@@ -284,7 +284,7 @@ local function updateExistingJobsParent(parentKey, parent, parentData,
|
|
284
284
|
parentDependenciesKey, completedKey,
|
285
285
|
jobIdKey, jobId, timestamp)
|
286
286
|
if parentKey ~= nil then
|
287
|
-
if rcall("ZSCORE", completedKey, jobId)
|
287
|
+
if rcall("ZSCORE", completedKey, jobId) then
|
288
288
|
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
289
289
|
updateParentDepsIfNeeded(parentKey, parent['queueKey'],
|
290
290
|
parentDependenciesKey, parent['id'],
|
@@ -34,12 +34,19 @@ const content = `--[[
|
|
34
34
|
local rcall = redis.call
|
35
35
|
local repeatKey = KEYS[1]
|
36
36
|
local delayedKey = KEYS[2]
|
37
|
+
local waitKey = KEYS[3]
|
38
|
+
local pausedKey = KEYS[4]
|
39
|
+
local metaKey = KEYS[5]
|
37
40
|
local prioritizedKey = KEYS[6]
|
38
41
|
local nextMillis = ARGV[1]
|
39
42
|
local jobSchedulerId = ARGV[3]
|
40
43
|
local templateOpts = cmsgpack.unpack(ARGV[5])
|
41
44
|
local prefixKey = ARGV[8]
|
42
45
|
-- Includes
|
46
|
+
--[[
|
47
|
+
Add delay marker if needed.
|
48
|
+
]]
|
49
|
+
-- Includes
|
43
50
|
--[[
|
44
51
|
Adds a delayed job to the queue by doing the following:
|
45
52
|
- Creates a new job key with the job data.
|
@@ -130,42 +137,80 @@ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, pr
|
|
130
137
|
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
131
138
|
end
|
132
139
|
--[[
|
133
|
-
Function to
|
140
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
141
|
+
(since an empty list and !EXISTS are not really the same).
|
134
142
|
]]
|
135
|
-
local function
|
136
|
-
|
137
|
-
if not maxEvents then
|
138
|
-
maxEvents = 10000
|
139
|
-
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
140
|
-
end
|
141
|
-
return maxEvents
|
143
|
+
local function isQueuePaused(queueMetaKey)
|
144
|
+
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
142
145
|
end
|
143
146
|
--[[
|
144
|
-
Function to
|
145
|
-
(since an empty list and !EXISTS are not really the same).
|
147
|
+
Function to store a job
|
146
148
|
]]
|
147
|
-
local function
|
148
|
-
|
149
|
-
|
150
|
-
|
149
|
+
local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
|
150
|
+
parentKey, parentData, repeatJobKey)
|
151
|
+
local jsonOpts = cjson.encode(opts)
|
152
|
+
local delay = opts['delay'] or 0
|
153
|
+
local priority = opts['priority'] or 0
|
154
|
+
local debounceId = opts['de'] and opts['de']['id']
|
155
|
+
local optionalValues = {}
|
156
|
+
if parentKey ~= nil then
|
157
|
+
table.insert(optionalValues, "parentKey")
|
158
|
+
table.insert(optionalValues, parentKey)
|
159
|
+
table.insert(optionalValues, "parent")
|
160
|
+
table.insert(optionalValues, parentData)
|
161
|
+
end
|
162
|
+
if repeatJobKey ~= nil then
|
163
|
+
table.insert(optionalValues, "rjk")
|
164
|
+
table.insert(optionalValues, repeatJobKey)
|
165
|
+
end
|
166
|
+
if debounceId then
|
167
|
+
table.insert(optionalValues, "deid")
|
168
|
+
table.insert(optionalValues, debounceId)
|
169
|
+
end
|
170
|
+
rcall("HMSET", jobIdKey, "name", name, "data", data, "opts", jsonOpts,
|
171
|
+
"timestamp", timestamp, "delay", delay, "priority", priority,
|
172
|
+
unpack(optionalValues))
|
173
|
+
rcall("XADD", eventsKey, "*", "event", "added", "jobId", jobId, "name", name)
|
174
|
+
return delay, priority
|
175
|
+
end
|
176
|
+
local function addJobFromScheduler(jobKey, jobId, rawOpts, waitKey, pausedKey, metaKey, prioritizedKey,
|
177
|
+
priorityCounter, delayedKey, markerKey, eventsKey, name, maxEvents, timestamp, data, jobSchedulerId)
|
178
|
+
local opts = cmsgpack.unpack(rawOpts)
|
179
|
+
local delay, priority = storeJob(eventsKey, jobKey, jobId, name, data,
|
180
|
+
opts, timestamp, nil, nil, jobSchedulerId)
|
181
|
+
if delay ~= 0 then
|
182
|
+
addDelayedJob(jobId, delayedKey, eventsKey, timestamp, maxEvents, markerKey, delay)
|
151
183
|
else
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
184
|
+
local isPaused = isQueuePaused(metaKey)
|
185
|
+
-- Standard or priority add
|
186
|
+
if priority == 0 then
|
187
|
+
if isPaused then
|
188
|
+
-- LIFO or FIFO
|
189
|
+
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
190
|
+
rcall(pushCmd, pausedKey, jobId)
|
156
191
|
else
|
157
|
-
|
192
|
+
-- LIFO or FIFO
|
193
|
+
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
194
|
+
rcall(pushCmd, waitKey, jobId)
|
158
195
|
end
|
196
|
+
else
|
197
|
+
-- Priority add
|
198
|
+
addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounter, isPaused)
|
159
199
|
end
|
200
|
+
-- Emit waiting event
|
201
|
+
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting", "jobId", jobId)
|
160
202
|
end
|
161
|
-
return waitKey, false
|
162
203
|
end
|
163
204
|
--[[
|
164
|
-
Function to
|
165
|
-
(since an empty list and !EXISTS are not really the same).
|
205
|
+
Function to get max events value or set by default 10000.
|
166
206
|
]]
|
167
|
-
local function
|
168
|
-
|
207
|
+
local function getOrSetMaxEvents(metaKey)
|
208
|
+
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
209
|
+
if not maxEvents then
|
210
|
+
maxEvents = 10000
|
211
|
+
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
212
|
+
end
|
213
|
+
return maxEvents
|
169
214
|
end
|
170
215
|
--[[
|
171
216
|
Function to remove job.
|
@@ -212,6 +257,26 @@ end
|
|
212
257
|
local getJobKeyPrefix = function (jobKey, jobId)
|
213
258
|
return string.sub(jobKey, 0, #jobKey - #jobId)
|
214
259
|
end
|
260
|
+
--[[
|
261
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
262
|
+
(since an empty list and !EXISTS are not really the same).
|
263
|
+
]]
|
264
|
+
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
265
|
+
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
|
266
|
+
if queueAttributes[1] then
|
267
|
+
return pausedKey, true
|
268
|
+
else
|
269
|
+
if queueAttributes[2] then
|
270
|
+
local activeCount = rcall("LLEN", activeKey)
|
271
|
+
if activeCount >= tonumber(queueAttributes[2]) then
|
272
|
+
return waitKey, true
|
273
|
+
else
|
274
|
+
return waitKey, false
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
return waitKey, false
|
279
|
+
end
|
215
280
|
local function moveParentToWait(parentPrefix, parentId, emitEvent)
|
216
281
|
local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
|
217
282
|
parentPrefix .. "wait", parentPrefix .. "paused")
|
@@ -292,36 +357,6 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
|
292
357
|
end
|
293
358
|
removeJobKeys(jobKey)
|
294
359
|
end
|
295
|
-
--[[
|
296
|
-
Function to store a job
|
297
|
-
]]
|
298
|
-
local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
|
299
|
-
parentKey, parentData, repeatJobKey)
|
300
|
-
local jsonOpts = cjson.encode(opts)
|
301
|
-
local delay = opts['delay'] or 0
|
302
|
-
local priority = opts['priority'] or 0
|
303
|
-
local debounceId = opts['de'] and opts['de']['id']
|
304
|
-
local optionalValues = {}
|
305
|
-
if parentKey ~= nil then
|
306
|
-
table.insert(optionalValues, "parentKey")
|
307
|
-
table.insert(optionalValues, parentKey)
|
308
|
-
table.insert(optionalValues, "parent")
|
309
|
-
table.insert(optionalValues, parentData)
|
310
|
-
end
|
311
|
-
if repeatJobKey ~= nil then
|
312
|
-
table.insert(optionalValues, "rjk")
|
313
|
-
table.insert(optionalValues, repeatJobKey)
|
314
|
-
end
|
315
|
-
if debounceId then
|
316
|
-
table.insert(optionalValues, "deid")
|
317
|
-
table.insert(optionalValues, debounceId)
|
318
|
-
end
|
319
|
-
rcall("HMSET", jobIdKey, "name", name, "data", data, "opts", jsonOpts,
|
320
|
-
"timestamp", timestamp, "delay", delay, "priority", priority,
|
321
|
-
unpack(optionalValues))
|
322
|
-
rcall("XADD", eventsKey, "*", "event", "added", "jobId", jobId, "name", name)
|
323
|
-
return delay, priority
|
324
|
-
end
|
325
360
|
--[[
|
326
361
|
Function to store a job scheduler
|
327
362
|
]]
|
@@ -376,12 +411,12 @@ if prevMillis ~= false then
|
|
376
411
|
removeJob(currentJobId, true, prefixKey, true --[[remove debounce key]] )
|
377
412
|
rcall("ZREM", prioritizedKey, currentJobId)
|
378
413
|
else
|
379
|
-
if isQueuePaused(
|
380
|
-
if rcall("LREM",
|
414
|
+
if isQueuePaused(metaKey) then
|
415
|
+
if rcall("LREM", pausedKey, 1, currentJobId) > 0 then
|
381
416
|
removeJob(currentJobId, true, prefixKey, true --[[remove debounce key]] )
|
382
417
|
end
|
383
418
|
else
|
384
|
-
if rcall("LREM",
|
419
|
+
if rcall("LREM", waitKey, 1, currentJobId) > 0 then
|
385
420
|
removeJob(currentJobId, true, prefixKey, true --[[remove debounce key]] )
|
386
421
|
end
|
387
422
|
end
|
@@ -392,35 +427,10 @@ local schedulerOpts = cmsgpack.unpack(ARGV[2])
|
|
392
427
|
storeJobScheduler(jobSchedulerId, schedulerKey, repeatKey, nextMillis, schedulerOpts, ARGV[4], templateOpts)
|
393
428
|
if rcall("EXISTS", nextDelayedJobKey) ~= 1 then
|
394
429
|
local eventsKey = KEYS[9]
|
395
|
-
local metaKey = KEYS[5]
|
396
430
|
local maxEvents = getOrSetMaxEvents(metaKey)
|
397
431
|
rcall("INCR", KEYS[8])
|
398
|
-
|
399
|
-
|
400
|
-
delayedOpts, ARGV[7], nil, nil, jobSchedulerId)
|
401
|
-
if delay ~= 0 then
|
402
|
-
addDelayedJob(nextDelayedJobId, delayedKey, eventsKey,
|
403
|
-
ARGV[7], maxEvents, KEYS[7], delay)
|
404
|
-
else
|
405
|
-
local isPaused = isQueuePaused(KEYS[5])
|
406
|
-
-- Standard or priority add
|
407
|
-
if priority == 0 then
|
408
|
-
if isPaused then
|
409
|
-
-- LIFO or FIFO
|
410
|
-
local pushCmd = delayedOpts['lifo'] and 'RPUSH' or 'LPUSH'
|
411
|
-
rcall(pushCmd, KEYS[4], nextDelayedJobId)
|
412
|
-
else
|
413
|
-
-- LIFO or FIFO
|
414
|
-
local pushCmd = delayedOpts['lifo'] and 'RPUSH' or 'LPUSH'
|
415
|
-
rcall(pushCmd, KEYS[3], nextDelayedJobId)
|
416
|
-
end
|
417
|
-
else
|
418
|
-
-- Priority add
|
419
|
-
addJobWithPriority(KEYS[7], KEYS[6], priority, nextDelayedJobId, KEYS[10], isPaused)
|
420
|
-
end
|
421
|
-
-- Emit waiting event
|
422
|
-
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting", "jobId", nextDelayedJobId)
|
423
|
-
end
|
432
|
+
addJobFromScheduler(nextDelayedJobKey, nextDelayedJobId, ARGV[6], waitKey, pausedKey, metaKey, prioritizedKey,
|
433
|
+
KEYS[10], delayedKey, KEYS[7], eventsKey, schedulerOpts['name'], maxEvents, ARGV[7], ARGV[4], jobSchedulerId)
|
424
434
|
if ARGV[9] ~= "" then
|
425
435
|
rcall("HSET", ARGV[9], "nrjid", nextDelayedJobId)
|
426
436
|
end
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"addJobScheduler-10.js","sourceRoot":"","sources":["../../../src/scripts/addJobScheduler-10.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"addJobScheduler-10.js","sourceRoot":"","sources":["../../../src/scripts/addJobScheduler-10.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmbf,CAAC;AACW,QAAA,eAAe,GAAG;IAC7B,IAAI,EAAE,iBAAiB;IACvB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
|
@@ -240,7 +240,7 @@ local function updateExistingJobsParent(parentKey, parent, parentData,
|
|
240
240
|
parentDependenciesKey, completedKey,
|
241
241
|
jobIdKey, jobId, timestamp)
|
242
242
|
if parentKey ~= nil then
|
243
|
-
if rcall("ZSCORE", completedKey, jobId)
|
243
|
+
if rcall("ZSCORE", completedKey, jobId) then
|
244
244
|
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
245
245
|
updateParentDepsIfNeeded(parentKey, parent['queueKey'],
|
246
246
|
parentDependenciesKey, parent['id'],
|
@@ -277,7 +277,7 @@ local function updateExistingJobsParent(parentKey, parent, parentData,
|
|
277
277
|
parentDependenciesKey, completedKey,
|
278
278
|
jobIdKey, jobId, timestamp)
|
279
279
|
if parentKey ~= nil then
|
280
|
-
if rcall("ZSCORE", completedKey, jobId)
|
280
|
+
if rcall("ZSCORE", completedKey, jobId) then
|
281
281
|
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
282
282
|
updateParentDepsIfNeeded(parentKey, parent['queueKey'],
|
283
283
|
parentDependenciesKey, parent['id'],
|
@@ -207,10 +207,10 @@ end
|
|
207
207
|
-- If we are overriding a repeatable job we must delete the delayed job for
|
208
208
|
-- the next iteration.
|
209
209
|
local prevMillis = rcall("ZSCORE", repeatKey, customKey)
|
210
|
-
if prevMillis
|
210
|
+
if prevMillis then
|
211
211
|
local delayedJobId = "repeat:" .. customKey .. ":" .. prevMillis
|
212
212
|
local nextDelayedJobId = repeatKey .. ":" .. customKey .. ":" .. nextMillis
|
213
|
-
if rcall("ZSCORE", delayedKey, delayedJobId)
|
213
|
+
if rcall("ZSCORE", delayedKey, delayedJobId)
|
214
214
|
and rcall("EXISTS", nextDelayedJobId) ~= 1 then
|
215
215
|
removeJob(delayedJobId, true, prefixKey, true --[[remove debounce key]])
|
216
216
|
rcall("ZREM", delayedKey, delayedJobId)
|
@@ -250,7 +250,7 @@ local function updateExistingJobsParent(parentKey, parent, parentData,
|
|
250
250
|
parentDependenciesKey, completedKey,
|
251
251
|
jobIdKey, jobId, timestamp)
|
252
252
|
if parentKey ~= nil then
|
253
|
-
if rcall("ZSCORE", completedKey, jobId)
|
253
|
+
if rcall("ZSCORE", completedKey, jobId) then
|
254
254
|
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
255
255
|
updateParentDepsIfNeeded(parentKey, parent['queueKey'],
|
256
256
|
parentDependenciesKey, parent['id'],
|
@@ -56,7 +56,7 @@ local function isJobSchedulerJob(jobId, jobKey, jobSchedulersKey)
|
|
56
56
|
local repeatJobKey = rcall("HGET", jobKey, "rjk")
|
57
57
|
if repeatJobKey then
|
58
58
|
local prevMillis = rcall("ZSCORE", jobSchedulersKey, repeatJobKey)
|
59
|
-
if prevMillis
|
59
|
+
if prevMillis then
|
60
60
|
local currentDelayedJobId = "repeat:" .. repeatJobKey .. ":" .. prevMillis
|
61
61
|
return jobId == currentDelayedJobId
|
62
62
|
end
|
@@ -24,16 +24,16 @@ const content = `--[[
|
|
24
24
|
'unknown'
|
25
25
|
]]
|
26
26
|
local rcall = redis.call
|
27
|
-
if rcall("ZSCORE", KEYS[1], ARGV[1])
|
27
|
+
if rcall("ZSCORE", KEYS[1], ARGV[1]) then
|
28
28
|
return "completed"
|
29
29
|
end
|
30
|
-
if rcall("ZSCORE", KEYS[2], ARGV[1])
|
30
|
+
if rcall("ZSCORE", KEYS[2], ARGV[1]) then
|
31
31
|
return "failed"
|
32
32
|
end
|
33
|
-
if rcall("ZSCORE", KEYS[3], ARGV[1])
|
33
|
+
if rcall("ZSCORE", KEYS[3], ARGV[1]) then
|
34
34
|
return "delayed"
|
35
35
|
end
|
36
|
-
if rcall("ZSCORE", KEYS[8], ARGV[1])
|
36
|
+
if rcall("ZSCORE", KEYS[8], ARGV[1]) then
|
37
37
|
return "prioritized"
|
38
38
|
end
|
39
39
|
-- Includes
|
@@ -60,7 +60,7 @@ local paused_items = rcall("LRANGE", KEYS[6] , 0, -1)
|
|
60
60
|
if checkItemInList(paused_items, ARGV[1]) ~= nil then
|
61
61
|
return "waiting"
|
62
62
|
end
|
63
|
-
if rcall("ZSCORE", KEYS[7], ARGV[1])
|
63
|
+
if rcall("ZSCORE", KEYS[7], ARGV[1]) then
|
64
64
|
return "waiting-children"
|
65
65
|
end
|
66
66
|
return "unknown"
|
@@ -23,28 +23,28 @@ const content = `--[[
|
|
23
23
|
'unknown'
|
24
24
|
]]
|
25
25
|
local rcall = redis.call
|
26
|
-
if rcall("ZSCORE", KEYS[1], ARGV[1])
|
26
|
+
if rcall("ZSCORE", KEYS[1], ARGV[1]) then
|
27
27
|
return "completed"
|
28
28
|
end
|
29
|
-
if rcall("ZSCORE", KEYS[2], ARGV[1])
|
29
|
+
if rcall("ZSCORE", KEYS[2], ARGV[1]) then
|
30
30
|
return "failed"
|
31
31
|
end
|
32
|
-
if rcall("ZSCORE", KEYS[3], ARGV[1])
|
32
|
+
if rcall("ZSCORE", KEYS[3], ARGV[1]) then
|
33
33
|
return "delayed"
|
34
34
|
end
|
35
|
-
if rcall("ZSCORE", KEYS[8], ARGV[1])
|
35
|
+
if rcall("ZSCORE", KEYS[8], ARGV[1]) then
|
36
36
|
return "prioritized"
|
37
37
|
end
|
38
|
-
if rcall("LPOS", KEYS[4] , ARGV[1])
|
38
|
+
if rcall("LPOS", KEYS[4] , ARGV[1]) then
|
39
39
|
return "active"
|
40
40
|
end
|
41
|
-
if rcall("LPOS", KEYS[5] , ARGV[1])
|
41
|
+
if rcall("LPOS", KEYS[5] , ARGV[1]) then
|
42
42
|
return "waiting"
|
43
43
|
end
|
44
|
-
if rcall("LPOS", KEYS[6] , ARGV[1])
|
44
|
+
if rcall("LPOS", KEYS[6] , ARGV[1]) then
|
45
45
|
return "waiting"
|
46
46
|
end
|
47
|
-
if rcall("ZSCORE", KEYS[7] , ARGV[1])
|
47
|
+
if rcall("ZSCORE", KEYS[7] , ARGV[1]) then
|
48
48
|
return "waiting-children"
|
49
49
|
end
|
50
50
|
return "unknown"
|
@@ -44,7 +44,7 @@ tslib_1.__exportStar(require("./reprocessJob-8"), exports);
|
|
44
44
|
tslib_1.__exportStar(require("./retryJob-11"), exports);
|
45
45
|
tslib_1.__exportStar(require("./saveStacktrace-1"), exports);
|
46
46
|
tslib_1.__exportStar(require("./updateData-1"), exports);
|
47
|
-
tslib_1.__exportStar(require("./updateJobScheduler-
|
47
|
+
tslib_1.__exportStar(require("./updateJobScheduler-11"), exports);
|
48
48
|
tslib_1.__exportStar(require("./updateProgress-3"), exports);
|
49
49
|
tslib_1.__exportStar(require("./updateRepeatableJobMillis-1"), exports);
|
50
50
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC;AAClC,+DAAqC;AACrC,qDAA2B;AAC3B,2DAAiC;AACjC,gEAAsC;AACtC,+DAAqC;AACrC,6DAAmC;AACnC,0DAAgC;AAChC,6DAAmC;AACnC,6DAAmC;AACnC,oDAA0B;AAC1B,yDAA+B;AAC/B,0DAAgC;AAChC,wDAA8B;AAC9B,mEAAyC;AACzC,8DAAoC;AACpC,wDAA8B;AAC9B,8DAAoC;AACpC,uDAA6B;AAC7B,yDAA+B;AAC/B,yDAA+B;AAC/B,0DAAgC;AAChC,sDAA4B;AAC5B,sEAA4C;AAC5C,6DAAmC;AACnC,oEAA0C;AAC1C,4DAAkC;AAClC,4DAAkC;AAClC,8DAAoC;AACpC,oEAA0C;AAC1C,yDAA+B;AAC/B,uDAA6B;AAC7B,oDAA0B;AAC1B,sDAA4B;AAC5B,0DAAgC;AAChC,oEAA0C;AAC1C,wDAA8B;AAC9B,iEAAuC;AACvC,+DAAqC;AACrC,2DAAiC;AACjC,wDAA8B;AAC9B,6DAAmC;AACnC,yDAA+B;AAC/B,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC;AAClC,+DAAqC;AACrC,qDAA2B;AAC3B,2DAAiC;AACjC,gEAAsC;AACtC,+DAAqC;AACrC,6DAAmC;AACnC,0DAAgC;AAChC,6DAAmC;AACnC,6DAAmC;AACnC,oDAA0B;AAC1B,yDAA+B;AAC/B,0DAAgC;AAChC,wDAA8B;AAC9B,mEAAyC;AACzC,8DAAoC;AACpC,wDAA8B;AAC9B,8DAAoC;AACpC,uDAA6B;AAC7B,yDAA+B;AAC/B,yDAA+B;AAC/B,0DAAgC;AAChC,sDAA4B;AAC5B,sEAA4C;AAC5C,6DAAmC;AACnC,oEAA0C;AAC1C,4DAAkC;AAClC,4DAAkC;AAClC,8DAAoC;AACpC,oEAA0C;AAC1C,yDAA+B;AAC/B,uDAA6B;AAC7B,oDAA0B;AAC1B,sDAA4B;AAC5B,0DAAgC;AAChC,oEAA0C;AAC1C,wDAA8B;AAC9B,iEAAuC;AACvC,+DAAqC;AACrC,2DAAiC;AACjC,wDAA8B;AAC9B,6DAAmC;AACnC,yDAA+B;AAC/B,kEAAwC;AACxC,6DAAmC;AACnC,wEAA8C"}
|
@@ -22,14 +22,14 @@ if rcall("EXISTS", KEYS[3]) ~= 1 then
|
|
22
22
|
end
|
23
23
|
return -1
|
24
24
|
end
|
25
|
-
if rcall("ZSCORE", KEYS[1], ARGV[1])
|
25
|
+
if rcall("ZSCORE", KEYS[1], ARGV[1]) then
|
26
26
|
if ARGV[2] == "1" then
|
27
27
|
local returnValue = rcall("HGET", KEYS[3], "returnvalue")
|
28
28
|
return {1,returnValue}
|
29
29
|
end
|
30
30
|
return 1
|
31
31
|
end
|
32
|
-
if rcall("ZSCORE", KEYS[2], ARGV[1])
|
32
|
+
if rcall("ZSCORE", KEYS[2], ARGV[1]) then
|
33
33
|
if ARGV[2] == "1" then
|
34
34
|
local failedReason = rcall("HGET", KEYS[3], "failedReason")
|
35
35
|
return {2,failedReason}
|
@@ -457,7 +457,7 @@ local function getOrSetMaxEvents(metaKey)
|
|
457
457
|
end
|
458
458
|
local function trimEvents(metaKey, eventStreamKey)
|
459
459
|
local maxEvents = getOrSetMaxEvents(metaKey)
|
460
|
-
if maxEvents
|
460
|
+
if maxEvents then
|
461
461
|
rcall("XTRIM", eventStreamKey, "MAXLEN", "~", maxEvents)
|
462
462
|
else
|
463
463
|
rcall("XTRIM", eventStreamKey, "MAXLEN", "~", 10000)
|
@@ -640,7 +640,7 @@ local function getOrSetMaxEvents(metaKey)
|
|
640
640
|
end
|
641
641
|
local function trimEvents(metaKey, eventStreamKey)
|
642
642
|
local maxEvents = getOrSetMaxEvents(metaKey)
|
643
|
-
if maxEvents
|
643
|
+
if maxEvents then
|
644
644
|
rcall("XTRIM", eventStreamKey, "MAXLEN", "~", maxEvents)
|
645
645
|
else
|
646
646
|
rcall("XTRIM", eventStreamKey, "MAXLEN", "~", 10000)
|
@@ -44,7 +44,7 @@ local function isJobSchedulerJob(jobId, jobKey, jobSchedulersKey)
|
|
44
44
|
local repeatJobKey = rcall("HGET", jobKey, "rjk")
|
45
45
|
if repeatJobKey then
|
46
46
|
local prevMillis = rcall("ZSCORE", jobSchedulersKey, repeatJobKey)
|
47
|
-
if prevMillis
|
47
|
+
if prevMillis then
|
48
48
|
local currentDelayedJobId = "repeat:" .. repeatJobKey .. ":" .. prevMillis
|
49
49
|
return jobId == currentDelayedJobId
|
50
50
|
end
|