bullmq 4.14.1 → 4.14.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.
Files changed (57) hide show
  1. package/dist/cjs/classes/async-fifo-queue.js +12 -5
  2. package/dist/cjs/classes/async-fifo-queue.js.map +1 -1
  3. package/dist/cjs/classes/scripts.js +57 -4
  4. package/dist/cjs/classes/scripts.js.map +1 -1
  5. package/dist/cjs/commands/addDelayedJob-7.lua +123 -0
  6. package/dist/cjs/commands/addParentJob-4.lua +100 -0
  7. package/dist/cjs/commands/addPrioritizedJob-8.lua +116 -0
  8. package/dist/cjs/commands/addStandardJob-6.lua +115 -0
  9. package/dist/cjs/commands/includes/storeJob.lua +30 -0
  10. package/dist/cjs/commands/includes/updateExistingJobsParent.lua +25 -0
  11. package/dist/cjs/commands/updateProgress-3.lua +30 -0
  12. package/dist/cjs/scripts/addDelayedJob-7.js +267 -0
  13. package/dist/cjs/scripts/addDelayedJob-7.js.map +1 -0
  14. package/dist/cjs/scripts/addParentJob-4.js +251 -0
  15. package/dist/cjs/scripts/addParentJob-4.js.map +1 -0
  16. package/dist/cjs/scripts/addPrioritizedJob-8.js +262 -0
  17. package/dist/cjs/scripts/addPrioritizedJob-8.js.map +1 -0
  18. package/dist/cjs/scripts/{addJob-9.js → addStandardJob-6.js} +87 -91
  19. package/dist/cjs/scripts/addStandardJob-6.js.map +1 -0
  20. package/dist/cjs/scripts/index.js +4 -1
  21. package/dist/cjs/scripts/index.js.map +1 -1
  22. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  23. package/dist/esm/classes/async-fifo-queue.d.ts +13 -1
  24. package/dist/esm/classes/async-fifo-queue.js +12 -5
  25. package/dist/esm/classes/async-fifo-queue.js.map +1 -1
  26. package/dist/esm/classes/job.d.ts +1 -1
  27. package/dist/esm/classes/scripts.d.ts +3 -0
  28. package/dist/esm/classes/scripts.js +57 -4
  29. package/dist/esm/classes/scripts.js.map +1 -1
  30. package/dist/esm/commands/addDelayedJob-7.lua +123 -0
  31. package/dist/esm/commands/addParentJob-4.lua +100 -0
  32. package/dist/esm/commands/addPrioritizedJob-8.lua +116 -0
  33. package/dist/esm/commands/addStandardJob-6.lua +115 -0
  34. package/dist/esm/commands/includes/storeJob.lua +30 -0
  35. package/dist/esm/commands/includes/updateExistingJobsParent.lua +25 -0
  36. package/dist/esm/commands/updateProgress-3.lua +30 -0
  37. package/dist/esm/scripts/addDelayedJob-7.d.ts +5 -0
  38. package/dist/esm/scripts/addDelayedJob-7.js +264 -0
  39. package/dist/esm/scripts/addDelayedJob-7.js.map +1 -0
  40. package/dist/esm/scripts/{addJob-9.d.ts → addParentJob-4.d.ts} +1 -1
  41. package/dist/esm/scripts/addParentJob-4.js +248 -0
  42. package/dist/esm/scripts/addParentJob-4.js.map +1 -0
  43. package/dist/esm/scripts/addPrioritizedJob-8.d.ts +5 -0
  44. package/dist/esm/scripts/addPrioritizedJob-8.js +259 -0
  45. package/dist/esm/scripts/addPrioritizedJob-8.js.map +1 -0
  46. package/dist/esm/scripts/addStandardJob-6.d.ts +5 -0
  47. package/dist/esm/scripts/{addJob-9.js → addStandardJob-6.js} +86 -90
  48. package/dist/esm/scripts/addStandardJob-6.js.map +1 -0
  49. package/dist/esm/scripts/index.d.ts +4 -1
  50. package/dist/esm/scripts/index.js +4 -1
  51. package/dist/esm/scripts/index.js.map +1 -1
  52. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  53. package/package.json +1 -1
  54. package/dist/cjs/commands/addJob-9.lua +0 -173
  55. package/dist/cjs/scripts/addJob-9.js.map +0 -1
  56. package/dist/esm/commands/addJob-9.lua +0 -173
  57. package/dist/esm/scripts/addJob-9.js.map +0 -1
