bullmq 2.3.1 → 2.3.2
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/redis-connection.js +1 -1
- package/dist/cjs/classes/redis-connection.js.map +1 -1
- package/dist/cjs/commands/addJob-8.lua +174 -0
- package/dist/cjs/commands/changeDelay-4.lua +43 -0
- package/dist/cjs/commands/cleanJobsInSet-2.lua +46 -0
- package/dist/cjs/commands/drain-4.lua +25 -0
- package/dist/cjs/commands/extendLock-2.lua +23 -0
- package/dist/cjs/commands/getState-7.lua +57 -0
- package/dist/cjs/commands/getStateV2-7.lua +51 -0
- package/dist/cjs/commands/includes/addJobWithPriority.lua +16 -0
- package/dist/cjs/commands/includes/batches.lua +18 -0
- package/dist/cjs/commands/includes/checkItemInList.lua +12 -0
- package/dist/cjs/commands/includes/checkStalledJobs.lua +137 -0
- package/dist/cjs/commands/includes/cleanList.lua +50 -0
- package/dist/cjs/commands/includes/cleanSet.lua +50 -0
- package/dist/cjs/commands/includes/collectMetrics.lua +46 -0
- package/dist/cjs/commands/includes/destructureJobKey.lua +12 -0
- package/dist/cjs/commands/includes/getNextDelayedTimestamp.lua +13 -0
- package/dist/cjs/commands/includes/getTargetQueueList.lua +12 -0
- package/dist/cjs/commands/includes/getTimestamp.lua +19 -0
- package/dist/cjs/commands/includes/getZSetItems.lua +7 -0
- package/dist/cjs/commands/includes/isLocked.lua +31 -0
- package/dist/cjs/commands/includes/moveJobFromWaitToActive.lua +84 -0
- package/dist/cjs/commands/includes/moveParentFromWaitingChildrenToFailed.lua +28 -0
- package/dist/cjs/commands/includes/promoteDelayedJobs.lua +49 -0
- package/dist/cjs/commands/includes/removeJob.lua +13 -0
- package/dist/cjs/commands/includes/removeJobFromAnyState.lua +26 -0
- package/dist/cjs/commands/includes/removeJobs.lua +38 -0
- package/dist/cjs/commands/includes/removeJobsByMaxAge.lua +15 -0
- package/dist/cjs/commands/includes/removeJobsByMaxCount.lua +15 -0
- package/dist/cjs/commands/includes/removeParentDependencyKey.lua +81 -0
- package/dist/cjs/commands/includes/trimEvents.lua +12 -0
- package/dist/cjs/commands/includes/updateParentDepsIfNeeded.lua +28 -0
- package/dist/cjs/commands/isFinished-3.lua +48 -0
- package/dist/cjs/commands/isJobInList-1.lua +16 -0
- package/dist/cjs/commands/moveStalledJobsToWait-8.lua +24 -0
- package/dist/cjs/commands/moveToActive-9.lua +67 -0
- package/dist/cjs/commands/moveToDelayed-5.lua +54 -0
- package/dist/cjs/commands/moveToFinished-12.lua +201 -0
- package/dist/cjs/commands/moveToWaitingChildren-4.lua +62 -0
- package/dist/cjs/commands/obliterate-2.lua +94 -0
- package/dist/cjs/commands/pause-4.lua +27 -0
- package/dist/cjs/commands/promote-6.lua +59 -0
- package/dist/cjs/commands/releaseLock-1.lua +19 -0
- package/dist/cjs/commands/removeJob-1.lua +72 -0
- package/dist/cjs/commands/removeRepeatable-2.lua +32 -0
- package/dist/cjs/commands/reprocessJob-4.lua +35 -0
- package/dist/cjs/commands/retryJob-6.lua +51 -0
- package/dist/cjs/commands/retryJobs-6.lua +53 -0
- package/dist/cjs/commands/takeLock-1.lua +17 -0
- package/dist/cjs/commands/updateData-1.lua +16 -0
- package/dist/cjs/commands/updateProgress-2.lua +22 -0
- package/dist/cjs/scripts/moveToFinished-12.js +5 -2
- package/dist/cjs/scripts/moveToFinished-12.js.map +1 -1
- package/dist/esm/classes/redis-connection.js +1 -1
- package/dist/esm/classes/redis-connection.js.map +1 -1
- package/dist/esm/commands/addJob-8.lua +174 -0
- package/dist/esm/commands/changeDelay-4.lua +43 -0
- package/dist/esm/commands/cleanJobsInSet-2.lua +46 -0
- package/dist/esm/commands/drain-4.lua +25 -0
- package/dist/esm/commands/extendLock-2.lua +23 -0
- package/dist/esm/commands/getState-7.lua +57 -0
- package/dist/esm/commands/getStateV2-7.lua +51 -0
- package/dist/esm/commands/includes/addJobWithPriority.lua +16 -0
- package/dist/esm/commands/includes/batches.lua +18 -0
- package/dist/esm/commands/includes/checkItemInList.lua +12 -0
- package/dist/esm/commands/includes/checkStalledJobs.lua +137 -0
- package/dist/esm/commands/includes/cleanList.lua +50 -0
- package/dist/esm/commands/includes/cleanSet.lua +50 -0
- package/dist/esm/commands/includes/collectMetrics.lua +46 -0
- package/dist/esm/commands/includes/destructureJobKey.lua +12 -0
- package/dist/esm/commands/includes/getNextDelayedTimestamp.lua +13 -0
- package/dist/esm/commands/includes/getTargetQueueList.lua +12 -0
- package/dist/esm/commands/includes/getTimestamp.lua +19 -0
- package/dist/esm/commands/includes/getZSetItems.lua +7 -0
- package/dist/esm/commands/includes/isLocked.lua +31 -0
- package/dist/esm/commands/includes/moveJobFromWaitToActive.lua +84 -0
- package/dist/esm/commands/includes/moveParentFromWaitingChildrenToFailed.lua +28 -0
- package/dist/esm/commands/includes/promoteDelayedJobs.lua +49 -0
- package/dist/esm/commands/includes/removeJob.lua +13 -0
- package/dist/esm/commands/includes/removeJobFromAnyState.lua +26 -0
- package/dist/esm/commands/includes/removeJobs.lua +38 -0
- package/dist/esm/commands/includes/removeJobsByMaxAge.lua +15 -0
- package/dist/esm/commands/includes/removeJobsByMaxCount.lua +15 -0
- package/dist/esm/commands/includes/removeParentDependencyKey.lua +81 -0
- package/dist/esm/commands/includes/trimEvents.lua +12 -0
- package/dist/esm/commands/includes/updateParentDepsIfNeeded.lua +28 -0
- package/dist/esm/commands/isFinished-3.lua +48 -0
- package/dist/esm/commands/isJobInList-1.lua +16 -0
- package/dist/esm/commands/moveStalledJobsToWait-8.lua +24 -0
- package/dist/esm/commands/moveToActive-9.lua +67 -0
- package/dist/esm/commands/moveToDelayed-5.lua +54 -0
- package/dist/esm/commands/moveToFinished-12.lua +201 -0
- package/dist/esm/commands/moveToWaitingChildren-4.lua +62 -0
- package/dist/esm/commands/obliterate-2.lua +94 -0
- package/dist/esm/commands/pause-4.lua +27 -0
- package/dist/esm/commands/promote-6.lua +59 -0
- package/dist/esm/commands/releaseLock-1.lua +19 -0
- package/dist/esm/commands/removeJob-1.lua +72 -0
- package/dist/esm/commands/removeRepeatable-2.lua +32 -0
- package/dist/esm/commands/reprocessJob-4.lua +35 -0
- package/dist/esm/commands/retryJob-6.lua +51 -0
- package/dist/esm/commands/retryJobs-6.lua +53 -0
- package/dist/esm/commands/takeLock-1.lua +17 -0
- package/dist/esm/commands/updateData-1.lua +16 -0
- package/dist/esm/commands/updateProgress-2.lua +22 -0
- package/dist/esm/scripts/moveToFinished-12.js +5 -2
- package/dist/esm/scripts/moveToFinished-12.js.map +1 -1
- package/package.json +2 -2
@@ -131,7 +131,7 @@ class RedisConnection extends events_1.EventEmitter {
|
|
131
131
|
throw new Error(`Redis version needs to be greater than ${RedisConnection.minimumVersion} Current: ${this.version}`);
|
132
132
|
}
|
133
133
|
if ((0, utils_2.isRedisVersionLowerThan)(this.version, RedisConnection.recommendedMinimumVersion)) {
|
134
|
-
console.warn(`It is highly
|
134
|
+
console.warn(`It is highly recommended to use a minimum Redis version of ${RedisConnection.recommendedMinimumVersion}
|
135
135
|
Current: ${this.version}`);
|
136
136
|
}
|
137
137
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"redis-connection.js","sourceRoot":"","sources":["../../../src/classes/redis-connection.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AACtC,qCAA6C;AAC7C,6DAA6D;AAC7D,aAAa;AACb,+CAAkE;AAElE,oCAKkB;AAClB,sCAAsC;AAEtC,MAAM,eAAe,GAAG;IACtB,uEAAuE;IACvE,mCAAmC;CACpC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ,MAAM,kBAAkB,GAAG;IACzB,oFAAoF;IACpF,mEAAmE;CACpE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ,MAAM,cAAc,GAAG,gDAAgD,CAAC;AAQxE,MAAa,eAAgB,SAAQ,qBAAY;IAe/C,YACE,IAAwB,EACP,SAAkB,KAAK,EACvB,WAAW,IAAI;QAEhC,KAAK,EAAE,C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AAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACrC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAE;gBACjD,MAAM,eAAe,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;gBACtE,IAAI,eAAe,KAAK,YAAY,EAAE;oBACpC,OAAO,CAAC,KAAK,CACX,iCAAiC,eAAe,6BAA6B,CAC9E,CAAC;iBACH;aACF;YAED,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;gBACvC,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;aACpD;SACF;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;;AA/PH,0CAgQC;AA/PQ,8BAAc,GAAG,OAAO,CAAC;AACzB,yCAAyB,GAAG,OAAO,CAAC"}
|
@@ -0,0 +1,174 @@
|
|
1
|
+
--[[
|
2
|
+
Adds a job to the queue by doing the following:
|
3
|
+
- Increases the job counter if needed.
|
4
|
+
- Creates a new job key with the job data.
|
5
|
+
|
6
|
+
- if delayed:
|
7
|
+
- computes timestamp.
|
8
|
+
- adds to delayed zset.
|
9
|
+
- Emits a global event 'delayed' if the job is delayed.
|
10
|
+
- if not delayed
|
11
|
+
- Adds the jobId to the wait/paused list in one of three ways:
|
12
|
+
- LIFO
|
13
|
+
- FIFO
|
14
|
+
- prioritized.
|
15
|
+
- Adds the job to the "added" list so that workers gets notified.
|
16
|
+
|
17
|
+
Input:
|
18
|
+
KEYS[1] 'wait',
|
19
|
+
KEYS[2] 'paused'
|
20
|
+
KEYS[3] 'meta'
|
21
|
+
KEYS[4] 'id'
|
22
|
+
KEYS[5] 'delayed'
|
23
|
+
KEYS[6] 'priority'
|
24
|
+
KEYS[7] 'completed'
|
25
|
+
KEYS[8] events stream key
|
26
|
+
|
27
|
+
ARGV[1] msgpacked arguments array
|
28
|
+
[1] key prefix,
|
29
|
+
[2] custom id (will not generate one automatically)
|
30
|
+
[3] name
|
31
|
+
[4] timestamp
|
32
|
+
[5] parentKey?
|
33
|
+
[6] waitChildrenKey key.
|
34
|
+
[7] parent dependencies key.
|
35
|
+
[8] parent? {id, queueKey}
|
36
|
+
[9] repeat job key
|
37
|
+
|
38
|
+
ARGV[2] Json stringified job data
|
39
|
+
ARGV[3] msgpacked options
|
40
|
+
|
41
|
+
Output:
|
42
|
+
jobId - OK
|
43
|
+
-5 - Missing parent key
|
44
|
+
]]
|
45
|
+
local jobId
|
46
|
+
local jobIdKey
|
47
|
+
local rcall = redis.call
|
48
|
+
|
49
|
+
local args = cmsgpack.unpack(ARGV[1])
|
50
|
+
|
51
|
+
local data = ARGV[2]
|
52
|
+
local opts = cmsgpack.unpack(ARGV[3])
|
53
|
+
|
54
|
+
local parentKey = args[5]
|
55
|
+
local repeatJobKey = args[9]
|
56
|
+
local parent = args[8]
|
57
|
+
local parentData
|
58
|
+
|
59
|
+
-- Includes
|
60
|
+
--- @include "includes/addJobWithPriority"
|
61
|
+
--- @include "includes/getTargetQueueList"
|
62
|
+
--- @include "includes/trimEvents"
|
63
|
+
--- @include "includes/getNextDelayedTimestamp"
|
64
|
+
|
65
|
+
if parentKey ~= nil then
|
66
|
+
if rcall("EXISTS", parentKey) ~= 1 then
|
67
|
+
return -5
|
68
|
+
end
|
69
|
+
|
70
|
+
parentData = cjson.encode(parent)
|
71
|
+
end
|
72
|
+
|
73
|
+
local jobCounter = rcall("INCR", KEYS[4])
|
74
|
+
|
75
|
+
-- Includes
|
76
|
+
--- @include "includes/updateParentDepsIfNeeded"
|
77
|
+
|
78
|
+
-- Trim events before emiting them to avoid trimming events emitted in this script
|
79
|
+
trimEvents(KEYS[3], KEYS[8])
|
80
|
+
|
81
|
+
local parentDependenciesKey = args[7]
|
82
|
+
if args[2] == "" then
|
83
|
+
jobId = jobCounter
|
84
|
+
jobIdKey = args[1] .. jobId
|
85
|
+
else
|
86
|
+
jobId = args[2]
|
87
|
+
jobIdKey = args[1] .. jobId
|
88
|
+
if rcall("EXISTS", jobIdKey) == 1 then
|
89
|
+
if parentKey ~= nil then
|
90
|
+
if rcall("ZSCORE", KEYS[7], jobId) ~= false then
|
91
|
+
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
92
|
+
updateParentDepsIfNeeded(parentKey, parent['queueKey'], parentDependenciesKey,
|
93
|
+
parent['id'], jobIdKey, returnvalue)
|
94
|
+
else
|
95
|
+
if parentDependenciesKey ~= nil then
|
96
|
+
rcall("SADD", parentDependenciesKey, jobIdKey)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
rcall("HMSET", jobIdKey, "parentKey", parentKey, "parent", parentData)
|
100
|
+
end
|
101
|
+
return jobId .. "" -- convert to string
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
-- Store the job.
|
106
|
+
local jsonOpts = cjson.encode(opts)
|
107
|
+
local delay = opts['delay'] or 0
|
108
|
+
local priority = opts['priority'] or 0
|
109
|
+
local timestamp = args[4]
|
110
|
+
|
111
|
+
local optionalValues = {}
|
112
|
+
if parentKey ~= nil then
|
113
|
+
table.insert(optionalValues, "parentKey")
|
114
|
+
table.insert(optionalValues, parentKey)
|
115
|
+
table.insert(optionalValues, "parent")
|
116
|
+
table.insert(optionalValues, parentData)
|
117
|
+
end
|
118
|
+
|
119
|
+
if repeatJobKey ~= nil then
|
120
|
+
table.insert(optionalValues, "rjk")
|
121
|
+
table.insert(optionalValues, repeatJobKey)
|
122
|
+
end
|
123
|
+
|
124
|
+
rcall("HMSET", jobIdKey, "name", args[3], "data", ARGV[2], "opts", jsonOpts,
|
125
|
+
"timestamp", timestamp, "delay", delay, "priority", priority, unpack(optionalValues))
|
126
|
+
|
127
|
+
rcall("XADD", KEYS[8], "*", "event", "added", "jobId", jobId, "name", args[3])
|
128
|
+
|
129
|
+
-- Check if job is delayed
|
130
|
+
local delayedTimestamp = (delay > 0 and (timestamp + delay)) or 0
|
131
|
+
|
132
|
+
-- Check if job is a parent, if so add to the parents set
|
133
|
+
local waitChildrenKey = args[6]
|
134
|
+
if waitChildrenKey ~= nil then
|
135
|
+
rcall("ZADD", waitChildrenKey, timestamp, jobId)
|
136
|
+
rcall("XADD", KEYS[8], "*", "event", "waiting-children", "jobId", jobId)
|
137
|
+
elseif (delayedTimestamp ~= 0) then
|
138
|
+
local timestamp = delayedTimestamp * 0x1000 + bit.band(jobCounter, 0xfff)
|
139
|
+
rcall("ZADD", KEYS[5], timestamp, jobId)
|
140
|
+
rcall("XADD", KEYS[8], "*", "event", "delayed", "jobId", jobId, "delay",
|
141
|
+
delayedTimestamp)
|
142
|
+
-- If wait list is empty, and this delayed job is the next one to be processed,
|
143
|
+
-- then we need to signal the workers by adding a dummy job (jobId 0) to the wait list.
|
144
|
+
local target = getTargetQueueList(KEYS[3], KEYS[1], KEYS[2])
|
145
|
+
if rcall("LLEN", target) == 0 then
|
146
|
+
local nextTimestamp = getNextDelayedTimestamp(KEYS[5])
|
147
|
+
if delayedTimestamp < nextTimestamp then
|
148
|
+
rcall("LPUSH", target, 0)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
else
|
152
|
+
local target = getTargetQueueList(KEYS[3], KEYS[1], KEYS[2])
|
153
|
+
|
154
|
+
-- Standard or priority add
|
155
|
+
if priority == 0 then
|
156
|
+
-- LIFO or FIFO
|
157
|
+
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH';
|
158
|
+
rcall(pushCmd, target, jobId)
|
159
|
+
else
|
160
|
+
-- Priority add
|
161
|
+
addJobWithPriority(KEYS[6], priority, target, jobId)
|
162
|
+
end
|
163
|
+
-- Emit waiting event
|
164
|
+
rcall("XADD", KEYS[8], "*", "event", "waiting", "jobId", jobId)
|
165
|
+
end
|
166
|
+
|
167
|
+
-- Check if this job is a child of another job, if so add it to the parents dependencies
|
168
|
+
-- TODO: Should not be possible to add a child job to a parent that is not in the "waiting-children" status.
|
169
|
+
-- fail in this case.
|
170
|
+
if parentDependenciesKey ~= nil then
|
171
|
+
rcall("SADD", parentDependenciesKey, jobIdKey)
|
172
|
+
end
|
173
|
+
|
174
|
+
return jobId .. "" -- convert to string
|
@@ -0,0 +1,43 @@
|
|
1
|
+
--[[
|
2
|
+
Change job delay when it is in delayed set.
|
3
|
+
Input:
|
4
|
+
KEYS[1] delayed key
|
5
|
+
KEYS[2] job key
|
6
|
+
KEYS[3] events stream
|
7
|
+
KEYS[4] delayed stream
|
8
|
+
|
9
|
+
ARGV[1] delay
|
10
|
+
ARGV[2] delayedTimestamp
|
11
|
+
ARGV[3] the id of the job
|
12
|
+
Output:
|
13
|
+
0 - OK
|
14
|
+
-1 - Missing job.
|
15
|
+
-3 - Job not in delayed set.
|
16
|
+
|
17
|
+
Events:
|
18
|
+
- delayed key.
|
19
|
+
]]
|
20
|
+
local rcall = redis.call
|
21
|
+
|
22
|
+
if rcall("EXISTS", KEYS[2]) == 1 then
|
23
|
+
|
24
|
+
local jobId = ARGV[3]
|
25
|
+
local score = tonumber(ARGV[2])
|
26
|
+
local delayedTimestamp = (score / 0x1000)
|
27
|
+
|
28
|
+
local numRemovedElements = rcall("ZREM", KEYS[1], jobId)
|
29
|
+
|
30
|
+
if (numRemovedElements < 1) then
|
31
|
+
return -3
|
32
|
+
end
|
33
|
+
|
34
|
+
rcall("HSET", KEYS[2], "delay", tonumber(ARGV[1]))
|
35
|
+
rcall("ZADD", KEYS[1], score, jobId)
|
36
|
+
|
37
|
+
rcall("XADD", KEYS[3], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp);
|
38
|
+
rcall("XADD", KEYS[4], "*", "nextTimestamp", delayedTimestamp);
|
39
|
+
|
40
|
+
return 0
|
41
|
+
else
|
42
|
+
return -1
|
43
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
--[[
|
2
|
+
Remove jobs from the specific set.
|
3
|
+
|
4
|
+
Input:
|
5
|
+
KEYS[1] set key,
|
6
|
+
KEYS[2] events stream key
|
7
|
+
|
8
|
+
ARGV[1] jobKey prefix
|
9
|
+
ARGV[2] timestamp
|
10
|
+
ARGV[3] limit the number of jobs to be removed. 0 is unlimited
|
11
|
+
ARGV[4] set name, can be any of 'wait', 'active', 'paused', 'delayed', 'completed', or 'failed'
|
12
|
+
]]
|
13
|
+
local rcall = redis.call
|
14
|
+
local rangeStart = 0
|
15
|
+
local rangeEnd = -1
|
16
|
+
|
17
|
+
local limit = tonumber(ARGV[3])
|
18
|
+
|
19
|
+
-- If we're only deleting _n_ items, avoid retrieving all items
|
20
|
+
-- for faster performance
|
21
|
+
--
|
22
|
+
-- Start from the tail of the list, since that's where oldest elements
|
23
|
+
-- are generally added for FIFO lists
|
24
|
+
if limit > 0 then
|
25
|
+
rangeStart = -1 - limit + 1
|
26
|
+
rangeEnd = -1
|
27
|
+
end
|
28
|
+
|
29
|
+
-- Includes
|
30
|
+
--- @include "includes/cleanList"
|
31
|
+
--- @include "includes/cleanSet"
|
32
|
+
|
33
|
+
local result
|
34
|
+
if ARGV[4] == "active" then
|
35
|
+
result = cleanList(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], false)
|
36
|
+
elseif ARGV[4] == "delayed" then
|
37
|
+
result = cleanSet(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], limit, {"processedOn", "timestamp"})
|
38
|
+
elseif ARGV[4] == "wait" or ARGV[4] == "paused" then
|
39
|
+
result = cleanList(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], true)
|
40
|
+
else
|
41
|
+
result = cleanSet(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], limit, {"finishedOn"} )
|
42
|
+
end
|
43
|
+
|
44
|
+
rcall("XADD", KEYS[2], "*", "event", "cleaned", "count", result[2])
|
45
|
+
|
46
|
+
return result[1]
|
@@ -0,0 +1,25 @@
|
|
1
|
+
--[[
|
2
|
+
Drains the queue, removes all jobs that are waiting
|
3
|
+
or delayed, but not active, completed or failed
|
4
|
+
|
5
|
+
Input:
|
6
|
+
KEYS[1] 'wait',
|
7
|
+
KEYS[2] 'paused'
|
8
|
+
KEYS[3] 'delayed'
|
9
|
+
KEYS[4] 'priority'
|
10
|
+
|
11
|
+
ARGV[1] queue key prefix
|
12
|
+
]]
|
13
|
+
local rcall = redis.call
|
14
|
+
local queueBaseKey = ARGV[1]
|
15
|
+
|
16
|
+
--- @include "includes/removeJobs"
|
17
|
+
|
18
|
+
removeListJobs(KEYS[1], true, queueBaseKey, 0) --wait
|
19
|
+
removeListJobs(KEYS[2], true, queueBaseKey, 0) --paused
|
20
|
+
|
21
|
+
if KEYS[3] ~= "" then
|
22
|
+
removeZSetJobs(KEYS[3], true, queueBaseKey, 0) --delayed
|
23
|
+
end
|
24
|
+
|
25
|
+
rcall("DEL", KEYS[4])
|
@@ -0,0 +1,23 @@
|
|
1
|
+
--[[
|
2
|
+
Extend lock and removes the job from the stalled set.
|
3
|
+
|
4
|
+
Input:
|
5
|
+
KEYS[1] 'lock',
|
6
|
+
KEYS[2] 'stalled'
|
7
|
+
|
8
|
+
ARGV[1] token
|
9
|
+
ARGV[2] lock duration in milliseconds
|
10
|
+
ARGV[3] jobid
|
11
|
+
|
12
|
+
Output:
|
13
|
+
"1" if lock extented succesfully.
|
14
|
+
]]
|
15
|
+
local rcall = redis.call
|
16
|
+
if rcall("GET", KEYS[1]) == ARGV[1] then
|
17
|
+
-- if rcall("SET", KEYS[1], ARGV[1], "PX", ARGV[2], "XX") then
|
18
|
+
if rcall("SET", KEYS[1], ARGV[1], "PX", ARGV[2]) then
|
19
|
+
rcall("SREM", KEYS[2], ARGV[3])
|
20
|
+
return 1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
return 0
|
@@ -0,0 +1,57 @@
|
|
1
|
+
--[[
|
2
|
+
Get a job state
|
3
|
+
|
4
|
+
Input:
|
5
|
+
KEYS[1] 'completed' key,
|
6
|
+
KEYS[2] 'failed' key
|
7
|
+
KEYS[3] 'delayed' key
|
8
|
+
KEYS[4] 'active' key
|
9
|
+
KEYS[5] 'wait' key
|
10
|
+
KEYS[6] 'paused' key
|
11
|
+
KEYS[7] waitChildrenKey key
|
12
|
+
|
13
|
+
ARGV[1] job id
|
14
|
+
Output:
|
15
|
+
'completed'
|
16
|
+
'failed'
|
17
|
+
'delayed'
|
18
|
+
'active'
|
19
|
+
'waiting'
|
20
|
+
'waiting-children'
|
21
|
+
'unknown'
|
22
|
+
]]
|
23
|
+
if redis.call("ZSCORE", KEYS[1], ARGV[1]) ~= false then
|
24
|
+
return "completed"
|
25
|
+
end
|
26
|
+
|
27
|
+
if redis.call("ZSCORE", KEYS[2], ARGV[1]) ~= false then
|
28
|
+
return "failed"
|
29
|
+
end
|
30
|
+
|
31
|
+
if redis.call("ZSCORE", KEYS[3], ARGV[1]) ~= false then
|
32
|
+
return "delayed"
|
33
|
+
end
|
34
|
+
|
35
|
+
-- Includes
|
36
|
+
--- @include "includes/checkItemInList"
|
37
|
+
|
38
|
+
local active_items = redis.call("LRANGE", KEYS[4] , 0, -1)
|
39
|
+
if checkItemInList(active_items, ARGV[1]) ~= nil then
|
40
|
+
return "active"
|
41
|
+
end
|
42
|
+
|
43
|
+
local wait_items = redis.call("LRANGE", KEYS[5] , 0, -1)
|
44
|
+
if checkItemInList(wait_items, ARGV[1]) ~= nil then
|
45
|
+
return "waiting"
|
46
|
+
end
|
47
|
+
|
48
|
+
local paused_items = redis.call("LRANGE", KEYS[6] , 0, -1)
|
49
|
+
if checkItemInList(paused_items, ARGV[1]) ~= nil then
|
50
|
+
return "waiting"
|
51
|
+
end
|
52
|
+
|
53
|
+
if redis.call("ZSCORE", KEYS[7], ARGV[1]) ~= false then
|
54
|
+
return "waiting-children"
|
55
|
+
end
|
56
|
+
|
57
|
+
return "unknown"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
--[[
|
2
|
+
Get a job state
|
3
|
+
|
4
|
+
Input:
|
5
|
+
KEYS[1] 'completed' key,
|
6
|
+
KEYS[2] 'failed' key
|
7
|
+
KEYS[3] 'delayed' key
|
8
|
+
KEYS[4] 'active' key
|
9
|
+
KEYS[5] 'wait' key
|
10
|
+
KEYS[6] 'paused' key
|
11
|
+
KEYS[7] waitChildrenKey key
|
12
|
+
|
13
|
+
ARGV[1] job id
|
14
|
+
Output:
|
15
|
+
'completed'
|
16
|
+
'failed'
|
17
|
+
'delayed'
|
18
|
+
'active'
|
19
|
+
'waiting'
|
20
|
+
'waiting-children'
|
21
|
+
'unknown'
|
22
|
+
]]
|
23
|
+
if redis.call("ZSCORE", KEYS[1], ARGV[1]) ~= false then
|
24
|
+
return "completed"
|
25
|
+
end
|
26
|
+
|
27
|
+
if redis.call("ZSCORE", KEYS[2], ARGV[1]) ~= false then
|
28
|
+
return "failed"
|
29
|
+
end
|
30
|
+
|
31
|
+
if redis.call("ZSCORE", KEYS[3], ARGV[1]) ~= false then
|
32
|
+
return "delayed"
|
33
|
+
end
|
34
|
+
|
35
|
+
if redis.call("LPOS", KEYS[4] , ARGV[1]) ~= false then
|
36
|
+
return "active"
|
37
|
+
end
|
38
|
+
|
39
|
+
if redis.call("LPOS", KEYS[5] , ARGV[1]) ~= false then
|
40
|
+
return "waiting"
|
41
|
+
end
|
42
|
+
|
43
|
+
if redis.call("LPOS", KEYS[6] , ARGV[1]) ~= false then
|
44
|
+
return "waiting"
|
45
|
+
end
|
46
|
+
|
47
|
+
if redis.call("ZSCORE", KEYS[7] , ARGV[1]) ~= false then
|
48
|
+
return "waiting-children"
|
49
|
+
end
|
50
|
+
|
51
|
+
return "unknown"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
--[[
|
2
|
+
Function to add job considering priority.
|
3
|
+
]]
|
4
|
+
|
5
|
+
local function addJobWithPriority(priorityKey, priority, targetKey, jobId)
|
6
|
+
rcall("ZADD", priorityKey, priority, jobId)
|
7
|
+
local count = rcall("ZCOUNT", priorityKey, 0, priority)
|
8
|
+
|
9
|
+
local len = rcall("LLEN", targetKey)
|
10
|
+
local id = rcall("LINDEX", targetKey, len - (count - 1))
|
11
|
+
if id then
|
12
|
+
rcall("LINSERT", targetKey, "BEFORE", id, jobId)
|
13
|
+
else
|
14
|
+
rcall("RPUSH", targetKey, jobId)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
--[[
|
2
|
+
Function to loop in batches.
|
3
|
+
Just a bit of warning, some commands as ZREM
|
4
|
+
could receive a maximum of 7000 parameters per call.
|
5
|
+
]]
|
6
|
+
|
7
|
+
local function batches(n, batchSize)
|
8
|
+
local i = 0
|
9
|
+
|
10
|
+
return function()
|
11
|
+
local from = i * batchSize + 1
|
12
|
+
i = i + 1
|
13
|
+
if (from <= n) then
|
14
|
+
local to = math.min(from + batchSize - 1, n)
|
15
|
+
return from, to
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
--[[
|
2
|
+
Move stalled jobs to wait.
|
3
|
+
|
4
|
+
Input:
|
5
|
+
stalledKey 'stalled' (SET)
|
6
|
+
waitKey 'wait', (LIST)
|
7
|
+
activeKey 'active', (LIST)
|
8
|
+
failedKey 'failed', (ZSET)
|
9
|
+
stalledCheckKey 'stalled-check', (KEY)
|
10
|
+
metaKey 'meta', (KEY)
|
11
|
+
pausedKey 'paused', (LIST)
|
12
|
+
eventStreamKey 'event stream' (STREAM)
|
13
|
+
|
14
|
+
maxStalledJobCount Max stalled job count
|
15
|
+
queueKeyPrefix queue.toKey('')
|
16
|
+
timestamp timestamp
|
17
|
+
maxCheckTime max check time
|
18
|
+
|
19
|
+
Events:
|
20
|
+
'stalled' with stalled job id.
|
21
|
+
]] local rcall = redis.call
|
22
|
+
|
23
|
+
-- Includes
|
24
|
+
--- @include "batches"
|
25
|
+
--- @include "getTargetQueueList"
|
26
|
+
--- @include "removeJob"
|
27
|
+
--- @include "removeJobsByMaxAge"
|
28
|
+
--- @include "removeJobsByMaxCount"
|
29
|
+
--- @include "trimEvents"
|
30
|
+
|
31
|
+
-- Check if we need to check for stalled jobs now.
|
32
|
+
|
33
|
+
local function checkStalledJobs(stalledKey, waitKey, activeKey, failedKey, stalledCheckKey,
|
34
|
+
metaKey, pausedKey, eventStreamKey, maxStalledJobCount, queueKeyPrefix, timestamp, maxCheckTime)
|
35
|
+
if rcall("EXISTS", stalledCheckKey) == 1 then
|
36
|
+
return {{}, {}}
|
37
|
+
end
|
38
|
+
|
39
|
+
rcall("SET", stalledCheckKey, timestamp, "PX", maxCheckTime)
|
40
|
+
|
41
|
+
-- Trim events before emiting them to avoid trimming events emitted in this script
|
42
|
+
trimEvents(metaKey, eventStreamKey)
|
43
|
+
|
44
|
+
-- Move all stalled jobs to wait
|
45
|
+
local stalling = rcall('SMEMBERS', stalledKey)
|
46
|
+
local stalled = {}
|
47
|
+
local failed = {}
|
48
|
+
if (#stalling > 0) then
|
49
|
+
rcall('DEL', stalledKey)
|
50
|
+
|
51
|
+
local MAX_STALLED_JOB_COUNT = tonumber(maxStalledJobCount)
|
52
|
+
|
53
|
+
-- Remove from active list
|
54
|
+
for i, jobId in ipairs(stalling) do
|
55
|
+
|
56
|
+
if jobId == '0' then
|
57
|
+
-- If the jobId is a delay marker ID we just remove it.
|
58
|
+
local removed = rcall("LREM", activeKey, 1, jobId)
|
59
|
+
else
|
60
|
+
local jobKey = queueKeyPrefix .. jobId
|
61
|
+
|
62
|
+
-- Check that the lock is also missing, then we can handle this job as really stalled.
|
63
|
+
if (rcall("EXISTS", jobKey .. ":lock") == 0) then
|
64
|
+
-- Remove from the active queue.
|
65
|
+
local removed = rcall("LREM", activeKey, 1, jobId)
|
66
|
+
|
67
|
+
if (removed > 0) then
|
68
|
+
-- If this job has been stalled too many times, such as if it crashes the worker, then fail it.
|
69
|
+
local stalledCount =
|
70
|
+
rcall("HINCRBY", jobKey, "stalledCounter", 1)
|
71
|
+
if (stalledCount > MAX_STALLED_JOB_COUNT) then
|
72
|
+
local rawOpts = rcall("HGET", jobKey, "opts")
|
73
|
+
local opts = cjson.decode(rawOpts)
|
74
|
+
local removeOnFailType = type(opts["removeOnFail"])
|
75
|
+
rcall("ZADD", failedKey, timestamp, jobId)
|
76
|
+
local failedReason =
|
77
|
+
"job stalled more than allowable limit"
|
78
|
+
rcall("HMSET", jobKey, "failedReason", failedReason,
|
79
|
+
"finishedOn", timestamp)
|
80
|
+
rcall("XADD", eventStreamKey, "*", "event", "failed", "jobId",
|
81
|
+
jobId, 'prev', 'active', 'failedReason',
|
82
|
+
failedReason)
|
83
|
+
|
84
|
+
if removeOnFailType == "number" then
|
85
|
+
removeJobsByMaxCount(opts["removeOnFail"], failedKey,
|
86
|
+
queueKeyPrefix)
|
87
|
+
elseif removeOnFailType == "boolean" then
|
88
|
+
if opts["removeOnFail"] then
|
89
|
+
removeJob(jobId, false, queueKeyPrefix)
|
90
|
+
rcall("ZREM", failedKey, jobId)
|
91
|
+
end
|
92
|
+
elseif removeOnFailType ~= "nil" then
|
93
|
+
local maxAge = opts["removeOnFail"]["age"]
|
94
|
+
local maxCount = opts["removeOnFail"]["count"]
|
95
|
+
|
96
|
+
if maxAge ~= nil then
|
97
|
+
removeJobsByMaxAge(timestamp, maxAge, failedKey,
|
98
|
+
queueKeyPrefix)
|
99
|
+
end
|
100
|
+
|
101
|
+
if maxCount ~= nil and maxCount > 0 then
|
102
|
+
removeJobsByMaxCount(maxCount, failedKey, queueKeyPrefix)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
table.insert(failed, jobId)
|
107
|
+
else
|
108
|
+
local target = getTargetQueueList(metaKey, waitKey,
|
109
|
+
pausedKey)
|
110
|
+
|
111
|
+
-- Move the job back to the wait queue, to immediately be picked up by a waiting worker.
|
112
|
+
rcall("RPUSH", target, jobId)
|
113
|
+
rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId",
|
114
|
+
jobId, 'prev', 'active')
|
115
|
+
|
116
|
+
-- Emit the stalled event
|
117
|
+
rcall("XADD", eventStreamKey, "*", "event", "stalled", "jobId",
|
118
|
+
jobId)
|
119
|
+
table.insert(stalled, jobId)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
-- Mark potentially stalled jobs
|
128
|
+
local active = rcall('LRANGE', activeKey, 0, -1)
|
129
|
+
|
130
|
+
if (#active > 0) then
|
131
|
+
for from, to in batches(#active, 7000) do
|
132
|
+
rcall('SADD', stalledKey, unpack(active, from, to))
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
return {failed, stalled}
|
137
|
+
end
|