bullmq 5.42.0 → 5.43.1

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 (48) hide show
  1. package/dist/cjs/classes/job.js +15 -23
  2. package/dist/cjs/classes/job.js.map +1 -1
  3. package/dist/cjs/classes/scripts.js +19 -0
  4. package/dist/cjs/classes/scripts.js.map +1 -1
  5. package/dist/cjs/commands/{addJobScheduler-10.lua → addJobScheduler-11.lua} +4 -2
  6. package/dist/cjs/commands/getDependencyCounts-4.lua +31 -0
  7. package/dist/cjs/commands/includes/addJobFromScheduler.lua +9 -13
  8. package/dist/cjs/commands/updateJobScheduler-12.lua +84 -0
  9. package/dist/cjs/scripts/{addJobScheduler-10.js → addJobScheduler-11.js} +41 -45
  10. package/dist/cjs/scripts/{addJobScheduler-10.js.map → addJobScheduler-11.js.map} +1 -1
  11. package/dist/cjs/scripts/getDependencyCounts-4.js +37 -0
  12. package/dist/cjs/scripts/getDependencyCounts-4.js.map +1 -0
  13. package/dist/cjs/scripts/index.js +3 -2
  14. package/dist/cjs/scripts/index.js.map +1 -1
  15. package/dist/cjs/scripts/{updateJobScheduler-11.js → updateJobScheduler-12.js} +63 -41
  16. package/dist/cjs/scripts/updateJobScheduler-12.js.map +1 -0
  17. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  18. package/dist/cjs/version.js +1 -1
  19. package/dist/esm/classes/job.d.ts +5 -1
  20. package/dist/esm/classes/job.js +15 -23
  21. package/dist/esm/classes/job.js.map +1 -1
  22. package/dist/esm/classes/scripts.d.ts +2 -0
  23. package/dist/esm/classes/scripts.js +19 -0
  24. package/dist/esm/classes/scripts.js.map +1 -1
  25. package/dist/esm/commands/{addJobScheduler-10.lua → addJobScheduler-11.lua} +4 -2
  26. package/dist/esm/commands/getDependencyCounts-4.lua +31 -0
  27. package/dist/esm/commands/includes/addJobFromScheduler.lua +9 -13
  28. package/dist/esm/commands/updateJobScheduler-12.lua +84 -0
  29. package/dist/esm/scripts/{addJobScheduler-10.js → addJobScheduler-11.js} +41 -45
  30. package/dist/esm/scripts/{addJobScheduler-10.js.map → addJobScheduler-11.js.map} +1 -1
  31. package/dist/esm/scripts/getDependencyCounts-4.d.ts +5 -0
  32. package/dist/esm/scripts/getDependencyCounts-4.js +34 -0
  33. package/dist/esm/scripts/getDependencyCounts-4.js.map +1 -0
  34. package/dist/esm/scripts/index.d.ts +3 -2
  35. package/dist/esm/scripts/index.js +3 -2
  36. package/dist/esm/scripts/index.js.map +1 -1
  37. package/dist/esm/scripts/{updateJobScheduler-11.js → updateJobScheduler-12.js} +63 -41
  38. package/dist/esm/scripts/updateJobScheduler-12.js.map +1 -0
  39. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  40. package/dist/esm/version.d.ts +1 -1
  41. package/dist/esm/version.js +1 -1
  42. package/package.json +1 -1
  43. package/dist/cjs/commands/updateJobScheduler-11.lua +0 -84
  44. package/dist/cjs/scripts/updateJobScheduler-11.js.map +0 -1
  45. package/dist/esm/commands/updateJobScheduler-11.lua +0 -84
  46. package/dist/esm/scripts/updateJobScheduler-11.js.map +0 -1
  47. /package/dist/esm/scripts/{addJobScheduler-10.d.ts → addJobScheduler-11.d.ts} +0 -0
  48. /package/dist/esm/scripts/{updateJobScheduler-11.d.ts → updateJobScheduler-12.d.ts} +0 -0