@@ -0,0 +1,259 @@
1
+ const content = `--[[
2
+ Adds a priotitized 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
+ - Adds the job to the "added" list so that workers gets notified.
6
+ Input:
7
+ KEYS[1] 'wait',
8
+ KEYS[2] 'paused'
9
+ KEYS[3] 'meta'
10
+ KEYS[4] 'id'
11
+ KEYS[5] 'prioritized'
12
+ KEYS[6] 'completed'
13
+ KEYS[7] events stream key
14
+ KEYS[8] 'pc' priority counter
15
+ ARGV[1] msgpacked arguments array
16
+ [1] key prefix,
17
+ [2] custom id (will not generate one automatically)
18
+ [3] name
19
+ [4] timestamp
20
+ [5] parentKey?
21
+ [6] waitChildrenKey key.
22
+ [7] parent dependencies key.
23
+ [8] parent? {id, queueKey}
24
+ [9] repeat job key
25
+ ARGV[2] Json stringified job data
26
+ ARGV[3] msgpacked options
27
+ Output:
28
+ jobId - OK
29
+ -5 - Missing parent key
30
+ ]]
31
+ local waitKey = KEYS[1]
32
+ local pausedKey = KEYS[2]
33
+ local metaKey = KEYS[3]
34
+ local idKey = KEYS[4]
35
+ local priorityKey = KEYS[5]
36
+ local completedKey = KEYS[6]
37
+ local eventsKey = KEYS[7]
38
+ local priorityCounterKey = KEYS[8]
39
+ local jobId
40
+ local jobIdKey
41
+ local rcall = redis.call
42
+ local args = cmsgpack.unpack(ARGV[1])
43
+ local data = ARGV[2]
44
+ local opts = cmsgpack.unpack(ARGV[3])
45
+ local parentKey = args[5]
46
+ local repeatJobKey = args[9]
47
+ local parent = args[8]
48
+ local parentData
49
+ -- Includes
50
+ --[[
51
+ Function to store a job
52
+ ]]
53
+ local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
54
+ parentKey, parentData, repeatJobKey)
55
+ local jsonOpts = cjson.encode(opts)
56
+ local delay = opts['delay'] or 0
57
+ local priority = opts['priority'] or 0
58
+ local optionalValues = {}
59
+ if parentKey ~= nil then
60
+ table.insert(optionalValues, "parentKey")
61
+ table.insert(optionalValues, parentKey)
62
+ table.insert(optionalValues, "parent")
63
+ table.insert(optionalValues, parentData)
64
+ end
65
+ if repeatJobKey ~= nil then
66
+ table.insert(optionalValues, "rjk")
67
+ table.insert(optionalValues, repeatJobKey)
68
+ end
69
+ rcall("HMSET", jobIdKey, "name", name, "data", data, "opts", jsonOpts,
70
+ "timestamp", timestamp, "delay", delay, "priority", priority,
71
+ unpack(optionalValues))
72
+ rcall("XADD", eventsKey, "*", "event", "added", "jobId", jobId, "name", name)
73
+ return delay, priority
74
+ end
75
+ --[[
76
+ Function to add job considering priority.
77
+ ]]
78
+ -- Includes
79
+ --[[
80
+ Function priority marker to wait if needed
81
+ in order to wake up our workers and to respect priority
82
+ order as much as possible
83
+ ]]
84
+ local function addPriorityMarkerIfNeeded(waitKey)
85
+ local waitLen = rcall("LLEN", waitKey)
86
+ if waitLen == 0 then
87
+ rcall("LPUSH", waitKey, "0:0")
88
+ end
89
+ end
90
+ local function addJobWithPriority(waitKey, prioritizedKey, priority, paused, jobId, priorityCounterKey)
91
+ local prioCounter = rcall("INCR", priorityCounterKey)
92
+ local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
93
+ rcall("ZADD", prioritizedKey, score, jobId)
94
+ if not paused then
95
+ addPriorityMarkerIfNeeded(waitKey)
96
+ end
97
+ end
98
+ --[[
99
+ Function to check for the meta.paused key to decide if we are paused or not
100
+ (since an empty list and !EXISTS are not really the same).
101
+ ]]
102
+ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
103
+ if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
104
+ return waitKey, false
105
+ else
106
+ return pausedKey, true
107
+ end
108
+ end
109
+ --[[
110
+ Validate and move or add dependencies to parent.
111
+ ]]
112
+ -- Includes
113
+ --[[
114
+ Validate and move parent to active if needed.
115
+ ]]
116
+ -- Includes
117
+ --[[
118
+ Add delay marker if needed.
119
+ ]]
120
+ -- Includes
121
+ --[[
122
+ Function to return the next delayed job timestamp.
123
+ ]]
124
+ local function getNextDelayedTimestamp(delayedKey)
125
+ local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
126
+ if #result then
127
+ local nextTimestamp = tonumber(result[2])
128
+ if (nextTimestamp ~= nil) then
129
+ nextTimestamp = nextTimestamp / 0x1000
130
+ end
131
+ return nextTimestamp
132
+ end
133
+ end
134
+ local function addDelayMarkerIfNeeded(targetKey, delayedKey)
135
+ local waitLen = rcall("LLEN", targetKey)
136
+ if waitLen <= 1 then
137
+ local nextTimestamp = getNextDelayedTimestamp(delayedKey)
138
+ if nextTimestamp ~= nil then
139
+ -- Check if there is already a marker with older timestamp
140
+ -- if there is, we need to replace it.
141
+ if waitLen == 1 then
142
+ local marker = rcall("LINDEX", targetKey, 0)
143
+ local oldTimestamp = tonumber(marker:sub(3))
144
+ if oldTimestamp and oldTimestamp > nextTimestamp then
145
+ rcall("LSET", targetKey, 0, "0:" .. nextTimestamp)
146
+ end
147
+ else
148
+ -- if there is no marker, then we need to add one
149
+ rcall("LPUSH", targetKey, "0:" .. nextTimestamp)
150
+ end
151
+ end
152
+ end
153
+ end
154
+ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
155
+ local isParentActive = rcall("ZSCORE", parentQueueKey .. ":waiting-children", parentId)
156
+ if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
157
+ rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
158
+ local parentWaitKey = parentQueueKey .. ":wait"
159
+ local parentTarget, paused = getTargetQueueList(parentQueueKey .. ":meta", parentWaitKey,
160
+ parentQueueKey .. ":paused")
161
+ local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
162
+ local priority = tonumber(jobAttributes[1]) or 0
163
+ local delay = tonumber(jobAttributes[2]) or 0
164
+ if delay > 0 then
165
+ local delayedTimestamp = tonumber(timestamp) + delay
166
+ local score = delayedTimestamp * 0x1000
167
+ local parentDelayedKey = parentQueueKey .. ":delayed"
168
+ rcall("ZADD", parentDelayedKey, score, parentId)
169
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId,
170
+ "delay", delayedTimestamp)
171
+ addDelayMarkerIfNeeded(parentTarget, parentDelayedKey)
172
+ else
173
+ if priority == 0 then
174
+ rcall("RPUSH", parentTarget, parentId)
175
+ else
176
+ addJobWithPriority(parentWaitKey, parentQueueKey .. ":prioritized", priority, paused,
177
+ parentId, parentQueueKey .. ":pc")
178
+ end
179
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId,
180
+ "prev", "waiting-children")
181
+ end
182
+ end
183
+ end
184
+ local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
185
+ parentId, jobIdKey, returnvalue, timestamp )
186
+ local processedSet = parentKey .. ":processed"
187
+ rcall("HSET", processedSet, jobIdKey, returnvalue)
188
+ moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
189
+ end
190
+ --[[
191
+ This function is used to update the parent's dependencies if the job
192
+ is already completed and about to be ignored. The parent must get its
193
+ dependencies updated to avoid the parent job being stuck forever in
194
+ the waiting-children state.
195
+ ]]
196
+ local function updateExistingJobsParent(parentKey, parent, parentData,
197
+ parentDependenciesKey, completedKey,
198
+ jobIdKey, jobId, timestamp)
199
+ if parentKey ~= nil then
200
+ if rcall("ZSCORE", completedKey, jobId) ~= false then
201
+ local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
202
+ updateParentDepsIfNeeded(parentKey, parent['queueKey'],
203
+ parentDependenciesKey, parent['id'],
204
+ jobIdKey, returnvalue, timestamp)
205
+ else
206
+ if parentDependenciesKey ~= nil then
207
+ rcall("SADD", parentDependenciesKey, jobIdKey)
208
+ end
209
+ end
210
+ rcall("HMSET", jobIdKey, "parentKey", parentKey, "parent", parentData)
211
+ end
212
+ end
213
+ if parentKey ~= nil then
214
+ if rcall("EXISTS", parentKey) ~= 1 then return -5 end
215
+ parentData = cjson.encode(parent)
216
+ end
217
+ local jobCounter = rcall("INCR", idKey)
218
+ local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents") or 10000
219
+ local parentDependenciesKey = args[7]
220
+ local timestamp = args[4]
221
+ if args[2] == "" then
222
+ jobId = jobCounter
223
+ jobIdKey = args[1] .. jobId
224
+ else
225
+ jobId = args[2]
226
+ jobIdKey = args[1] .. jobId
227
+ if rcall("EXISTS", jobIdKey) == 1 then
228
+ updateExistingJobsParent(parentKey, parent, parentData,
229
+ parentDependenciesKey, completedKey, jobIdKey,
230
+ jobId, timestamp)
231
+ rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
232
+ "duplicated", "jobId", jobId)
233
+ return jobId .. "" -- convert to string
234
+ end
235
+ end
236
+ -- Store the job.
237
+ local delay, priority = storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2],
238
+ opts, timestamp, parentKey, parentData,
239
+ repeatJobKey)
240
+ local target, paused = getTargetQueueList(metaKey, waitKey, pausedKey)
241
+ addJobWithPriority(waitKey, priorityKey, priority, paused, jobId,
242
+ priorityCounterKey)
243
+ -- Emit waiting event
244
+ rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
245
+ "jobId", jobId)
246
+ -- Check if this job is a child of another job, if so add it to the parents dependencies
247
+ -- TODO: Should not be possible to add a child job to a parent that is not in the "waiting-children" status.
248
+ -- fail in this case.
249
+ if parentDependenciesKey ~= nil then
250
+ rcall("SADD", parentDependenciesKey, jobIdKey)
251
+ end
252
+ return jobId .. "" -- convert to string
253
+ `;
254
+ export const addPrioritizedJob = {
255
+ name: 'addPrioritizedJob',
256
+ content,
257
+ keys: 8,
258
+ };
259
+ //# sourceMappingURL=addPrioritizedJob-8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addPrioritizedJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addPrioritizedJob-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Pf,CAAC;AACF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,mBAAmB;IACzB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const addStandardJob: {
2
+ name: string;
3
+ content: string;
4
+ keys: number;
5
+ };
@@ -17,11 +17,8 @@ const content = `--[[
17
17
  KEYS[2] 'paused'
18
18
  KEYS[3] 'meta'
19
19
  KEYS[4] 'id'
20
- KEYS[5] 'delayed'
21
- KEYS[6] 'prioritized'
22
- KEYS[7] 'completed'
23
- KEYS[8] events stream key
24
- KEYS[9] 'pc' priority counter
20
+ KEYS[5] 'completed'
21
+ KEYS[6] events stream key
25
22
  ARGV[1] msgpacked arguments array
26
23
  [1] key prefix,
27
24
  [2] custom id (will not generate one automatically)
@@ -38,6 +35,7 @@ const content = `--[[
38
35
  jobId - OK
39
36
  -5 - Missing parent key
40
37
  ]]
