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
|
@@ -281,7 +281,7 @@ local function updateExistingJobsParent(parentKey, parent, parentData,
|
|
281
281
|
parentDependenciesKey, completedKey,
|
282
282
|
jobIdKey, jobId, timestamp)
|
283
283
|
if parentKey ~= nil then
|
284
|
-
if rcall("ZSCORE", completedKey, jobId)
|
284
|
+
if rcall("ZSCORE", completedKey, jobId) then
|
285
285
|
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
286
286
|
updateParentDepsIfNeeded(parentKey, parent['queueKey'],
|
287
287
|
parentDependenciesKey, parent['id'],
|
@@ -31,12 +31,19 @@ const content = `--[[
|
|
31
31
|
local rcall = redis.call
|
32
32
|
local repeatKey = KEYS[1]
|
33
33
|
local delayedKey = KEYS[2]
|
34
|
+
local waitKey = KEYS[3]
|
35
|
+
local pausedKey = KEYS[4]
|
36
|
+
local metaKey = KEYS[5]
|
34
37
|
local prioritizedKey = KEYS[6]
|
35
38
|
local nextMillis = ARGV[1]
|
36
39
|
local jobSchedulerId = ARGV[3]
|
37
40
|
local templateOpts = cmsgpack.unpack(ARGV[5])
|
38
41
|
local prefixKey = ARGV[8]
|
39
42
|
-- Includes
|
43
|
+
--[[
|
44
|
+
Add delay marker if needed.
|
45
|
+
]]
|
46
|
+
-- Includes
|
40
47
|
--[[
|
41
48
|
Adds a delayed job to the queue by doing the following:
|
42
49
|
- Creates a new job key with the job data.
|
@@ -127,42 +134,80 @@ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, pr
|
|
127
134
|
addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
|
128
135
|
end
|
129
136
|
--[[
|
130
|
-
Function to
|
137
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
138
|
+
(since an empty list and !EXISTS are not really the same).
|
131
139
|
]]
|
132
|
-
local function
|
133
|
-
|
134
|
-
if not maxEvents then
|
135
|
-
maxEvents = 10000
|
136
|
-
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
137
|
-
end
|
138
|
-
return maxEvents
|
140
|
+
local function isQueuePaused(queueMetaKey)
|
141
|
+
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
139
142
|
end
|
140
143
|
--[[
|
141
|
-
Function to
|
142
|
-
(since an empty list and !EXISTS are not really the same).
|
144
|
+
Function to store a job
|
143
145
|
]]
|
144
|
-
local function
|
145
|
-
|
146
|
-
|
147
|
-
|
146
|
+
local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
|
147
|
+
parentKey, parentData, repeatJobKey)
|
148
|
+
local jsonOpts = cjson.encode(opts)
|
149
|
+
local delay = opts['delay'] or 0
|
150
|
+
local priority = opts['priority'] or 0
|
151
|
+
local debounceId = opts['de'] and opts['de']['id']
|
152
|
+
local optionalValues = {}
|
153
|
+
if parentKey ~= nil then
|
154
|
+
table.insert(optionalValues, "parentKey")
|
155
|
+
table.insert(optionalValues, parentKey)
|
156
|
+
table.insert(optionalValues, "parent")
|
157
|
+
table.insert(optionalValues, parentData)
|
158
|
+
end
|
159
|
+
if repeatJobKey ~= nil then
|
160
|
+
table.insert(optionalValues, "rjk")
|
161
|
+
table.insert(optionalValues, repeatJobKey)
|
162
|
+
end
|
163
|
+
if debounceId then
|
164
|
+
table.insert(optionalValues, "deid")
|
165
|
+
table.insert(optionalValues, debounceId)
|
166
|
+
end
|
167
|
+
rcall("HMSET", jobIdKey, "name", name, "data", data, "opts", jsonOpts,
|
168
|
+
"timestamp", timestamp, "delay", delay, "priority", priority,
|
169
|
+
unpack(optionalValues))
|
170
|
+
rcall("XADD", eventsKey, "*", "event", "added", "jobId", jobId, "name", name)
|
171
|
+
return delay, priority
|
172
|
+
end
|
173
|
+
local function addJobFromScheduler(jobKey, jobId, rawOpts, waitKey, pausedKey, metaKey, prioritizedKey,
|
174
|
+
priorityCounter, delayedKey, markerKey, eventsKey, name, maxEvents, timestamp, data, jobSchedulerId)
|
175
|
+
local opts = cmsgpack.unpack(rawOpts)
|
176
|
+
local delay, priority = storeJob(eventsKey, jobKey, jobId, name, data,
|
177
|
+
opts, timestamp, nil, nil, jobSchedulerId)
|
178
|
+
if delay ~= 0 then
|
179
|
+
addDelayedJob(jobId, delayedKey, eventsKey, timestamp, maxEvents, markerKey, delay)
|
148
180
|
else
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
181
|
+
local isPaused = isQueuePaused(metaKey)
|
182
|
+
-- Standard or priority add
|
183
|
+
if priority == 0 then
|
184
|
+
if isPaused then
|
185
|
+
-- LIFO or FIFO
|
186
|
+
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
187
|
+
rcall(pushCmd, pausedKey, jobId)
|
153
188
|
else
|
154
|
-
|
189
|
+
-- LIFO or FIFO
|
190
|
+
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
191
|
+
rcall(pushCmd, waitKey, jobId)
|
155
192
|
end
|
193
|
+
else
|
194
|
+
-- Priority add
|
195
|
+
addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounter, isPaused)
|
156
196
|
end
|
197
|
+
-- Emit waiting event
|
198
|
+
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting", "jobId", jobId)
|
157
199
|
end
|
158
|
-
return waitKey, false
|
159
200
|
end
|
160
201
|
--[[
|
161
|
-
Function to
|
162
|
-
(since an empty list and !EXISTS are not really the same).
|
202
|
+
Function to get max events value or set by default 10000.
|
163
203
|
]]
|
164
|
-
local function
|
165
|
-
|
204
|
+
local function getOrSetMaxEvents(metaKey)
|
205
|
+
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
206
|
+
if not maxEvents then
|
207
|
+
maxEvents = 10000
|
208
|
+
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
209
|
+
end
|
210
|
+
return maxEvents
|
166
211
|
end
|
167
212
|
--[[
|
168
213
|
Function to remove job.
|
@@ -209,6 +254,26 @@ end
|
|
209
254
|
local getJobKeyPrefix = function (jobKey, jobId)
|
210
255
|
return string.sub(jobKey, 0, #jobKey - #jobId)
|
211
256
|
end
|
257
|
+
--[[
|
258
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
259
|
+
(since an empty list and !EXISTS are not really the same).
|
260
|
+
]]
|
261
|
+
local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
262
|
+
local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
|
263
|
+
if queueAttributes[1] then
|
264
|
+
return pausedKey, true
|
265
|
+
else
|
266
|
+
if queueAttributes[2] then
|
267
|
+
local activeCount = rcall("LLEN", activeKey)
|
268
|
+
if activeCount >= tonumber(queueAttributes[2]) then
|
269
|
+
return waitKey, true
|
270
|
+
else
|
271
|
+
return waitKey, false
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
return waitKey, false
|
276
|
+
end
|
212
277
|
local function moveParentToWait(parentPrefix, parentId, emitEvent)
|
213
278
|
local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
|
214
279
|
parentPrefix .. "wait", parentPrefix .. "paused")
|
@@ -289,36 +354,6 @@ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
|
|
289
354
|
end
|
290
355
|
removeJobKeys(jobKey)
|
291
356
|
end
|
292
|
-
--[[
|
293
|
-
Function to store a job
|
294
|
-
]]
|
295
|
-
local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
|
296
|
-
parentKey, parentData, repeatJobKey)
|
297
|
-
local jsonOpts = cjson.encode(opts)
|
298
|
-
local delay = opts['delay'] or 0
|
299
|
-
local priority = opts['priority'] or 0
|
300
|
-
local debounceId = opts['de'] and opts['de']['id']
|
301
|
-
local optionalValues = {}
|
302
|
-
if parentKey ~= nil then
|
303
|
-
table.insert(optionalValues, "parentKey")
|
304
|
-
table.insert(optionalValues, parentKey)
|
305
|
-
table.insert(optionalValues, "parent")
|
306
|
-
table.insert(optionalValues, parentData)
|
307
|
-
end
|
308
|
-
if repeatJobKey ~= nil then
|
309
|
-
table.insert(optionalValues, "rjk")
|
310
|
-
table.insert(optionalValues, repeatJobKey)
|
311
|
-
end
|
312
|
-
if debounceId then
|
313
|
-
table.insert(optionalValues, "deid")
|
314
|
-
table.insert(optionalValues, debounceId)
|
315
|
-
end
|
316
|
-
rcall("HMSET", jobIdKey, "name", name, "data", data, "opts", jsonOpts,
|
317
|
-
"timestamp", timestamp, "delay", delay, "priority", priority,
|
318
|
-
unpack(optionalValues))
|
319
|
-
rcall("XADD", eventsKey, "*", "event", "added", "jobId", jobId, "name", name)
|
320
|
-
return delay, priority
|
321
|
-
end
|
322
357
|
--[[
|
323
358
|
Function to store a job scheduler
|
324
359
|
]]
|
@@ -373,12 +408,12 @@ if prevMillis ~= false then
|
|
373
408
|
removeJob(currentJobId, true, prefixKey, true --[[remove debounce key]] )
|
374
409
|
rcall("ZREM", prioritizedKey, currentJobId)
|
375
410
|
else
|
376
|
-
if isQueuePaused(
|
377
|
-
if rcall("LREM",
|
411
|
+
if isQueuePaused(metaKey) then
|
412
|
+
if rcall("LREM", pausedKey, 1, currentJobId) > 0 then
|
378
413
|
removeJob(currentJobId, true, prefixKey, true --[[remove debounce key]] )
|
379
414
|
end
|
380
415
|
else
|
381
|
-
if rcall("LREM",
|
416
|
+
if rcall("LREM", waitKey, 1, currentJobId) > 0 then
|
382
417
|
removeJob(currentJobId, true, prefixKey, true --[[remove debounce key]] )
|
383
418
|
end
|
384
419
|
end
|
@@ -389,35 +424,10 @@ local schedulerOpts = cmsgpack.unpack(ARGV[2])
|
|
389
424
|
storeJobScheduler(jobSchedulerId, schedulerKey, repeatKey, nextMillis, schedulerOpts, ARGV[4], templateOpts)
|
390
425
|
if rcall("EXISTS", nextDelayedJobKey) ~= 1 then
|
391
426
|
local eventsKey = KEYS[9]
|
392
|
-
local metaKey = KEYS[5]
|
393
427
|
local maxEvents = getOrSetMaxEvents(metaKey)
|
394
428
|
rcall("INCR", KEYS[8])
|
395
|
-
|
396
|
-
|
397
|
-
delayedOpts, ARGV[7], nil, nil, jobSchedulerId)
|
398
|
-
if delay ~= 0 then
|
399
|
-
addDelayedJob(nextDelayedJobId, delayedKey, eventsKey,
|
400
|
-
ARGV[7], maxEvents, KEYS[7], delay)
|
401
|
-
else
|
402
|
-
local isPaused = isQueuePaused(KEYS[5])
|
403
|
-
-- Standard or priority add
|
404
|
-
if priority == 0 then
|
405
|
-
if isPaused then
|
406
|
-
-- LIFO or FIFO
|
407
|
-
local pushCmd = delayedOpts['lifo'] and 'RPUSH' or 'LPUSH'
|
408
|
-
rcall(pushCmd, KEYS[4], nextDelayedJobId)
|
409
|
-
else
|
410
|
-
-- LIFO or FIFO
|
411
|
-
local pushCmd = delayedOpts['lifo'] and 'RPUSH' or 'LPUSH'
|
412
|
-
rcall(pushCmd, KEYS[3], nextDelayedJobId)
|
413
|
-
end
|
414
|
-
else
|
415
|
-
-- Priority add
|
416
|
-
addJobWithPriority(KEYS[7], KEYS[6], priority, nextDelayedJobId, KEYS[10], isPaused)
|
417
|
-
end
|
418
|
-
-- Emit waiting event
|
419
|
-
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting", "jobId", nextDelayedJobId)
|
420
|
-
end
|
429
|
+
addJobFromScheduler(nextDelayedJobKey, nextDelayedJobId, ARGV[6], waitKey, pausedKey, metaKey, prioritizedKey,
|
430
|
+
KEYS[10], delayedKey, KEYS[7], eventsKey, schedulerOpts['name'], maxEvents, ARGV[7], ARGV[4], jobSchedulerId)
|
421
431
|
if ARGV[9] ~= "" then
|
422
432
|
rcall("HSET", ARGV[9], "nrjid", nextDelayedJobId)
|
423
433
|
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;AACF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,iBAAiB;IACvB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
|
@@ -237,7 +237,7 @@ local function updateExistingJobsParent(parentKey, parent, parentData,
|
|
237
237
|
parentDependenciesKey, completedKey,
|
238
238
|
jobIdKey, jobId, timestamp)
|
239
239
|
if parentKey ~= nil then
|
240
|
-
if rcall("ZSCORE", completedKey, jobId)
|
240
|
+
if rcall("ZSCORE", completedKey, jobId) then
|
241
241
|
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
242
242
|
updateParentDepsIfNeeded(parentKey, parent['queueKey'],
|
243
243
|
parentDependenciesKey, parent['id'],
|
@@ -274,7 +274,7 @@ local function updateExistingJobsParent(parentKey, parent, parentData,
|
|
274
274
|
parentDependenciesKey, completedKey,
|
275
275
|
jobIdKey, jobId, timestamp)
|
276
276
|
if parentKey ~= nil then
|
277
|
-
if rcall("ZSCORE", completedKey, jobId)
|
277
|
+
if rcall("ZSCORE", completedKey, jobId) then
|
278
278
|
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
279
279
|
updateParentDepsIfNeeded(parentKey, parent['queueKey'],
|
280
280
|
parentDependenciesKey, parent['id'],
|
@@ -204,10 +204,10 @@ end
|
|
204
204
|
-- If we are overriding a repeatable job we must delete the delayed job for
|
205
205
|
-- the next iteration.
|
206
206
|
local prevMillis = rcall("ZSCORE", repeatKey, customKey)
|
207
|
-
if prevMillis
|
207
|
+
if prevMillis then
|
208
208
|
local delayedJobId = "repeat:" .. customKey .. ":" .. prevMillis
|
209
209
|
local nextDelayedJobId = repeatKey .. ":" .. customKey .. ":" .. nextMillis
|
210
|
-
if rcall("ZSCORE", delayedKey, delayedJobId)
|
210
|
+
if rcall("ZSCORE", delayedKey, delayedJobId)
|
211
211
|
and rcall("EXISTS", nextDelayedJobId) ~= 1 then
|
212
212
|
removeJob(delayedJobId, true, prefixKey, true --[[remove debounce key]])
|
213
213
|
rcall("ZREM", delayedKey, delayedJobId)
|
@@ -247,7 +247,7 @@ local function updateExistingJobsParent(parentKey, parent, parentData,
|
|
247
247
|
parentDependenciesKey, completedKey,
|
248
248
|
jobIdKey, jobId, timestamp)
|
249
249
|
if parentKey ~= nil then
|
250
|
-
if rcall("ZSCORE", completedKey, jobId)
|
250
|
+
if rcall("ZSCORE", completedKey, jobId) then
|
251
251
|
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
252
252
|
updateParentDepsIfNeeded(parentKey, parent['queueKey'],
|
253
253
|
parentDependenciesKey, parent['id'],
|
@@ -53,7 +53,7 @@ local function isJobSchedulerJob(jobId, jobKey, jobSchedulersKey)
|
|
53
53
|
local repeatJobKey = rcall("HGET", jobKey, "rjk")
|
54
54
|
if repeatJobKey then
|
55
55
|
local prevMillis = rcall("ZSCORE", jobSchedulersKey, repeatJobKey)
|
56
|
-
if prevMillis
|
56
|
+
if prevMillis then
|
57
57
|
local currentDelayedJobId = "repeat:" .. repeatJobKey .. ":" .. prevMillis
|
58
58
|
return jobId == currentDelayedJobId
|
59
59
|
end
|
@@ -21,16 +21,16 @@ const content = `--[[
|
|
21
21
|
'unknown'
|
22
22
|
]]
|
23
23
|
local rcall = redis.call
|
24
|
-
if rcall("ZSCORE", KEYS[1], ARGV[1])
|
24
|
+
if rcall("ZSCORE", KEYS[1], ARGV[1]) then
|
25
25
|
return "completed"
|
26
26
|
end
|
27
|
-
if rcall("ZSCORE", KEYS[2], ARGV[1])
|
27
|
+
if rcall("ZSCORE", KEYS[2], ARGV[1]) then
|
28
28
|
return "failed"
|
29
29
|
end
|
30
|
-
if rcall("ZSCORE", KEYS[3], ARGV[1])
|
30
|
+
if rcall("ZSCORE", KEYS[3], ARGV[1]) then
|
31
31
|
return "delayed"
|
32
32
|
end
|
33
|
-
if rcall("ZSCORE", KEYS[8], ARGV[1])
|
33
|
+
if rcall("ZSCORE", KEYS[8], ARGV[1]) then
|
34
34
|
return "prioritized"
|
35
35
|
end
|
36
36
|
-- Includes
|
@@ -57,7 +57,7 @@ local paused_items = rcall("LRANGE", KEYS[6] , 0, -1)
|
|
57
57
|
if checkItemInList(paused_items, ARGV[1]) ~= nil then
|
58
58
|
return "waiting"
|
59
59
|
end
|
60
|
-
if rcall("ZSCORE", KEYS[7], ARGV[1])
|
60
|
+
if rcall("ZSCORE", KEYS[7], ARGV[1]) then
|
61
61
|
return "waiting-children"
|
62
62
|
end
|
63
63
|
return "unknown"
|
@@ -20,28 +20,28 @@ const content = `--[[
|
|
20
20
|
'unknown'
|
21
21
|
]]
|
22
22
|
local rcall = redis.call
|
23
|
-
if rcall("ZSCORE", KEYS[1], ARGV[1])
|
23
|
+
if rcall("ZSCORE", KEYS[1], ARGV[1]) then
|
24
24
|
return "completed"
|
25
25
|
end
|
26
|
-
if rcall("ZSCORE", KEYS[2], ARGV[1])
|
26
|
+
if rcall("ZSCORE", KEYS[2], ARGV[1]) then
|
27
27
|
return "failed"
|
28
28
|
end
|
29
|
-
if rcall("ZSCORE", KEYS[3], ARGV[1])
|
29
|
+
if rcall("ZSCORE", KEYS[3], ARGV[1]) then
|
30
30
|
return "delayed"
|
31
31
|
end
|
32
|
-
if rcall("ZSCORE", KEYS[8], ARGV[1])
|
32
|
+
if rcall("ZSCORE", KEYS[8], ARGV[1]) then
|
33
33
|
return "prioritized"
|
34
34
|
end
|
35
|
-
if rcall("LPOS", KEYS[4] , ARGV[1])
|
35
|
+
if rcall("LPOS", KEYS[4] , ARGV[1]) then
|
36
36
|
return "active"
|
37
37
|
end
|
38
|
-
if rcall("LPOS", KEYS[5] , ARGV[1])
|
38
|
+
if rcall("LPOS", KEYS[5] , ARGV[1]) then
|
39
39
|
return "waiting"
|
40
40
|
end
|
41
|
-
if rcall("LPOS", KEYS[6] , ARGV[1])
|
41
|
+
if rcall("LPOS", KEYS[6] , ARGV[1]) then
|
42
42
|
return "waiting"
|
43
43
|
end
|
44
|
-
if rcall("ZSCORE", KEYS[7] , ARGV[1])
|
44
|
+
if rcall("ZSCORE", KEYS[7] , ARGV[1]) then
|
45
45
|
return "waiting-children"
|
46
46
|
end
|
47
47
|
return "unknown"
|
@@ -41,6 +41,6 @@ export * from './reprocessJob-8';
|
|
41
41
|
export * from './retryJob-11';
|
42
42
|
export * from './saveStacktrace-1';
|
43
43
|
export * from './updateData-1';
|
44
|
-
export * from './updateJobScheduler-
|
44
|
+
export * from './updateJobScheduler-11';
|
45
45
|
export * from './updateProgress-3';
|
46
46
|
export * from './updateRepeatableJobMillis-1';
|
@@ -41,7 +41,7 @@ export * from './reprocessJob-8';
|
|
41
41
|
export * from './retryJob-11';
|
42
42
|
export * from './saveStacktrace-1';
|
43
43
|
export * from './updateData-1';
|
44
|
-
export * from './updateJobScheduler-
|
44
|
+
export * from './updateJobScheduler-11';
|
45
45
|
export * from './updateProgress-3';
|
46
46
|
export * from './updateRepeatableJobMillis-1';
|
47
47
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AAC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24
24
|
local returnValue = rcall("HGET", KEYS[3], "returnvalue")
|
25
25
|
return {1,returnValue}
|
26
26
|
end
|
27
27
|
return 1
|
28
28
|
end
|
29
|
-
if rcall("ZSCORE", KEYS[2], ARGV[1])
|
29
|
+
if rcall("ZSCORE", KEYS[2], ARGV[1]) then
|
30
30
|
if ARGV[2] == "1" then
|
31
31
|
local failedReason = rcall("HGET", KEYS[3], "failedReason")
|
32
32
|
return {2,failedReason}
|
@@ -454,7 +454,7 @@ local function getOrSetMaxEvents(metaKey)
|
|
454
454
|
end
|
455
455
|
local function trimEvents(metaKey, eventStreamKey)
|
456
456
|
local maxEvents = getOrSetMaxEvents(metaKey)
|
457
|
-
if maxEvents
|
457
|
+
if maxEvents then
|
458
458
|
rcall("XTRIM", eventStreamKey, "MAXLEN", "~", maxEvents)
|
459
459
|
else
|
460
460
|
rcall("XTRIM", eventStreamKey, "MAXLEN", "~", 10000)
|
@@ -637,7 +637,7 @@ local function getOrSetMaxEvents(metaKey)
|
|
637
637
|
end
|
638
638
|
local function trimEvents(metaKey, eventStreamKey)
|
639
639
|
local maxEvents = getOrSetMaxEvents(metaKey)
|
640
|
-
if maxEvents
|
640
|
+
if maxEvents then
|
641
641
|
rcall("XTRIM", eventStreamKey, "MAXLEN", "~", maxEvents)
|
642
642
|
else
|
643
643
|
rcall("XTRIM", eventStreamKey, "MAXLEN", "~", 10000)
|