@@ -14,6 +14,7 @@ const content = `--[[
14
14
  KEYS[8] 'id' key
15
15
  KEYS[9] 'events' key
16
16
  KEYS[10] 'pc' priority counter
17
+ KEYS[11] 'active' key
17
18
  ARGV[1] next milliseconds
18
19
  ARGV[2] msgpacked options
19
20
  [1] name
@@ -173,29 +174,51 @@ local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
173
174
  rcall("XADD", eventsKey, "*", "event", "added", "jobId", jobId, "name", name)
174
175
  return delay, priority
175
176
  end
176
- local function addJobFromScheduler(jobKey, jobId, rawOpts, waitKey, pausedKey, metaKey, prioritizedKey,
177
- priorityCounter, delayedKey, markerKey, eventsKey, name, maxEvents, timestamp, data, jobSchedulerId)
177
+ --[[
178
+ Function to check for the meta.paused key to decide if we are paused or not
179
+ (since an empty list and !EXISTS are not really the same).
180
+ ]]
181
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
182
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
183
+ if queueAttributes[1] then
184
+ return pausedKey, true
185
+ else
186
+ if queueAttributes[2] then
187
+ local activeCount = rcall("LLEN", activeKey)
188
+ if activeCount >= tonumber(queueAttributes[2]) then
189
+ return waitKey, true
190
+ else
191
+ return waitKey, false
192
+ end
193
+ end
194
+ end
195
+ return waitKey, false
196
+ end
197
+ --[[
198
+ Function to add job in target list and add marker if needed.
199
+ ]]
200
+ -- Includes
201
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
202
+ rcall(pushCmd, targetKey, jobId)
203
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
204
+ end
205
+ local function addJobFromScheduler(jobKey, jobId, rawOpts, waitKey, pausedKey, activeKey, metaKey,
206
+ prioritizedKey, priorityCounter, delayedKey, markerKey, eventsKey, name, maxEvents, timestamp,
207
+ data, jobSchedulerId)
178
208
  local opts = cmsgpack.unpack(rawOpts)
179
209
  local delay, priority = storeJob(eventsKey, jobKey, jobId, name, data,
180
210
  opts, timestamp, nil, nil, jobSchedulerId)
181
211
  if delay ~= 0 then
182
212
  addDelayedJob(jobId, delayedKey, eventsKey, timestamp, maxEvents, markerKey, delay)
183
213
  else
184
- local isPaused = isQueuePaused(metaKey)
214
+ local target, isPausedOrMaxed = getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
185
215
  -- Standard or priority add
186
216
  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)
191
- else
192
- -- LIFO or FIFO
193
- local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
194
- rcall(pushCmd, waitKey, jobId)
195
- end
217
+ local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
218
+ addJobInTargetList(target, markerKey, pushCmd, isPausedOrMaxed, jobId)
196
219
  else
197
220
  -- Priority add
198
- addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounter, isPaused)
221
+ addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounter, isPausedOrMaxed)
199
222
  end
200
223
  -- Emit waiting event
201
224
  rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting", "jobId", jobId)
@@ -239,14 +262,6 @@ end
239
262
  which requires code from "moveToFinished"
240
263
  ]]
241
264
  -- Includes
242
- --[[
243
- Function to add job in target list and add marker if needed.
244
- ]]
245
- -- Includes
246
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
247
- rcall(pushCmd, targetKey, jobId)
248
- addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
249
- end
250
265
  --[[
251
266
  Functions to destructure job key.
252
267
  Just a bit of warning, these functions may be a bit slow and affect performance significantly.
@@ -257,26 +272,6 @@ end
257
272
  local getJobKeyPrefix = function (jobKey, jobId)
258
273
  return string.sub(jobKey, 0, #jobKey - #jobId)
259
274
  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
280
275
  local function moveParentToWait(parentPrefix, parentId, emitEvent)
281
276
  local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
282
277
  parentPrefix .. "wait", parentPrefix .. "paused")
@@ -429,8 +424,9 @@ if rcall("EXISTS", nextDelayedJobKey) ~= 1 then
429
424
  local eventsKey = KEYS[9]
430
425
  local maxEvents = getOrSetMaxEvents(metaKey)
431
426
  rcall("INCR", KEYS[8])
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)
427
+ addJobFromScheduler(nextDelayedJobKey, nextDelayedJobId, ARGV[6], waitKey, pausedKey,
428
+ KEYS[11], metaKey, prioritizedKey, KEYS[10], delayedKey, KEYS[7], eventsKey,
429
+ schedulerOpts['name'], maxEvents, ARGV[7], ARGV[4], jobSchedulerId)
434
430
  if ARGV[9] ~= "" then
435
431
  rcall("HSET", ARGV[9], "nrjid", nextDelayedJobId)
436
432
  end
@@ -440,6 +436,6 @@ end
440
436
  exports.addJobScheduler = {
441
437
  name: 'addJobScheduler',
442
438
  content,
443
- keys: 10,
439
+ keys: 11,
444
440
  };
445
- //# sourceMappingURL=addJobScheduler-10.js.map
441
+ //# sourceMappingURL=addJobScheduler-11.js.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"addJobScheduler-11.js","sourceRoot":"","sources":["../../../src/scripts/addJobScheduler-11.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+af,CAAC;AACW,QAAA,eAAe,GAAG;IAC7B,IAAI,EAAE,iBAAiB;IACvB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDependencyCounts = void 0;
4
+ const content = `--[[
5
+ Get counts per child states
6
+ Input:
7
+ KEYS[1] processed key
8
+ KEYS[2] unprocessed key
9
+ KEYS[3] ignored key
10
+ KEYS[4] failed key
11
+ ARGV[1...] types
12
+ ]]
13
+ local rcall = redis.call;
14
+ local processedKey = KEYS[1]
15
+ local unprocessedKey = KEYS[2]
16
+ local ignoredKey = KEYS[3]
17
+ local failedKey = KEYS[4]
18
+ local results = {}
19
+ for i = 1, #ARGV do
20
+ if ARGV[i] == "processed" then
21
+ results[#results+1] = rcall("HLEN", processedKey)
22
+ elseif ARGV[i] == "unprocessed" then
23
+ results[#results+1] = rcall("SCARD", unprocessedKey)
24
+ elseif ARGV[i] == "ignored" then
25
+ results[#results+1] = rcall("HLEN", ignoredKey)
26
+ else
27
+ results[#results+1] = rcall("ZCARD", failedKey)
28
+ end
29
+ end
30
+ return results
31
+ `;
32
+ exports.getDependencyCounts = {
33
+ name: 'getDependencyCounts',
34
+ content,
35
+ keys: 4,
36
+ };
37
+ //# sourceMappingURL=getDependencyCounts-4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDependencyCounts-4.js","sourceRoot":"","sources":["../../../src/scripts/getDependencyCounts-4.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2Bf,CAAC;AACW,QAAA,mBAAmB,GAAG;IACjC,IAAI,EAAE,qBAAqB;IAC3B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./addDelayedJob-6"), exports);
5
- tslib_1.__exportStar(require("./addJobScheduler-10"), exports);
5
+ tslib_1.__exportStar(require("./addJobScheduler-11"), exports);
6
6
  tslib_1.__exportStar(require("./addLog-2"), exports);
7
7
  tslib_1.__exportStar(require("./addParentJob-4"), exports);
8
8
  tslib_1.__exportStar(require("./addPrioritizedJob-8"), exports);
@@ -16,6 +16,7 @@ tslib_1.__exportStar(require("./extendLock-2"), exports);
16
16
  tslib_1.__exportStar(require("./extendLocks-1"), exports);
17
17
  tslib_1.__exportStar(require("./getCounts-1"), exports);
18
18
  tslib_1.__exportStar(require("./getCountsPerPriority-4"), exports);
19
+ tslib_1.__exportStar(require("./getDependencyCounts-4"), exports);
19
20
  tslib_1.__exportStar(require("./getJobScheduler-1"), exports);
20
21
  tslib_1.__exportStar(require("./getRanges-1"), exports);
21
22
  tslib_1.__exportStar(require("./getRateLimitTtl-1"), exports);
@@ -44,7 +45,7 @@ tslib_1.__exportStar(require("./reprocessJob-8"), exports);
44
45
  tslib_1.__exportStar(require("./retryJob-11"), exports);
45
46
  tslib_1.__exportStar(require("./saveStacktrace-1"), exports);
46
47
  tslib_1.__exportStar(require("./updateData-1"), exports);
47
- tslib_1.__exportStar(require("./updateJobScheduler-11"), exports);
48
+ tslib_1.__exportStar(require("./updateJobScheduler-12"), exports);
48
49
  tslib_1.__exportStar(require("./updateProgress-3"), exports);
49
50
  tslib_1.__exportStar(require("./updateRepeatableJobMillis-1"), exports);
50
51
  //# 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,kEAAwC;AACxC,6DAAmC;AACnC,wEAA8C"}
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,kEAAwC;AACxC,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"}
@@ -15,6 +15,7 @@ const content = `--[[
15
15
  KEYS[9] events stream key
16
16
  KEYS[10] 'pc' priority counter
17
17
  KEYS[11] producer key
18
+ KEYS[12] 'active' key
18
19
  ARGV[1] next milliseconds
19
20
  ARGV[2] jobs scheduler id
20
21
  ARGV[3] Json stringified delayed data
@@ -24,8 +25,7 @@ const content = `--[[
24
25
  ARGV[7] producer id
25
26
  Output:
26
27
  next delayed job id - OK
27
- ]]
28
- local rcall = redis.call
28
+ ]] local rcall = redis.call
29
29
  local repeatKey = KEYS[1]
30
30
  local delayedKey = KEYS[2]
31
31
  local waitKey = KEYS[3]
@@ -168,29 +168,51 @@ local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
168
168
  rcall("XADD", eventsKey, "*", "event", "added", "jobId", jobId, "name", name)
169
169
  return delay, priority
170
170
  end
171
- local function addJobFromScheduler(jobKey, jobId, rawOpts, waitKey, pausedKey, metaKey, prioritizedKey,
172
- priorityCounter, delayedKey, markerKey, eventsKey, name, maxEvents, timestamp, data, jobSchedulerId)
171
+ --[[
172
+ Function to check for the meta.paused key to decide if we are paused or not
173
+ (since an empty list and !EXISTS are not really the same).
174
+ ]]
175
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
176
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
177
+ if queueAttributes[1] then
178
+ return pausedKey, true
179
+ else
180
+ if queueAttributes[2] then
181
+ local activeCount = rcall("LLEN", activeKey)
182
+ if activeCount >= tonumber(queueAttributes[2]) then
183
+ return waitKey, true
184
+ else
185
+ return waitKey, false
186
+ end
187
+ end
188
+ end
189
+ return waitKey, false
190
+ end
191
+ --[[
192
+ Function to add job in target list and add marker if needed.
193
+ ]]
194
+ -- Includes
195
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
196
+ rcall(pushCmd, targetKey, jobId)
197
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
198
+ end
199
+ local function addJobFromScheduler(jobKey, jobId, rawOpts, waitKey, pausedKey, activeKey, metaKey,
200
+ prioritizedKey, priorityCounter, delayedKey, markerKey, eventsKey, name, maxEvents, timestamp,
201
+ data, jobSchedulerId)
173
202
  local opts = cmsgpack.unpack(rawOpts)
174
203
  local delay, priority = storeJob(eventsKey, jobKey, jobId, name, data,
175
204
  opts, timestamp, nil, nil, jobSchedulerId)
176
205
  if delay ~= 0 then
177
206
  addDelayedJob(jobId, delayedKey, eventsKey, timestamp, maxEvents, markerKey, delay)
178
207
  else
179
- local isPaused = isQueuePaused(metaKey)
208
+ local target, isPausedOrMaxed = getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
180
209
  -- Standard or priority add
181
210
  if priority == 0 then
182
- if isPaused then
183
- -- LIFO or FIFO
184
- local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
185
- rcall(pushCmd, pausedKey, jobId)
186
- else
187
- -- LIFO or FIFO
188
- local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
189
- rcall(pushCmd, waitKey, jobId)
190
- end
211
+ local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
212
+ addJobInTargetList(target, markerKey, pushCmd, isPausedOrMaxed, jobId)
191
213
  else
192
214
  -- Priority add
193
- addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounter, isPaused)
215
+ addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounter, isPausedOrMaxed)
194
216
  end
195
217
  -- Emit waiting event
196
218
  rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting", "jobId", jobId)
@@ -208,39 +230,39 @@ local function getOrSetMaxEvents(metaKey)
208
230
  return maxEvents
209
231
  end
210
232
  local schedulerKey = repeatKey .. ":" .. jobSchedulerId
211
- local nextDelayedJobId = "repeat:" .. jobSchedulerId .. ":" .. nextMillis
212
- local nextDelayedJobKey = schedulerKey .. ":" .. nextMillis
233
+ local nextDelayedJobId = "repeat:" .. jobSchedulerId .. ":" .. nextMillis
234
+ local nextDelayedJobKey = schedulerKey .. ":" .. nextMillis
213
235
  -- Validate that scheduler exists.
214
236
  local prevMillis = rcall("ZSCORE", repeatKey, jobSchedulerId)
215
237
  if prevMillis ~= false then
216
- local currentDelayedJobId = "repeat:" .. jobSchedulerId .. ":" .. prevMillis
217
- if producerId == currentDelayedJobId and rcall("EXISTS", nextDelayedJobKey) ~= 1 then
218
- local schedulerAttributes = rcall("HMGET", schedulerKey, "name", "data")
219
- rcall("ZADD", repeatKey, nextMillis, jobSchedulerId)
220
- rcall("HINCRBY", schedulerKey, "ic", 1)
221
- local eventsKey = KEYS[9]
222
- local maxEvents = getOrSetMaxEvents(metaKey)
223
- rcall("INCR", KEYS[8])
224
- -- TODO: remove this workaround in next breaking change,
225
- -- all job-schedulers must save job data
226
- local templateData = schedulerAttributes[2] or ARGV[3]
227
- if templateData and templateData ~= '{}' then
228
- rcall("HSET", schedulerKey, "data", templateData)
238
+ local currentDelayedJobId = "repeat:" .. jobSchedulerId .. ":" .. prevMillis
239
+ if producerId == currentDelayedJobId and rcall("EXISTS", nextDelayedJobKey) ~= 1 then
240
+ local schedulerAttributes = rcall("HMGET", schedulerKey, "name", "data")
241
+ rcall("ZADD", repeatKey, nextMillis, jobSchedulerId)
242
+ rcall("HINCRBY", schedulerKey, "ic", 1)
243
+ local eventsKey = KEYS[9]
244
+ local maxEvents = getOrSetMaxEvents(metaKey)
245
+ rcall("INCR", KEYS[8])
246
+ -- TODO: remove this workaround in next breaking change,
247
+ -- all job-schedulers must save job data
248
+ local templateData = schedulerAttributes[2] or ARGV[3]
249
+ if templateData and templateData ~= '{}' then
250
+ rcall("HSET", schedulerKey, "data", templateData)
251
+ end
252
+ addJobFromScheduler(nextDelayedJobKey, nextDelayedJobId, ARGV[4], waitKey, pausedKey,
253
+ KEYS[12], metaKey, prioritizedKey, KEYS[10], delayedKey, KEYS[7], eventsKey,
254
+ schedulerAttributes[1], maxEvents, ARGV[5], templateData or '{}', jobSchedulerId)
255
+ -- TODO: remove this workaround in next breaking change
256
+ if KEYS[11] ~= "" then
257
+ rcall("HSET", KEYS[11], "nrjid", nextDelayedJobId)
258
+ end
259
+ return nextDelayedJobId .. "" -- convert to string
229
260
  end
230
- addJobFromScheduler(nextDelayedJobKey, nextDelayedJobId, ARGV[4], waitKey, pausedKey, metaKey, prioritizedKey,
231
- KEYS[10], delayedKey, KEYS[7], eventsKey, schedulerAttributes[1], maxEvents, ARGV[5],
232
- templateData or '{}', jobSchedulerId)
233
- -- TODO: remove this workaround in next breaking change
234
- if KEYS[11] ~= "" then
235
- rcall("HSET", KEYS[11], "nrjid", nextDelayedJobId)
236
- end
237
- return nextDelayedJobId .. "" -- convert to string
238
- end
239
261
  end
240
262
  `;
241
263
  exports.updateJobScheduler = {
242
264
  name: 'updateJobScheduler',
243
265
  content,
244
- keys: 11,
266
+ keys: 12,
245
267
  };
246
- //# sourceMappingURL=updateJobScheduler-11.js.map
268
+ //# sourceMappingURL=updateJobScheduler-12.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateJobScheduler-12.js","sourceRoot":"","sources":["../../../src/scripts/updateJobScheduler-12.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkQf,CAAC;AACW,QAAA,kBAAkB,GAAG;IAChC,IAAI,EAAE,oBAAoB;IAC1B,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}