38
+ local eventsKey = KEYS[6]
41
39
  local jobId
42
40
  local jobIdKey
43
41
  local rcall = redis.call
@@ -49,6 +47,39 @@ local repeatJobKey = args[9]
49
47
  local parent = args[8]
50
48
  local parentData
51
49
  -- Includes
50
+ --[[
51
+ Function to store a job
52
+ ]]
53
+ local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
54
+ parentKey, parentData, repeatJobKey)
55
+ local jsonOpts = cjson.encode(opts)
56
+ local delay = opts['delay'] or 0
57
+ local priority = opts['priority'] or 0
58
+ local optionalValues = {}
59
+ if parentKey ~= nil then
60
+ table.insert(optionalValues, "parentKey")
61
+ table.insert(optionalValues, parentKey)
62
+ table.insert(optionalValues, "parent")
63
+ table.insert(optionalValues, parentData)
64
+ end
65
+ if repeatJobKey ~= nil then
66
+ table.insert(optionalValues, "rjk")
67
+ table.insert(optionalValues, repeatJobKey)
68
+ end
69
+ rcall("HMSET", jobIdKey, "name", name, "data", data, "opts", jsonOpts,
70
+ "timestamp", timestamp, "delay", delay, "priority", priority,
71
+ unpack(optionalValues))
72
+ rcall("XADD", eventsKey, "*", "event", "added", "jobId", jobId, "name", name)
73
+ return delay, priority
74
+ end
75
+ --[[
76
+ Validate and move or add dependencies to parent.
77
+ ]]
78
+ -- Includes
79
+ --[[
80
+ Validate and move parent to active if needed.
81
+ ]]
82
+ -- Includes
52
83
  --[[
53
84
  Add delay marker if needed.
54
85
  ]]
