bullmq 3.5.4 → 3.5.6

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 (77) hide show
  1. package/dist/cjs/classes/backoffs.d.ts +2 -3
  2. package/dist/cjs/classes/backoffs.js.map +1 -1
  3. package/dist/cjs/classes/job.d.ts +6 -24
  4. package/dist/cjs/classes/job.js.map +1 -1
  5. package/dist/cjs/classes/queue-base.d.ts +2 -1
  6. package/dist/cjs/classes/queue-base.js.map +1 -1
  7. package/dist/cjs/classes/queue.d.ts +2 -2
  8. package/dist/cjs/classes/queue.js.map +1 -1
  9. package/dist/cjs/classes/scripts.d.ts +9 -17
  10. package/dist/cjs/classes/scripts.js.map +1 -1
  11. package/dist/cjs/classes/worker.js +11 -4
  12. package/dist/cjs/classes/worker.js.map +1 -1
  13. package/dist/cjs/commands/addJob-8.lua +2 -7
  14. package/dist/cjs/commands/includes/addDelayMarkerIfNeeded.lua +15 -0
  15. package/dist/cjs/commands/includes/updateParentDepsIfNeeded.lua +2 -6
  16. package/dist/cjs/commands/moveToActive-9.lua +1 -1
  17. package/dist/cjs/commands/moveToDelayed-8.lua +6 -9
  18. package/dist/cjs/interfaces/index.d.ts +1 -0
  19. package/dist/cjs/interfaces/index.js +1 -0
  20. package/dist/cjs/interfaces/index.js.map +1 -1
  21. package/dist/cjs/interfaces/minimal-job.d.ts +129 -0
  22. package/dist/cjs/interfaces/minimal-job.js +3 -0
  23. package/dist/cjs/interfaces/minimal-job.js.map +1 -0
  24. package/dist/cjs/interfaces/parent.d.ts +5 -0
  25. package/dist/cjs/scripts/addJob-8.js +27 -26
  26. package/dist/cjs/scripts/addJob-8.js.map +1 -1
  27. package/dist/cjs/scripts/moveToActive-9.js +1 -1
  28. package/dist/cjs/scripts/moveToDelayed-8.js +39 -32
  29. package/dist/cjs/scripts/moveToDelayed-8.js.map +1 -1
  30. package/dist/cjs/scripts/moveToFinished-12.js +13 -6
  31. package/dist/cjs/scripts/moveToFinished-12.js.map +1 -1
  32. package/dist/cjs/types/backoff-strategy.d.ts +2 -2
  33. package/dist/cjs/types/index.d.ts +1 -0
  34. package/dist/cjs/types/index.js +1 -0
  35. package/dist/cjs/types/index.js.map +1 -1
  36. package/dist/cjs/types/minimal-queue.d.ts +2 -0
  37. package/dist/cjs/types/minimal-queue.js +3 -0
  38. package/dist/cjs/types/minimal-queue.js.map +1 -0
  39. package/dist/esm/classes/backoffs.d.ts +2 -3
  40. package/dist/esm/classes/backoffs.js.map +1 -1
  41. package/dist/esm/classes/job.d.ts +6 -24
  42. package/dist/esm/classes/job.js.map +1 -1
  43. package/dist/esm/classes/queue-base.d.ts +2 -1
  44. package/dist/esm/classes/queue-base.js.map +1 -1
  45. package/dist/esm/classes/queue.d.ts +2 -2
  46. package/dist/esm/classes/queue.js.map +1 -1
  47. package/dist/esm/classes/scripts.d.ts +9 -17
  48. package/dist/esm/classes/scripts.js.map +1 -1
  49. package/dist/esm/classes/worker.js +11 -4
  50. package/dist/esm/classes/worker.js.map +1 -1
  51. package/dist/esm/commands/addJob-8.lua +2 -7
  52. package/dist/esm/commands/includes/addDelayMarkerIfNeeded.lua +15 -0
  53. package/dist/esm/commands/includes/updateParentDepsIfNeeded.lua +2 -6
  54. package/dist/esm/commands/moveToActive-9.lua +1 -1
  55. package/dist/esm/commands/moveToDelayed-8.lua +6 -9
  56. package/dist/esm/interfaces/index.d.ts +1 -0
  57. package/dist/esm/interfaces/index.js +1 -0
  58. package/dist/esm/interfaces/index.js.map +1 -1
  59. package/dist/esm/interfaces/minimal-job.d.ts +129 -0
  60. package/dist/esm/interfaces/minimal-job.js +2 -0
  61. package/dist/esm/interfaces/minimal-job.js.map +1 -0
  62. package/dist/esm/interfaces/parent.d.ts +5 -0
  63. package/dist/esm/scripts/addJob-8.js +27 -26
  64. package/dist/esm/scripts/addJob-8.js.map +1 -1
  65. package/dist/esm/scripts/moveToActive-9.js +1 -1
  66. package/dist/esm/scripts/moveToDelayed-8.js +39 -32
  67. package/dist/esm/scripts/moveToDelayed-8.js.map +1 -1
  68. package/dist/esm/scripts/moveToFinished-12.js +13 -6
  69. package/dist/esm/scripts/moveToFinished-12.js.map +1 -1
  70. package/dist/esm/types/backoff-strategy.d.ts +2 -2
  71. package/dist/esm/types/index.d.ts +1 -0
  72. package/dist/esm/types/index.js +1 -0
  73. package/dist/esm/types/index.js.map +1 -1
  74. package/dist/esm/types/minimal-queue.d.ts +2 -0
  75. package/dist/esm/types/minimal-queue.js +2 -0
  76. package/dist/esm/types/minimal-queue.js.map +1 -0
  77. package/package.json +3 -1