@@ -120,14 +151,6 @@ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
120
151
  return pausedKey, true
121
152
  end
122
153
  end
123
- --[[
124
- Validate and move or add dependencies to parent.
125
- ]]
126
- -- Includes
127
- --[[
128
- Validate and move parent to active if needed.
129
- ]]
130
- -- Includes
131
154
  local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
132
155
  local isParentActive = rcall("ZSCORE", parentQueueKey .. ":waiting-children", parentId)
133
156
  if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
@@ -164,100 +187,73 @@ local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDepende
164
187
  rcall("HSET", processedSet, jobIdKey, returnvalue)
165
188
  moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
166
189
  end
190
+ --[[
191
+ This function is used to update the parent's dependencies if the job
192
+ is already completed and about to be ignored. The parent must get its
193
+ dependencies updated to avoid the parent job being stuck forever in
194
+ the waiting-children state.
195
+ ]]
196
+ local function updateExistingJobsParent(parentKey, parent, parentData,
197
+ parentDependenciesKey, completedKey,
198
+ jobIdKey, jobId, timestamp)
199
+ if parentKey ~= nil then
200
+ if rcall("ZSCORE", completedKey, jobId) ~= false then
201
+ local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
202
+ updateParentDepsIfNeeded(parentKey, parent['queueKey'],
203
+ parentDependenciesKey, parent['id'],
204
+ jobIdKey, returnvalue, timestamp)
205
+ else
206
+ if parentDependenciesKey ~= nil then
207
+ rcall("SADD", parentDependenciesKey, jobIdKey)
208
+ end
209
+ end
210
+ rcall("HMSET", jobIdKey, "parentKey", parentKey, "parent", parentData)
211
+ end
212
+ end
167
213
  if parentKey ~= nil then