@@ -28,9 +28,10 @@
28
28
  local rcall = redis.call
29
29
 
30
30
  -- Includes
31
- --- @include "includes/promoteDelayedJobs"
31
+ --- @include "includes/addDelayMarkerIfNeeded"
32
32
  --- @include "includes/getTargetQueueList"
33
33
  --- @include "includes/getNextDelayedTimestamp"
34
+ --- @include "includes/promoteDelayedJobs"
34
35
 
35
36
  local jobKey = KEYS[5]
36
37
  if rcall("EXISTS", jobKey) == 1 then
@@ -54,17 +55,13 @@ if rcall("EXISTS", jobKey) == 1 then
54
55
  return -3
55
56
  end
56
57
 
58
+ rcall("ZADD", delayedKey, score, jobId)
59
+ rcall("XADD", KEYS[6], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp)
60
+
57
61
  -- Check if we need to push a marker job to wake up sleeping workers.
58
62
  local target = getTargetQueueList(KEYS[8], KEYS[1], KEYS[7])
59
- if rcall("LLEN", target) == 0 then
60
- local nextTimestamp = getNextDelayedTimestamp(delayedKey)
61
- if not nextTimestamp or (delayedTimestamp < nextTimestamp) then
62
- rcall("LPUSH", target, "0:" .. delayedTimestamp - tonumber(ARGV[2]))
63
- end
64
- end
63
+ addDelayMarkerIfNeeded(target, delayedKey)
65
64
 
66
- rcall("ZADD", delayedKey, score, jobId)
67
- rcall("XADD", KEYS[6], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp)
68
65
  return 0
69
66
  else
70
67
  return -1
@@ -10,6 +10,7 @@ export * from './job-json';
10
10
  export * from './keep-jobs';
11
11
  export * from './metrics-options';
12
12
  export * from './metrics';
13
+ export * from './minimal-job';
13
14
  export * from './parent-command';
14
15
  export * from './parent-message';
15
16
  export * from './parent';
@@ -13,6 +13,7 @@ tslib_1.__exportStar(require("./job-json"), exports);
13
13
  tslib_1.__exportStar(require("./keep-jobs"), exports);
14
14
  tslib_1.__exportStar(require("./metrics-options"), exports);
15
15
  tslib_1.__exportStar(require("./metrics"), exports);
16
+ tslib_1.__exportStar(require("./minimal-job"), exports);
16
17
  tslib_1.__exportStar(require("./parent-command"), exports);
17
18
  tslib_1.__exportStar(require("./parent-message"), exports);