168
- if rcall("EXISTS", parentKey) ~= 1 then
169
- return -5
170
- end
171
- parentData = cjson.encode(parent)
214
+ if rcall("EXISTS", parentKey) ~= 1 then return -5 end
215
+ parentData = cjson.encode(parent)
172
216
  end
173
217
  local jobCounter = rcall("INCR", KEYS[4])
174
218
  local maxEvents = rcall("HGET", KEYS[3], "opts.maxLenEvents") or 10000
175
219
  local parentDependenciesKey = args[7]
176
220
  local timestamp = args[4]
177
221
  if args[2] == "" then
178
- jobId = jobCounter
179
- jobIdKey = args[1] .. jobId
222
+ jobId = jobCounter
223
+ jobIdKey = args[1] .. jobId
180
224
  else
181
- jobId = args[2]
182
- jobIdKey = args[1] .. jobId
183
- if rcall("EXISTS", jobIdKey) == 1 then
184
- if parentKey ~= nil then
185
- if rcall("ZSCORE", KEYS[7], jobId) ~= false then
186
- local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
187
- updateParentDepsIfNeeded(parentKey, parent['queueKey'], parentDependenciesKey,
188
- parent['id'], jobIdKey, returnvalue, timestamp)
189
- else
190
- if parentDependenciesKey ~= nil then
191
- rcall("SADD", parentDependenciesKey, jobIdKey)
192
- end
193
- end
194
- rcall("HMSET", jobIdKey, "parentKey", parentKey, "parent", parentData)
225
+ jobId = args[2]
226
+ jobIdKey = args[1] .. jobId
227
+ if rcall("EXISTS", jobIdKey) == 1 then
228
+ updateExistingJobsParent(parentKey, parent, parentData,
229
+ parentDependenciesKey, KEYS[5], jobIdKey,
230
+ jobId, timestamp)
231
+ rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
232
+ "duplicated", "jobId", jobId)
233
+ return jobId .. "" -- convert to string
195
234
  end
196
- rcall("XADD", KEYS[8], "MAXLEN", "~", maxEvents, "*", "event", "duplicated",
197
- "jobId", jobId)
198
- return jobId .. "" -- convert to string
199
- end
200
235
  end
201
236
  -- Store the job.