18
19
  tslib_1.__exportStar(require("./parent"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,4DAAkC;AAClC,6DAAmC;AACnC,0DAAgC;AAChC,0DAAgC;AAChC,uDAA6B;AAC7B,qDAA2B;AAC3B,2DAAiC;AACjC,qDAA2B;AAC3B,sDAA4B;AAC5B,4DAAkC;AAClC,oDAA0B;AAC1B,2DAAiC;AACjC,2DAAiC;AACjC,mDAAyB;AACzB,0DAAgC;AAChC,iEAAuC;AACvC,0DAAgC;AAChC,0DAAgC;AAChC,2DAAiC;AACjC,oEAA0C;AAC1C,0DAAgC;AAChC,2DAAiC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,4DAAkC;AAClC,6DAAmC;AACnC,0DAAgC;AAChC,0DAAgC;AAChC,uDAA6B;AAC7B,qDAA2B;AAC3B,2DAAiC;AACjC,qDAA2B;AAC3B,sDAA4B;AAC5B,4DAAkC;AAClC,oDAA0B;AAC1B,wDAA8B;AAC9B,2DAAiC;AACjC,2DAAiC;AACjC,mDAAyB;AACzB,0DAAgC;AAChC,iEAAuC;AACvC,0DAAgC;AAChC,0DAAgC;AAChC,2DAAiC;AACjC,oEAA0C;AAC1C,0DAAgC;AAChC,2DAAiC"}
@@ -0,0 +1,129 @@
1
+ import { JobsOptions, JobJsonSandbox } from '../types';
2
+ import { JobJson } from './job-json';
3
+ import { ParentKeys } from './parent';
4
+ export type BulkJobOptions = Omit<JobsOptions, 'repeat'>;
5
+ export interface MoveToWaitingChildrenOpts {
6
+ child?: {
7
+ id: string;
8
+ queue: string;
9
+ };
10
+ }
11
+ export interface DependenciesOpts {
12
+ processed?: {
13
+ cursor?: number;
14
+ count?: number;
15
+ };
16
+ unprocessed?: {
17
+ cursor?: number;
18
+ count?: number;
19
+ };
20
+ }
21
+ /**
22
+ * MinimalJob
23
+ */
24
+ export interface MinimalJob<DataType = any, ReturnType = any, NameType extends string = string> {
25
+ /**
26
+ * The name of the Job
27
+ */
28
+ name: NameType;
29
+ /**
30
+ * The payload for this job.
31
+ */
32
+ data: DataType;
33
+ /**
34
+ * The options object for this job.
35
+ */
36
+ opts: JobsOptions;
37
+ id?: string;
38
+ /**
39
+ * The progress a job has performed so far.
40
+ * @defaultValue 0
41
+ */
42
+ progress: number | object;
43
+ /**
44
+ * The value returned by the processor when processing this job.
45
+ * @defaultValue null
46
+ */
47
+ returnvalue: ReturnType;
48
+ /**
49
+ * Stacktrace for the error (for failed jobs).
50
+ * @defaultValue null
51
+ */
52
+ stacktrace: string[];
53
+ /**
54
+ * An amount of milliseconds to wait until this job can be processed.
55
+ * @defaultValue 0
56
+ */
57
+ delay: number;
58
+ /**
59
+ * Timestamp when the job was created (unless overridden with job options).
60
+ */
61
+ timestamp: number;
62
+ /**
63
+ * Number of attempts after the job has failed.
64
+ * @defaultValue 0
65
+ */
66
+ attemptsMade: number;
67
+ /**
68
+ * Reason for failing.
69
+ */
70
+ failedReason: string;
71
+ /**
72
+ * Timestamp for when the job finished (completed or failed).
73
+ */
74
+ finishedOn?: number;
75
+ /**
76
+ * Timestamp for when the job was processed.
77
+ */
78
+ processedOn?: number;
79
+ /**
80
+ * Fully qualified key (including the queue prefix) pointing to the parent of this job.
81
+ */
82
+ parentKey?: string;
83
+ /**
84
+ * Object that contains parentId (id) and parent queueKey.
85
+ */
86
+ parent?: ParentKeys;
87
+ /**
88
+ * Base repeat job key.
89
+ */
90
+ repeatJobKey?: string;
91
+ /**
92
+ * Prepares a job to be serialized for storage in Redis.
93
+ * @returns
94
+ */
95
+ asJSON(): JobJson;
96
+ /**
97
+ * Prepares a job to be passed to Sandbox.
98
+ * @returns
99
+ */
100
+ asJSONSandbox(): JobJsonSandbox;
101
+ /**
102
+ * Updates a job's data
103
+ *
104
+ * @param data - the data that will replace the current jobs data.
105
+ */
106
+ update(data: DataType): Promise<void>;
107
+ /**
108
+ * Updates a job's progress
109
+ *
110
+ * @param progress - number or object to be saved as progress.
111
+ */
112
+ updateProgress(progress: number | object): Promise<void>;
113
+ /**
114
+ * Logs one row of log data.
115
+ *
116
+ * @param logRow - string with log data to be logged.
117
+ */
118
+ log(logRow: string): Promise<number>;
119
+ get queueName(): string;
120
+ /**
121
+ * @returns the prefix that is used.
122
+ */
123
+ get prefix(): string;
124
+ /**
125
+ * @returns it includes the prefix, the namespace separator :, and queue name.
126
+ * @see https://www.gnu.org/software/gawk/manual/html_node/Qualified-Names.html
127
+ */
128
+ get queueQualifiedName(): string;
129
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=minimal-job.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minimal-job.js","sourceRoot":"","sources":["../../../src/interfaces/minimal-job.ts"],"names":[],"mappings":""}
@@ -13,3 +13,8 @@ export interface ParentKeys {
13
13
  id: string;
14
14
  queueKey: string;
15
15
  }
16
+ export type ParentOpts = {
17
+ waitChildrenKey?: string;
18
+ parentDependenciesKey?: string;
19
+ parentKey?: string;
20
+ };
@@ -51,6 +51,31 @@ local repeatJobKey = args[9]
51
51
  local parent = args[8]
52
52
  local parentData
53
53
  -- Includes
54
+ --[[
55
+ Add delay marker if needed.
56
+ ]]
57
+ -- Includes
58
+ --[[
59
+ Function to return the next delayed job timestamp.
60
+ ]]
61
+ local function getNextDelayedTimestamp(delayedKey)
62
+ local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
63
+ if #result then
64
+ local nextTimestamp = tonumber(result[2])
65
+ if (nextTimestamp ~= nil) then
66
+ nextTimestamp = nextTimestamp / 0x1000
67
+ end
68
+ return nextTimestamp
69
+ end
70
+ end
71
+ local function addDelayMarkerIfNeeded(target, delayedKey)
72
+ if rcall("LLEN", target) == 0 then
73
+ local nextTimestamp = getNextDelayedTimestamp(delayedKey)
74
+ if nextTimestamp ~= nil then
75
+ rcall("LPUSH", target, "0:" .. nextTimestamp)
76
+ end
77
+ end
78
+ end
54
79
  --[[
55
80
  Function to add job considering priority.
56
81
  ]]
@@ -87,19 +112,6 @@ local function trimEvents(metaKey, eventStreamKey)
87
112
  rcall("XTRIM", eventStreamKey, "MAXLEN", "~", 10000)
88
113
  end
89
114
  end
90
- --[[
91
- Function to return the next delayed job timestamp.
92
- ]]
93
- local function getNextDelayedTimestamp(delayedKey)
94
- local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
95
- if #result then
96
- local nextTimestamp = tonumber(result[2])
97
- if (nextTimestamp ~= nil) then
98
- nextTimestamp = nextTimestamp / 0x1000
99
- end
100
- return nextTimestamp
101
- end
102
- end
103
115
  --[[
104
116
  Validate and move or add dependencies to parent.
105
117
  ]]
@@ -121,12 +133,7 @@ local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDepende
121
133
  local score = delayedTimestamp * 0x1000
122
134
  local parentDelayedKey = parentQueueKey .. ":delayed"
123
135
  rcall("ZADD", parentDelayedKey, score, parentId)
124
- if rcall("LLEN", parentTarget) == 0 then
125
- local nextTimestamp = getNextDelayedTimestamp(parentDelayedKey)
126
- if not nextTimestamp or (delayedTimestamp <= nextTimestamp) then
127
- rcall("LPUSH", parentTarget, "0:" .. delayedTimestamp - tonumber(timestamp))
128
- end
129
- end
136
+ addDelayMarkerIfNeeded(parentTarget, parentDelayedKey)
130
137
  -- Standard or priority add
131
138
  elseif priority == 0 then
132
139
  rcall("RPUSH", parentTarget, parentId)
@@ -203,13 +210,7 @@ elseif (delayedTimestamp ~= 0) then
203
210
  -- If wait list is empty, and this delayed job is the next one to be processed,
204
211
  -- then we need to signal the workers by adding a dummy job (jobId 0:delay) to the wait list.
205
212
  local target = getTargetQueueList(KEYS[3], KEYS[1], KEYS[2])
206
- if rcall("LLEN", target) == 0 then
207
- local nextTimestamp = getNextDelayedTimestamp(KEYS[5])
208
- if not nextTimestamp or (delayedTimestamp < nextTimestamp) then
209
- local delay = delayedTimestamp - tonumber(timestamp)
210
- rcall("LPUSH", target, "0:" .. delay)
211
- end
212
- end
213
+ addDelayMarkerIfNeeded(target, KEYS[5])
213
214
  else
214
215
  local target = getTargetQueueList(KEYS[3], KEYS[1], KEYS[2])
215
216
  -- Standard or priority add
@@ -1 +1 @@
1
- {"version":3,"file":"addJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addJob-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsOf,CAAC;AACW,QAAA,MAAM,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"addJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addJob-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuOf,CAAC;AACW,QAAA,MAAM,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -199,7 +199,7 @@ end
199
199
  -- Return the timestamp for the next delayed job if any.
200
200
  local nextTimestamp = getNextDelayedTimestamp(KEYS[7])
201
201
  if (nextTimestamp ~= nil) then
202
- return { 0, 0, 0, nextTimestamp - tonumber(ARGV[2])}
202
+ return { 0, 0, 0, nextTimestamp}
203
203
  end
204
204
  `;
205
205
  exports.moveToActive = {
@@ -26,6 +26,42 @@ const content = `--[[
26
26
  ]]
27
27
  local rcall = redis.call
28
28
  -- Includes
29
+ --[[
30
+ Add delay marker if needed.
31
+ ]]
32
+ -- Includes
33
+ --[[
34
+ Function to return the next delayed job timestamp.
35
+ ]]
36
+ local function getNextDelayedTimestamp(delayedKey)
37
+ local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
38
+ if #result then
39
+ local nextTimestamp = tonumber(result[2])
40
+ if (nextTimestamp ~= nil) then
41
+ nextTimestamp = nextTimestamp / 0x1000
42
+ end
43
+ return nextTimestamp
44
+ end
45
+ end
46
+ local function addDelayMarkerIfNeeded(target, delayedKey)
47
+ if rcall("LLEN", target) == 0 then
48
+ local nextTimestamp = getNextDelayedTimestamp(delayedKey)
49
+ if nextTimestamp ~= nil then
50
+ rcall("LPUSH", target, "0:" .. nextTimestamp)
51
+ end
52
+ end
53
+ end
54
+ --[[
55
+ Function to check for the meta.paused key to decide if we are paused or not
56
+ (since an empty list and !EXISTS are not really the same).
57
+ ]]
58
+ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
59
+ if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
60
+ return waitKey
61
+ else
62
+ return pausedKey
63
+ end
64
+ end
29
65
  --[[
30
66
  Updates the delay set, by moving delayed jobs that should
31
67
  be processed now to "wait".
@@ -48,17 +84,6 @@ local function addJobWithPriority(priorityKey, priority, targetKey, jobId)
48
84
  rcall("RPUSH", targetKey, jobId)
49
85
  end
50
86
  end
51
- --[[
52
- Function to check for the meta.paused key to decide if we are paused or not
53
- (since an empty list and !EXISTS are not really the same).
54
- ]]
55
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
56
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
57
- return waitKey
58
- else
59
- return pausedKey
60
- end
61
- end
62
87
  -- Try to get as much as 1000 jobs at once
63
88
  local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
64
89
  metaKey, eventStreamKey, prefix, timestamp)
@@ -83,19 +108,6 @@ local function promoteDelayedJobs(delayedKey, waitKey, priorityKey, pausedKey,
83
108
  end
84
109
  end
85
110
  end
86
- --[[
87
- Function to return the next delayed job timestamp.
88
- ]]
89
- local function getNextDelayedTimestamp(delayedKey)
90
- local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
91
- if #result then
92
- local nextTimestamp = tonumber(result[2])
93
- if (nextTimestamp ~= nil) then
94
- nextTimestamp = nextTimestamp / 0x1000
95
- end
96
- return nextTimestamp
97
- end
98
- end
99
111
  local jobKey = KEYS[5]
100
112
  if rcall("EXISTS", jobKey) == 1 then
101
113
  local delayedKey = KEYS[4]
@@ -114,16 +126,11 @@ if rcall("EXISTS", jobKey) == 1 then
114
126
  if (numRemovedElements < 1) then
115
127
  return -3
116
128
  end
117
- -- Check if we need to push a marker job to wake up sleeping workers.
118
- local target = getTargetQueueList(KEYS[8], KEYS[1], KEYS[7])
119
- if rcall("LLEN", target) == 0 then
120
- local nextTimestamp = getNextDelayedTimestamp(delayedKey)
121
- if not nextTimestamp or (delayedTimestamp < nextTimestamp) then
122
- rcall("LPUSH", target, "0:" .. delayedTimestamp - tonumber(ARGV[2]))
123
- end
124
- end
125
129
  rcall("ZADD", delayedKey, score, jobId)
126
130
  rcall("XADD", KEYS[6], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp)
131
+ -- Check if we need to push a marker job to wake up sleeping workers.
132
+ local target = getTargetQueueList(KEYS[8], KEYS[1], KEYS[7])
133
+ addDelayMarkerIfNeeded(target, delayedKey)
127
134
  return 0
128
135
  else
129
136
  return -1
@@ -1 +1 @@
1
- {"version":3,"file":"moveToDelayed-8.js","sourceRoot":"","sources":["../../../src/scripts/moveToDelayed-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Hf,CAAC;AACW,QAAA,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"moveToDelayed-8.js","sourceRoot":"","sources":["../../../src/scripts/moveToDelayed-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsIf,CAAC;AACW,QAAA,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -379,6 +379,18 @@ end
379
379
  Validate and move or add dependencies to parent.
380
380
  ]]
381
381
  -- Includes
382
+ --[[
383
+ Add delay marker if needed.
384
+ ]]
385
+ -- Includes
386
+ local function addDelayMarkerIfNeeded(target, delayedKey)
387
+ if rcall("LLEN", target) == 0 then
388
+ local nextTimestamp = getNextDelayedTimestamp(delayedKey)
389
+ if nextTimestamp ~= nil then
390
+ rcall("LPUSH", target, "0:" .. nextTimestamp)
391
+ end
392
+ end
393
+ end
382
394
  local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
383
395
  parentId, jobIdKey, returnvalue, timestamp )
384
396
  local processedSet = parentKey .. ":processed"
@@ -396,12 +408,7 @@ local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDepende
396
408
  local score = delayedTimestamp * 0x1000
397
409
  local parentDelayedKey = parentQueueKey .. ":delayed"
398
410
  rcall("ZADD", parentDelayedKey, score, parentId)
399
- if rcall("LLEN", parentTarget) == 0 then
400
- local nextTimestamp = getNextDelayedTimestamp(parentDelayedKey)
401
- if not nextTimestamp or (delayedTimestamp <= nextTimestamp) then
402
- rcall("LPUSH", parentTarget, "0:" .. delayedTimestamp - tonumber(timestamp))
403
- end
404
- end
411
+ addDelayMarkerIfNeeded(parentTarget, parentDelayedKey)
405
412
  -- Standard or priority add
406
413
  elseif priority == 0 then
407
414
  rcall("RPUSH", parentTarget, parentId)
@@ -1 +1 @@
1
- {"version":3,"file":"moveToFinished-12.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-12.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;CAqjBf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
@@ -1,2 +1,2 @@
1
- import { Job } from '../classes/job';
2
- export type BackoffStrategy = (attemptsMade?: number, type?: string, err?: Error, job?: Job) => Promise<number> | number;
1
+ import { MinimalJob } from '../interfaces/minimal-job';
2
+ export type BackoffStrategy = (attemptsMade?: number, type?: string, err?: Error, job?: MinimalJob) => Promise<number> | number;
@@ -1,5 +1,6 @@
1
1
  export * from './backoff-strategy';
2
2
  export * from './finished-status';
3
+ export * from './minimal-queue';
3
4
  export * from './job-json-sandbox';
4
5
  export * from './job-options';
5
6
  export * from './job-type';
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./backoff-strategy"), exports);
5
5
  tslib_1.__exportStar(require("./finished-status"), exports);
6
+ tslib_1.__exportStar(require("./minimal-queue"), exports);
6
7
  tslib_1.__exportStar(require("./job-json-sandbox"), exports);
7
8
  tslib_1.__exportStar(require("./job-options"), exports);
8
9
  tslib_1.__exportStar(require("./job-type"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,4DAAkC;AAClC,6DAAmC;AACnC,wDAA8B;AAC9B,qDAA2B;AAC3B,4DAAkC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,4DAAkC;AAClC,0DAAgC;AAChC,6DAAmC;AACnC,wDAA8B;AAC9B,qDAA2B;AAC3B,4DAAkC"}
@@ -0,0 +1,2 @@
1
+ import { QueueBase } from '../classes/queue-base';
2
+ export type MinimalQueue = Pick<QueueBase, 'name' | 'client' | 'toKey' | 'keys' | 'opts' | 'closing' | 'waitUntilReady' | 'removeListener' | 'emit' | 'on' | 'redisVersion'>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=minimal-queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minimal-queue.js","sourceRoot":"","sources":["../../../src/types/minimal-queue.ts"],"names":[],"mappings":""}
@@ -1,5 +1,4 @@
1
- import { Job } from './job';
2
- import { BackoffOptions } from '../interfaces/backoff-options';
1
+ import { BackoffOptions, MinimalJob } from '../interfaces';
3
2
  import { BackoffStrategy } from '../types';
4
3
  interface BuiltInStrategies {
5
4
  [index: string]: (delay: number) => BackoffStrategy;
@@ -7,6 +6,6 @@ interface BuiltInStrategies {
7
6
  export declare class Backoffs {
8
7
  static builtinStrategies: BuiltInStrategies;
9
8
  static normalize(backoff: number | BackoffOptions): BackoffOptions;
10
- static calculate(backoff: BackoffOptions, attemptsMade: number, err: Error, job: Job, customStrategy?: BackoffStrategy): Promise<number> | number;
9
+ static calculate(backoff: BackoffOptions, attemptsMade: number, err: Error, job: MinimalJob, customStrategy?: BackoffStrategy): Promise<number> | number;
11
10
  }
12
11
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"backoffs.js","sourceRoot":"","sources":["../../../src/classes/backoffs.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,QAAQ;IAenB,MAAM,CAAC,SAAS,CAAC,OAAgC;QAC/C,IAAI,MAAM,CAAC,QAAQ,CAAS,OAAO,CAAC,EAAE;YACpC,OAAO;gBACL,IAAI,EAAE,OAAO;gBACb,KAAK,EAAU,OAAO;aACvB,CAAC;SACH;aAAM,IAAI,OAAO,EAAE;YAClB,OAAuB,OAAO,CAAC;SAChC;IACH,CAAC;IAED,MAAM,CAAC,SAAS,CACd,OAAuB,EACvB,YAAoB,EACpB,GAAU,EACV,GAAQ,EACR,cAAgC;QAEhC,IAAI,OAAO,EAAE;YACX,MAAM,QAAQ,GAAG,cAAc,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AAoB,EACpB,GAAU,EACV,GAAe,EACf,cAAgC;QAEhC,IAAI,OAAO,EAAE;YACX,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;YAEzD,OAAO,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;SACvD;IACH,CAAC;;AArCM,0BAAiB,GAAsB;IAC5C,KAAK,EAAE,UAAU,KAAa;QAC5B,OAAO;YACL,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;IACJ,CAAC;IAED,WAAW,EAAE,UAAU,KAAa;QAClC,OAAO,UAAU,YAAoB;YACnC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;QAC3D,CAAC,CAAC;IACJ,CAAC;CACF,CAAC;AA4BJ,SAAS,cAAc,CACrB,OAAuB,EACvB,cAA+B;IAE/B,IAAI,OAAO,CAAC,IAAI,IAAI,QAAQ,CAAC,iBAAiB,EAAE;QAC9C,OAAO,QAAQ,CAAC,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;KAChE;SAAM,IAAI,cAAc,EAAE;QACzB,OAAO,cAAc,CAAC;KACvB;SAAM;QACL,MAAM,IAAI,KAAK,CACb,4BAA4B,OAAO,CAAC,IAAI;kFACoC,CAC7E,CAAC;KACH;AACH,CAAC"}
@@ -1,25 +1,7 @@
1
1
  import { ChainableCommander } from 'ioredis';
2
- import { JobJson, JobJsonRaw, ParentKeys, RedisClient } from '../interfaces';
3
- import { FinishedStatus, JobsOptions, JobState, JobJsonSandbox } from '../types';
4
- import { QueueEvents } from './queue-events';
5
- import { MinimalQueue, ParentOpts, Scripts } from './scripts';
6
- export type BulkJobOptions = Omit<JobsOptions, 'repeat'>;
7
- export interface MoveToWaitingChildrenOpts {
8
- child?: {
9
- id: string;
10
- queue: string;
11
- };
12
- }
13
- export interface DependenciesOpts {
14
- processed?: {
15
- cursor?: number;
16
- count?: number;
17
- };
18
- unprocessed?: {
19
- cursor?: number;
20
- count?: number;
21
- };
22
- }
2
+ import { BulkJobOptions, DependenciesOpts, JobJson, JobJsonRaw, MinimalJob, MoveToWaitingChildrenOpts, ParentKeys, ParentOpts, RedisClient } from '../interfaces';
3
+ import { FinishedStatus, JobsOptions, JobState, JobJsonSandbox, MinimalQueue } from '../types';
4
+ import { Scripts } from './scripts';
23
5
  /**
24
6
  * Job
25
7
  *
@@ -30,7 +12,7 @@ export interface DependenciesOpts {
30
12
  *
31
13
  * @class Job
32
14
  */
33
- export declare class Job<DataType = any, ReturnType = any, NameType extends string = string> {
15
+ export declare class Job<DataType = any, ReturnType = any, NameType extends string = string> implements MinimalJob<DataType, ReturnType, NameType> {
34
16
  protected queue: MinimalQueue;
35
17
  /**
36
18
  * The name of the Job
@@ -154,7 +136,7 @@ export declare class Job<DataType = any, ReturnType = any, NameType extends stri
154
136
  * @returns
155
137
  */
156
138
  static fromId<T = any, R = any, N extends string = string>(queue: MinimalQueue, jobId: string): Promise<Job<T, R, N> | undefined>;
157
- toJSON(): Omit<this, "toJSON" | "scripts" | "prefix" | "addJob" | "changeDelay" | "extendLock" | "getState" | "moveToDelayed" | "moveToWaitingChildren" | "promote" | "updateProgress" | "discard" | "queue" | "asJSON" | "asJSONSandbox" | "update" | "log" | "remove" | "moveToCompleted" | "moveToFailed" | "isCompleted" | "isFailed" | "isDelayed" | "isWaitingChildren" | "isActive" | "isWaiting" | "queueName" | "queueQualifiedName" | "getChildrenValues" | "getDependencies" | "getDependenciesCount" | "waitUntilFinished" | "retry">;
139
+ toJSON(): Omit<this, "toJSON" | "scripts" | "addJob" | "changeDelay" | "extendLock" | "getState" | "moveToDelayed" | "moveToWaitingChildren" | "promote" | "updateProgress" | "discard" | "queue" | "asJSON" | "asJSONSandbox" | "update" | "log" | "remove" | "moveToCompleted" | "moveToFailed" | "isCompleted" | "isFailed" | "isDelayed" | "isWaitingChildren" | "isActive" | "isWaiting" | "queueName" | "prefix" | "queueQualifiedName" | "getChildrenValues" | "getDependencies" | "getDependenciesCount" | "waitUntilFinished" | "retry">;
158
140
  /**
159
141
  * Prepares a job to be serialized for storage in Redis.
160
142
  * @returns
@@ -305,7 +287,7 @@ export declare class Job<DataType = any, ReturnType = any, NameType extends stri
305
287
  * @param queueEvents - Instance of QueueEvents.
306
288
  * @param ttl - Time in milliseconds to wait for job to finish before timing out.
307
289
  */
308
- waitUntilFinished(queueEvents: QueueEvents, ttl?: number): Promise<ReturnType>;
290
+ waitUntilFinished(queueEvents: MinimalQueue, ttl?: number): Promise<ReturnType>;
309
291
  /**
310
292
  * Moves the job to the delay set.
311
293
  *