202
- local jsonOpts = cjson.encode(opts)
203
- local delay = opts['delay'] or 0
204
- local priority = opts['priority'] or 0
205
- local optionalValues = {}
206
- if parentKey ~= nil then
207
- table.insert(optionalValues, "parentKey")
208
- table.insert(optionalValues, parentKey)
209
- table.insert(optionalValues, "parent")
210
- table.insert(optionalValues, parentData)
211
- end
212
- if repeatJobKey ~= nil then
213
- table.insert(optionalValues, "rjk")
214
- table.insert(optionalValues, repeatJobKey)
215
- end
216
- rcall("HMSET", jobIdKey, "name", args[3], "data", ARGV[2], "opts", jsonOpts,
217
- "timestamp", timestamp, "delay", delay, "priority", priority, unpack(optionalValues))
218
- rcall("XADD", KEYS[8], "*", "event", "added", "jobId", jobId, "name", args[3])
219
- -- Check if job is delayed
220
- local delayedTimestamp = (delay > 0 and (timestamp + delay)) or 0
221
- -- Check if job is a parent, if so add to the parents set
222
- local waitChildrenKey = args[6]
223
- if waitChildrenKey ~= nil then
224
- rcall("ZADD", waitChildrenKey, timestamp, jobId)
225
- rcall("XADD", KEYS[8], "MAXLEN", "~", maxEvents, "*", "event", "waiting-children", "jobId", jobId)
226
- elseif (delayedTimestamp ~= 0) then
227
- local delayedKey = KEYS[5]
228
- local score = delayedTimestamp * 0x1000 + bit.band(jobCounter, 0xfff)
229
- rcall("ZADD", delayedKey, score, jobId)
230
- rcall("XADD", KEYS[8], "MAXLEN", "~", maxEvents, "*", "event", "delayed", "jobId", jobId,
231
- "delay", delayedTimestamp)
232
- -- If wait list is empty, and this delayed job is the next one to be processed,
233
- -- then we need to signal the workers by adding a dummy job (jobId 0:delay) to the wait list.
234
- local target = getTargetQueueList(KEYS[3], KEYS[1], KEYS[2])
235
- addDelayMarkerIfNeeded(target, delayedKey)
236
- else
237
- local target, paused = getTargetQueueList(KEYS[3], KEYS[1], KEYS[2])
238
- -- Standard or priority add
239
- if priority == 0 then
240
- -- LIFO or FIFO
241
- local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
242
- rcall(pushCmd, target, jobId)
243
- else
244
- addJobWithPriority(KEYS[1], KEYS[6], priority, paused, jobId, KEYS[9])
245
- end
246
- -- Emit waiting event
247
- rcall("XADD", KEYS[8], "MAXLEN", "~", maxEvents, "*", "event", "waiting",
248
- "jobId", jobId)
249
- end
237
+ storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2], opts, timestamp,
238
+ parentKey, parentData, repeatJobKey)
239
+ local target, paused = getTargetQueueList(KEYS[3], KEYS[1], KEYS[2])
240
+ -- LIFO or FIFO
241
+ local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
242
+ rcall(pushCmd, target, jobId)
243
+ -- Emit waiting event
244
+ rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
245
+ "jobId", jobId)
250
246
  -- Check if this job is a child of another job, if so add it to the parents dependencies
251
247
  -- TODO: Should not be possible to add a child job to a parent that is not in the "waiting-children" status.
252
248
  -- fail in this case.
253
249
  if parentDependenciesKey ~= nil then
254
- rcall("SADD", parentDependenciesKey, jobIdKey)
250
+ rcall("SADD", parentDependenciesKey, jobIdKey)
255
251
  end
256
252
  return jobId .. "" -- convert to string
257
253
  `;
258
- export const addJob = {
259
- name: 'addJob',
254
+ export const addStandardJob = {
255
+ name: 'addStandardJob',
260
256
  content,
261
- keys: 9,
257
+ keys: 6,
262
258
  };
263
- //# sourceMappingURL=addJob-9.js.map
259
+ //# sourceMappingURL=addStandardJob-6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addStandardJob-6.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Pf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -1,4 +1,7 @@
1
- export * from './addJob-9';
1
+ export * from './addDelayedJob-7';
2
+ export * from './addParentJob-4';
3
+ export * from './addPrioritizedJob-8';
4
+ export * from './addStandardJob-6';
2
5
  export * from './changeDelay-3';
3
6
  export * from './changePriority-5';
4
7
  export * from './cleanJobsInSet-2';
@@ -1,4 +1,7 @@
1
- export * from './addJob-9';
1
+ export * from './addDelayedJob-7';
2
+ export * from './addParentJob-4';
3
+ export * from './addPrioritizedJob-8';
4
+ export * from './addStandardJob-6';
2
5
  export * from './changeDelay-3';
3
6
  export * from './changePriority-5';
4
7
  export * from './cleanJobsInSet-2';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}