bullmq 1.81.4 → 1.82.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/compat.d.ts +1 -1
- package/dist/cjs/classes/compat.js +2 -1
- package/dist/cjs/classes/compat.js.map +1 -1
- package/dist/cjs/classes/flow-producer.d.ts +4 -0
- package/dist/cjs/classes/flow-producer.js +7 -1
- package/dist/cjs/classes/flow-producer.js.map +1 -1
- package/dist/cjs/classes/job.d.ts +3 -2
- package/dist/cjs/classes/job.js +23 -24
- package/dist/cjs/classes/job.js.map +1 -1
- package/dist/cjs/classes/queue-base.d.ts +7 -0
- package/dist/cjs/classes/queue-base.js +9 -0
- package/dist/cjs/classes/queue-base.js.map +1 -1
- package/dist/cjs/classes/queue-getters.d.ts +4 -0
- package/dist/cjs/classes/queue-getters.js +8 -2
- package/dist/cjs/classes/queue-getters.js.map +1 -1
- package/dist/cjs/classes/queue-scheduler.js +2 -3
- package/dist/cjs/classes/queue-scheduler.js.map +1 -1
- package/dist/cjs/classes/queue.d.ts +2 -2
- package/dist/cjs/classes/queue.js +15 -13
- package/dist/cjs/classes/queue.js.map +1 -1
- package/dist/cjs/classes/repeat.d.ts +2 -2
- package/dist/cjs/classes/repeat.js +3 -5
- package/dist/cjs/classes/repeat.js.map +1 -1
- package/dist/cjs/classes/scripts.d.ts +37 -36
- package/dist/cjs/classes/scripts.js +142 -136
- package/dist/cjs/classes/scripts.js.map +1 -1
- package/dist/cjs/classes/worker.js +2 -4
- package/dist/cjs/classes/worker.js.map +1 -1
- package/dist/cjs/commands/includes/removeJobsByMaxCount.lua +1 -1
- package/dist/cjs/commands/moveStalledJobsToWait-8.lua +4 -4
- package/dist/cjs/commands/moveToFinished-12.lua +1 -1
- package/dist/cjs/commands/removeJob-1.lua +23 -8
- package/dist/cjs/commands/removeRepeatable-2.lua +9 -1
- package/dist/esm/classes/compat.d.ts +1 -1
- package/dist/esm/classes/compat.js +2 -1
- package/dist/esm/classes/compat.js.map +1 -1
- package/dist/esm/classes/flow-producer.d.ts +4 -0
- package/dist/esm/classes/flow-producer.js +7 -1
- package/dist/esm/classes/flow-producer.js.map +1 -1
- package/dist/esm/classes/job.d.ts +3 -2
- package/dist/esm/classes/job.js +23 -24
- package/dist/esm/classes/job.js.map +1 -1
- package/dist/esm/classes/queue-base.d.ts +7 -0
- package/dist/esm/classes/queue-base.js +9 -0
- package/dist/esm/classes/queue-base.js.map +1 -1
- package/dist/esm/classes/queue-getters.d.ts +4 -0
- package/dist/esm/classes/queue-getters.js +8 -2
- package/dist/esm/classes/queue-getters.js.map +1 -1
- package/dist/esm/classes/queue-scheduler.js +2 -3
- package/dist/esm/classes/queue-scheduler.js.map +1 -1
- package/dist/esm/classes/queue.d.ts +2 -2
- package/dist/esm/classes/queue.js +15 -13
- package/dist/esm/classes/queue.js.map +1 -1
- package/dist/esm/classes/repeat.d.ts +2 -2
- package/dist/esm/classes/repeat.js +3 -5
- package/dist/esm/classes/repeat.js.map +1 -1
- package/dist/esm/classes/scripts.d.ts +37 -36
- package/dist/esm/classes/scripts.js +142 -136
- package/dist/esm/classes/scripts.js.map +1 -1
- package/dist/esm/classes/worker.js +2 -4
- package/dist/esm/classes/worker.js.map +1 -1
- package/dist/esm/commands/includes/removeJobsByMaxCount.lua +1 -1
- package/dist/esm/commands/moveStalledJobsToWait-8.lua +4 -4
- package/dist/esm/commands/moveToFinished-12.lua +1 -1
- package/dist/esm/commands/removeJob-1.lua +23 -8
- package/dist/esm/commands/removeRepeatable-2.lua +9 -1
- package/package.json +1 -1
@@ -1,10 +1,9 @@
|
|
1
1
|
/**
|
2
2
|
* Includes all the scripts needed by the queue and jobs.
|
3
3
|
*/
|
4
|
+
/// <reference types="node" />
|
4
5
|
import { JobJson, JobJsonRaw, JobsOptions, RedisClient, KeepJobs } from '../interfaces';
|
5
6
|
import { JobState, FinishedStatus, FinishedPropValAttribute } from '../types';
|
6
|
-
import { Worker } from './worker';
|
7
|
-
import { QueueScheduler } from './queue-scheduler';
|
8
7
|
import { QueueBase } from './queue-base';
|
9
8
|
import { Job, MoveToChildrenOpts } from './job';
|
10
9
|
export declare type MinimalQueue = Pick<QueueBase, 'name' | 'client' | 'toKey' | 'keys' | 'opts' | 'closing' | 'waitUntilReady' | 'removeListener' | 'emit' | 'on' | 'redisVersion'>;
|
@@ -15,29 +14,31 @@ export declare type ParentOpts = {
|
|
15
14
|
};
|
16
15
|
export declare type JobData = [JobJsonRaw | number, string?];
|
17
16
|
export declare class Scripts {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
17
|
+
protected queue: MinimalQueue;
|
18
|
+
constructor(queue: MinimalQueue);
|
19
|
+
isJobInList(listKey: string, jobId: string): Promise<boolean>;
|
20
|
+
addJob(client: RedisClient, job: JobJson, opts: JobsOptions, jobId: string, parentOpts?: ParentOpts): Promise<string>;
|
21
|
+
pause(pause: boolean): Promise<void>;
|
22
|
+
private removeRepeatableArgs;
|
23
|
+
removeRepeatable(repeatJobId: string, repeatJobKey: string): Promise<number>;
|
24
|
+
remove(jobId: string): Promise<number>;
|
25
|
+
extendLock(jobId: string, token: string, duration: number): Promise<number>;
|
26
|
+
updateData<T = any, R = any, N extends string = string>(job: Job<T, R, N>, data: T): Promise<void>;
|
27
|
+
updateProgress<T = any, R = any, N extends string = string>(job: Job<T, R, N>, progress: number | object): Promise<void>;
|
28
|
+
protected moveToFinishedArgs<T = any, R = any, N extends string = string>(job: Job<T, R, N>, val: any, propVal: FinishedPropValAttribute, shouldRemove: boolean | number | KeepJobs, target: FinishedStatus, token: string, fetchNext?: boolean): (string | number | boolean | Buffer)[];
|
29
|
+
protected moveToFinished<DataType = any, ReturnType = any, NameType extends string = string>(job: Job<DataType, ReturnType, NameType>, val: any, propVal: FinishedPropValAttribute, shouldRemove: boolean | number | KeepJobs, target: FinishedStatus, token: string, fetchNext: boolean): Promise<JobData | []>;
|
30
|
+
finishedErrors(code: number, jobId: string, command: string, state?: string): Error;
|
31
|
+
private drainArgs;
|
32
|
+
drain(delayed: boolean): Promise<void>;
|
33
|
+
moveToCompleted<T = any, R = any, N extends string = string>(job: Job<T, R, N>, returnvalue: R, removeOnComplete: boolean | number | KeepJobs, token: string, fetchNext: boolean): Promise<JobData | []>;
|
34
|
+
moveToFailedArgs<T = any, R = any, N extends string = string>(job: Job<T, R, N>, failedReason: string, removeOnFailed: boolean | number | KeepJobs, token: string, fetchNext?: boolean): (string | number | boolean | Buffer)[];
|
35
|
+
isFinished(jobId: string, returnValue?: boolean): Promise<number | [number, string]>;
|
36
|
+
getState(jobId: string): Promise<JobState | 'unknown'>;
|
37
|
+
changeDelay(jobId: string, delay: number): Promise<void>;
|
38
|
+
private changeDelayArgs;
|
39
|
+
moveToDelayedArgs(jobId: string, timestamp: number, token: string): string[];
|
40
|
+
moveToWaitingChildrenArgs(jobId: string, token: string, opts?: MoveToChildrenOpts): string[];
|
41
|
+
moveToDelayed(jobId: string, timestamp: number, token?: string): Promise<void>;
|
41
42
|
/**
|
42
43
|
* Move parent job to waiting-children state.
|
43
44
|
*
|
@@ -49,16 +50,16 @@ export declare class Scripts {
|
|
49
50
|
* @throws JobNotInState
|
50
51
|
* This exception is thrown if job is not in active state.
|
51
52
|
*/
|
52
|
-
|
53
|
+
moveToWaitingChildren(jobId: string, token: string, opts?: MoveToChildrenOpts): Promise<boolean>;
|
53
54
|
/**
|
54
55
|
* Remove jobs in a specific state.
|
55
56
|
*
|
56
57
|
* @returns Id jobs from the deleted records.
|
57
58
|
*/
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
cleanJobsInSet(set: string, timestamp: number, limit?: number): Promise<string[]>;
|
60
|
+
retryJobArgs<T = any, R = any, N extends string = string>(job: Job<T, R, N>): string[];
|
61
|
+
protected retryJobsArgs(state: FinishedStatus, count: number, timestamp: number): (string | number)[];
|
62
|
+
retryJobs(state?: FinishedStatus, count?: number, timestamp?: number): Promise<number>;
|
62
63
|
/**
|
63
64
|
* Attempts to reprocess a job
|
64
65
|
*
|
@@ -73,14 +74,14 @@ export declare class Scripts {
|
|
73
74
|
* -1 means the job is currently locked and can't be retried.
|
74
75
|
* -2 means the job was not found in the expected set
|
75
76
|
*/
|
76
|
-
|
77
|
-
|
77
|
+
reprocessJob<T = any, R = any, N extends string = string>(job: Job<T, R, N>, state: 'failed' | 'completed'): Promise<void>;
|
78
|
+
moveToActive<T, R, N extends string>(token: string, jobId?: string): Promise<[] | [number | JobJsonRaw, string?]>;
|
78
79
|
/**
|
79
80
|
* It checks if the job in the top of the delay set should be moved back to the
|
80
81
|
* top of the wait queue (so that it will be processed as soon as possible)
|
81
82
|
*/
|
82
|
-
|
83
|
-
|
83
|
+
updateDelaySet(delayedTimestamp: number): Promise<[number, string]>;
|
84
|
+
promote(jobId: string): Promise<number>;
|
84
85
|
/**
|
85
86
|
* Looks for unlocked jobs in the active queue.
|
86
87
|
*
|
@@ -90,8 +91,8 @@ export declare class Scripts {
|
|
90
91
|
* (e.g. if the job handler keeps crashing),
|
91
92
|
* we limit the number stalled job recoveries to settings.maxStalledCount.
|
92
93
|
*/
|
93
|
-
|
94
|
-
|
94
|
+
moveStalledJobsToWait(): Promise<any>;
|
95
|
+
obliterate(opts: {
|
95
96
|
force: boolean;
|
96
97
|
count: number;
|
97
98
|
}): Promise<number>;
|
@@ -13,10 +13,13 @@ import * as semver from 'semver';
|
|
13
13
|
import { ErrorCode } from '../enums';
|
14
14
|
import { array2obj, getParentKey } from '../utils';
|
15
15
|
export class Scripts {
|
16
|
-
|
17
|
-
|
16
|
+
constructor(queue) {
|
17
|
+
this.queue = queue;
|
18
|
+
}
|
19
|
+
async isJobInList(listKey, jobId) {
|
20
|
+
const client = await this.queue.client;
|
18
21
|
let result;
|
19
|
-
if (semver.lt(queue.redisVersion, '6.0.6')) {
|
22
|
+
if (semver.lt(this.queue.redisVersion, '6.0.6')) {
|
20
23
|
result = await client.isJobInList([listKey, jobId]);
|
21
24
|
}
|
22
25
|
else {
|
@@ -24,12 +27,12 @@ export class Scripts {
|
|
24
27
|
}
|
25
28
|
return Number.isInteger(result);
|
26
29
|
}
|
27
|
-
|
30
|
+
async addJob(client, job, opts, jobId, parentOpts = {
|
28
31
|
parentKey: null,
|
29
32
|
waitChildrenKey: null,
|
30
33
|
parentDependenciesKey: null,
|
31
34
|
}) {
|
32
|
-
const queueKeys = queue.keys;
|
35
|
+
const queueKeys = this.queue.keys;
|
33
36
|
const keys = [
|
34
37
|
queueKeys.wait,
|
35
38
|
queueKeys.paused,
|
@@ -71,68 +74,68 @@ export class Scripts {
|
|
71
74
|
}
|
72
75
|
return result;
|
73
76
|
}
|
74
|
-
|
75
|
-
const client = await queue.client;
|
77
|
+
async pause(pause) {
|
78
|
+
const client = await this.queue.client;
|
76
79
|
let src = 'wait', dst = 'paused';
|
77
80
|
if (!pause) {
|
78
81
|
src = 'paused';
|
79
82
|
dst = 'wait';
|
80
83
|
}
|
81
|
-
const keys = [src, dst, 'meta'].map((name) => queue.toKey(name));
|
82
|
-
keys.push(queue.keys.events);
|
84
|
+
const keys = [src, dst, 'meta'].map((name) => this.queue.toKey(name));
|
85
|
+
keys.push(this.queue.keys.events);
|
83
86
|
return client.pause(keys.concat([pause ? 'paused' : 'resumed']));
|
84
87
|
}
|
85
|
-
|
86
|
-
const queueKeys = queue.keys;
|
88
|
+
removeRepeatableArgs(repeatJobId, repeatJobKey) {
|
89
|
+
const queueKeys = this.queue.keys;
|
87
90
|
const keys = [queueKeys.repeat, queueKeys.delayed];
|
88
91
|
const args = [repeatJobId, repeatJobKey, queueKeys['']];
|
89
92
|
return keys.concat(args);
|
90
93
|
}
|
91
|
-
|
92
|
-
const client = await queue.client;
|
93
|
-
const args = this.removeRepeatableArgs(
|
94
|
+
async removeRepeatable(repeatJobId, repeatJobKey) {
|
95
|
+
const client = await this.queue.client;
|
96
|
+
const args = this.removeRepeatableArgs(repeatJobId, repeatJobKey);
|
94
97
|
return client.removeRepeatable(args);
|
95
98
|
}
|
96
|
-
|
97
|
-
const client = await queue.client;
|
98
|
-
const keys = [jobId].map(name => queue.toKey(name));
|
99
|
+
async remove(jobId) {
|
100
|
+
const client = await this.queue.client;
|
101
|
+
const keys = [jobId].map(name => this.queue.toKey(name));
|
99
102
|
return client.removeJob(keys.concat([jobId]));
|
100
103
|
}
|
101
|
-
|
102
|
-
const client = await queue.client;
|
104
|
+
async extendLock(jobId, token, duration) {
|
105
|
+
const client = await this.queue.client;
|
103
106
|
const args = [
|
104
|
-
queue.toKey(jobId) + ':lock',
|
105
|
-
queue.keys.stalled,
|
107
|
+
this.queue.toKey(jobId) + ':lock',
|
108
|
+
this.queue.keys.stalled,
|
106
109
|
token,
|
107
110
|
duration,
|
108
111
|
jobId,
|
109
112
|
];
|
110
113
|
return client.extendLock(args);
|
111
114
|
}
|
112
|
-
|
113
|
-
const client = await queue.client;
|
114
|
-
const keys = [queue.toKey(job.id)];
|
115
|
+
async updateData(job, data) {
|
116
|
+
const client = await this.queue.client;
|
117
|
+
const keys = [this.queue.toKey(job.id)];
|
115
118
|
const dataJson = JSON.stringify(data);
|
116
119
|
const result = await client.updateData(keys.concat([dataJson]));
|
117
120
|
if (result < 0) {
|
118
121
|
throw this.finishedErrors(result, job.id, 'updateData');
|
119
122
|
}
|
120
123
|
}
|
121
|
-
|
122
|
-
const client = await queue.client;
|
123
|
-
const keys = [queue.toKey(job.id), queue.keys.events];
|
124
|
+
async updateProgress(job, progress) {
|
125
|
+
const client = await this.queue.client;
|
126
|
+
const keys = [this.queue.toKey(job.id), this.queue.keys.events];
|
124
127
|
const progressJson = JSON.stringify(progress);
|
125
128
|
const result = await client.updateProgress(keys.concat([job.id, progressJson]));
|
126
129
|
if (result < 0) {
|
127
130
|
throw this.finishedErrors(result, job.id, 'updateProgress');
|
128
131
|
}
|
129
|
-
queue.emit('progress', job, progress);
|
132
|
+
this.queue.emit('progress', job, progress);
|
130
133
|
}
|
131
|
-
|
134
|
+
moveToFinishedArgs(job, val, propVal, shouldRemove, target, token, fetchNext = true) {
|
132
135
|
var _a, _b, _c;
|
133
|
-
const queueKeys = queue.keys;
|
134
|
-
const opts = queue.opts;
|
135
|
-
const metricsKey = queue.toKey(`metrics:${target}`);
|
136
|
+
const queueKeys = this.queue.keys;
|
137
|
+
const opts = this.queue.opts;
|
138
|
+
const metricsKey = this.queue.toKey(`metrics:${target}`);
|
136
139
|
const keys = [
|
137
140
|
queueKeys.wait,
|
138
141
|
queueKeys.active,
|
@@ -143,7 +146,7 @@ export class Scripts {
|
|
143
146
|
queueKeys.delayed,
|
144
147
|
queueKeys.delay,
|
145
148
|
queueKeys[target],
|
146
|
-
queue.toKey(job.id),
|
149
|
+
this.queue.toKey(job.id),
|
147
150
|
queueKeys.meta,
|
148
151
|
metricsKey,
|
149
152
|
];
|
@@ -159,7 +162,7 @@ export class Scripts {
|
|
159
162
|
typeof val === 'undefined' ? 'null' : val,
|
160
163
|
target,
|
161
164
|
JSON.stringify({ jobId: job.id, val: val }),
|
162
|
-
!fetchNext || queue.closing ? 0 : 1,
|
165
|
+
!fetchNext || this.queue.closing ? 0 : 1,
|
163
166
|
queueKeys[''],
|
164
167
|
pack({
|
165
168
|
token,
|
@@ -177,9 +180,9 @@ export class Scripts {
|
|
177
180
|
];
|
178
181
|
return keys.concat(args);
|
179
182
|
}
|
180
|
-
|
181
|
-
const client = await queue.client;
|
182
|
-
const args = this.moveToFinishedArgs(
|
183
|
+
async moveToFinished(job, val, propVal, shouldRemove, target, token, fetchNext) {
|
184
|
+
const client = await this.queue.client;
|
185
|
+
const args = this.moveToFinishedArgs(job, val, propVal, shouldRemove, target, token, fetchNext);
|
183
186
|
const result = await client.moveToFinished(args);
|
184
187
|
if (result < 0) {
|
185
188
|
throw this.finishedErrors(result, job.id, 'finished', 'active');
|
@@ -188,7 +191,7 @@ export class Scripts {
|
|
188
191
|
return raw2jobData(result);
|
189
192
|
}
|
190
193
|
}
|
191
|
-
|
194
|
+
finishedErrors(code, jobId, command, state) {
|
192
195
|
switch (code) {
|
193
196
|
case ErrorCode.JobNotExist:
|
194
197
|
return new Error(`Missing key for job ${jobId}. ${command}`);
|
@@ -202,8 +205,8 @@ export class Scripts {
|
|
202
205
|
return new Error(`Missing key for parent job ${jobId}. ${command}`);
|
203
206
|
}
|
204
207
|
}
|
205
|
-
|
206
|
-
const queueKeys = queue.keys;
|
208
|
+
drainArgs(delayed) {
|
209
|
+
const queueKeys = this.queue.keys;
|
207
210
|
const keys = [
|
208
211
|
queueKeys.wait,
|
209
212
|
queueKeys.paused,
|
@@ -213,26 +216,26 @@ export class Scripts {
|
|
213
216
|
const args = [queueKeys['']];
|
214
217
|
return keys.concat(args);
|
215
218
|
}
|
216
|
-
|
217
|
-
const client = await queue.client;
|
218
|
-
const args = this.drainArgs(
|
219
|
+
async drain(delayed) {
|
220
|
+
const client = await this.queue.client;
|
221
|
+
const args = this.drainArgs(delayed);
|
219
222
|
return client.drain(args);
|
220
223
|
}
|
221
|
-
|
222
|
-
return this.moveToFinished(
|
224
|
+
moveToCompleted(job, returnvalue, removeOnComplete, token, fetchNext) {
|
225
|
+
return this.moveToFinished(job, returnvalue, 'returnvalue', removeOnComplete, 'completed', token, fetchNext);
|
223
226
|
}
|
224
|
-
|
225
|
-
return this.moveToFinishedArgs(
|
227
|
+
moveToFailedArgs(job, failedReason, removeOnFailed, token, fetchNext = false) {
|
228
|
+
return this.moveToFinishedArgs(job, failedReason, 'failedReason', removeOnFailed, 'failed', token, fetchNext);
|
226
229
|
}
|
227
|
-
|
228
|
-
const client = await queue.client;
|
229
|
-
const keys = ['completed', 'failed', jobId].map(
|
230
|
-
return queue.toKey(key);
|
230
|
+
async isFinished(jobId, returnValue = false) {
|
231
|
+
const client = await this.queue.client;
|
232
|
+
const keys = ['completed', 'failed', jobId].map((key) => {
|
233
|
+
return this.queue.toKey(key);
|
231
234
|
});
|
232
235
|
return client.isFinished(keys.concat([jobId, returnValue ? '1' : '']));
|
233
236
|
}
|
234
|
-
|
235
|
-
const client = await queue.client;
|
237
|
+
async getState(jobId) {
|
238
|
+
const client = await this.queue.client;
|
236
239
|
const keys = [
|
237
240
|
'completed',
|
238
241
|
'failed',
|
@@ -241,24 +244,24 @@ export class Scripts {
|
|
241
244
|
'wait',
|
242
245
|
'paused',
|
243
246
|
'waiting-children',
|
244
|
-
].map(
|
245
|
-
return queue.toKey(key);
|
247
|
+
].map((key) => {
|
248
|
+
return this.queue.toKey(key);
|
246
249
|
});
|
247
|
-
if (semver.lt(queue.redisVersion, '6.0.6')) {
|
250
|
+
if (semver.lt(this.queue.redisVersion, '6.0.6')) {
|
248
251
|
return client.getState(keys.concat([jobId]));
|
249
252
|
}
|
250
253
|
return client.getStateV2(keys.concat([jobId]));
|
251
254
|
}
|
252
|
-
|
253
|
-
const client = await queue.client;
|
255
|
+
async changeDelay(jobId, delay) {
|
256
|
+
const client = await this.queue.client;
|
254
257
|
const delayTimestamp = Date.now() + delay;
|
255
|
-
const args = this.changeDelayArgs(
|
258
|
+
const args = this.changeDelayArgs(jobId, delayTimestamp);
|
256
259
|
const result = await client.changeDelay(args);
|
257
260
|
if (result < 0) {
|
258
261
|
throw this.finishedErrors(result, jobId, 'changeDelay', 'delayed');
|
259
262
|
}
|
260
263
|
}
|
261
|
-
|
264
|
+
changeDelayArgs(jobId, timestamp) {
|
262
265
|
//
|
263
266
|
// Bake in the job id first 12 bits into the timestamp
|
264
267
|
// to guarantee correct execution order of delayed jobs
|
@@ -270,14 +273,14 @@ export class Scripts {
|
|
270
273
|
if (timestamp > 0) {
|
271
274
|
timestamp = timestamp * 0x1000 + (+jobId & 0xfff);
|
272
275
|
}
|
273
|
-
const keys = ['delayed', jobId].map(
|
274
|
-
return queue.toKey(name);
|
276
|
+
const keys = ['delayed', jobId].map(name => {
|
277
|
+
return this.queue.toKey(name);
|
275
278
|
});
|
276
|
-
keys.push.apply(keys, [queue.keys.events, queue.keys.delay]);
|
279
|
+
keys.push.apply(keys, [this.queue.keys.events, this.queue.keys.delay]);
|
277
280
|
return keys.concat([JSON.stringify(timestamp), jobId]);
|
278
281
|
}
|
279
282
|
// Note: We have an issue here with jobs using custom job ids
|
280
|
-
|
283
|
+
moveToDelayedArgs(jobId, timestamp, token) {
|
281
284
|
//
|
282
285
|
// Bake in the job id first 12 bits into the timestamp
|
283
286
|
// to guarantee correct execution order of delayed jobs
|
@@ -289,21 +292,21 @@ export class Scripts {
|
|
289
292
|
if (timestamp > 0) {
|
290
293
|
timestamp = timestamp * 0x1000 + (+jobId & 0xfff);
|
291
294
|
}
|
292
|
-
const keys = ['active', 'delayed', jobId].map(
|
293
|
-
return queue.toKey(name);
|
295
|
+
const keys = ['active', 'delayed', jobId].map(name => {
|
296
|
+
return this.queue.toKey(name);
|
294
297
|
});
|
295
|
-
keys.push.apply(keys, [queue.keys.events, queue.keys.delay]);
|
298
|
+
keys.push.apply(keys, [this.queue.keys.events, this.queue.keys.delay]);
|
296
299
|
return keys.concat([JSON.stringify(timestamp), jobId, token]);
|
297
300
|
}
|
298
|
-
|
301
|
+
moveToWaitingChildrenArgs(jobId, token, opts) {
|
299
302
|
var _a;
|
300
303
|
let timestamp = Math.max(0, (_a = opts.timestamp) !== null && _a !== void 0 ? _a : 0);
|
301
304
|
const childKey = getParentKey(opts.child);
|
302
305
|
if (timestamp > 0) {
|
303
306
|
timestamp = timestamp * 0x1000 + (+jobId & 0xfff);
|
304
307
|
}
|
305
|
-
const keys = [`${jobId}:lock`, 'active', 'waiting-children', jobId].map(
|
306
|
-
return queue.toKey(name);
|
308
|
+
const keys = [`${jobId}:lock`, 'active', 'waiting-children', jobId].map(name => {
|
309
|
+
return this.queue.toKey(name);
|
307
310
|
});
|
308
311
|
return keys.concat([
|
309
312
|
token,
|
@@ -312,9 +315,9 @@ export class Scripts {
|
|
312
315
|
jobId,
|
313
316
|
]);
|
314
317
|
}
|
315
|
-
|
316
|
-
const client = await queue.client;
|
317
|
-
const args = this.moveToDelayedArgs(
|
318
|
+
async moveToDelayed(jobId, timestamp, token = '0') {
|
319
|
+
const client = await this.queue.client;
|
320
|
+
const args = this.moveToDelayedArgs(jobId, timestamp, token);
|
318
321
|
const result = await client.moveToDelayed(args);
|
319
322
|
if (result < 0) {
|
320
323
|
throw this.finishedErrors(result, jobId, 'moveToDelayed', 'active');
|
@@ -331,9 +334,9 @@ export class Scripts {
|
|
331
334
|
* @throws JobNotInState
|
332
335
|
* This exception is thrown if job is not in active state.
|
333
336
|
*/
|
334
|
-
|
335
|
-
const client = await queue.client;
|
336
|
-
const args = this.moveToWaitingChildrenArgs(
|
337
|
+
async moveToWaitingChildren(jobId, token, opts = {}) {
|
338
|
+
const client = await this.queue.client;
|
339
|
+
const args = this.moveToWaitingChildrenArgs(jobId, token, opts);
|
337
340
|
const result = await client.moveToWaitingChildren(args);
|
338
341
|
switch (result) {
|
339
342
|
case 0:
|
@@ -349,39 +352,39 @@ export class Scripts {
|
|
349
352
|
*
|
350
353
|
* @returns Id jobs from the deleted records.
|
351
354
|
*/
|
352
|
-
|
353
|
-
const client = await queue.client;
|
355
|
+
async cleanJobsInSet(set, timestamp, limit = 0) {
|
356
|
+
const client = await this.queue.client;
|
354
357
|
return client.cleanJobsInSet([
|
355
|
-
queue.toKey(set),
|
356
|
-
queue.toKey('events'),
|
357
|
-
queue.toKey(''),
|
358
|
+
this.queue.toKey(set),
|
359
|
+
this.queue.toKey('events'),
|
360
|
+
this.queue.toKey(''),
|
358
361
|
timestamp,
|
359
362
|
limit,
|
360
363
|
set,
|
361
364
|
]);
|
362
365
|
}
|
363
|
-
|
366
|
+
retryJobArgs(job) {
|
364
367
|
const jobId = job.id;
|
365
|
-
const keys = ['active', 'wait', jobId].map(
|
366
|
-
return queue.toKey(name);
|
368
|
+
const keys = ['active', 'wait', jobId].map(name => {
|
369
|
+
return this.queue.toKey(name);
|
367
370
|
});
|
368
|
-
keys.push(queue.keys.events);
|
371
|
+
keys.push(this.queue.keys.events);
|
369
372
|
const pushCmd = (job.opts.lifo ? 'R' : 'L') + 'PUSH';
|
370
373
|
return keys.concat([pushCmd, jobId]);
|
371
374
|
}
|
372
|
-
|
375
|
+
retryJobsArgs(state, count, timestamp) {
|
373
376
|
const keys = [
|
374
|
-
queue.toKey(''),
|
375
|
-
queue.keys.events,
|
376
|
-
queue.toKey(state),
|
377
|
-
queue.toKey('wait'),
|
377
|
+
this.queue.toKey(''),
|
378
|
+
this.queue.keys.events,
|
379
|
+
this.queue.toKey(state),
|
380
|
+
this.queue.toKey('wait'),
|
378
381
|
];
|
379
382
|
const args = [count, timestamp];
|
380
383
|
return keys.concat(args);
|
381
384
|
}
|
382
|
-
|
383
|
-
const client = await queue.client;
|
384
|
-
const args = this.retryJobsArgs(
|
385
|
+
async retryJobs(state = 'failed', count = 1000, timestamp = new Date().getTime()) {
|
386
|
+
const client = await this.queue.client;
|
387
|
+
const args = this.retryJobsArgs(state, count, timestamp);
|
385
388
|
return client.retryJobs(args);
|
386
389
|
}
|
387
390
|
/**
|
@@ -398,13 +401,13 @@ export class Scripts {
|
|
398
401
|
* -1 means the job is currently locked and can't be retried.
|
399
402
|
* -2 means the job was not found in the expected set
|
400
403
|
*/
|
401
|
-
|
402
|
-
const client = await queue.client;
|
404
|
+
async reprocessJob(job, state) {
|
405
|
+
const client = await this.queue.client;
|
403
406
|
const keys = [
|
404
|
-
queue.toKey(job.id),
|
405
|
-
queue.keys.events,
|
406
|
-
queue.toKey(state),
|
407
|
-
queue.toKey('wait'),
|
407
|
+
this.queue.toKey(job.id),
|
408
|
+
this.queue.keys.events,
|
409
|
+
this.queue.toKey(state),
|
410
|
+
this.queue.toKey('wait'),
|
408
411
|
];
|
409
412
|
const args = [
|
410
413
|
job.id,
|
@@ -419,10 +422,10 @@ export class Scripts {
|
|
419
422
|
throw this.finishedErrors(result, job.id, 'reprocessJob', state);
|
420
423
|
}
|
421
424
|
}
|
422
|
-
|
423
|
-
const client = await
|
424
|
-
const opts =
|
425
|
-
const queueKeys =
|
425
|
+
async moveToActive(token, jobId) {
|
426
|
+
const client = await this.queue.client;
|
427
|
+
const opts = this.queue.opts;
|
428
|
+
const queueKeys = this.queue.keys;
|
426
429
|
const keys = [
|
427
430
|
queueKeys.wait,
|
428
431
|
queueKeys.active,
|
@@ -457,30 +460,30 @@ export class Scripts {
|
|
457
460
|
* It checks if the job in the top of the delay set should be moved back to the
|
458
461
|
* top of the wait queue (so that it will be processed as soon as possible)
|
459
462
|
*/
|
460
|
-
|
461
|
-
const client = await queue.client;
|
463
|
+
async updateDelaySet(delayedTimestamp) {
|
464
|
+
const client = await this.queue.client;
|
462
465
|
const keys = [
|
463
|
-
queue.keys.delayed,
|
464
|
-
queue.keys.wait,
|
465
|
-
queue.keys.priority,
|
466
|
-
queue.keys.paused,
|
467
|
-
queue.keys.meta,
|
468
|
-
queue.keys.events,
|
469
|
-
queue.keys.delay,
|
466
|
+
this.queue.keys.delayed,
|
467
|
+
this.queue.keys.wait,
|
468
|
+
this.queue.keys.priority,
|
469
|
+
this.queue.keys.paused,
|
470
|
+
this.queue.keys.meta,
|
471
|
+
this.queue.keys.events,
|
472
|
+
this.queue.keys.delay,
|
470
473
|
];
|
471
|
-
const args = [queue.toKey(''), delayedTimestamp];
|
474
|
+
const args = [this.queue.toKey(''), delayedTimestamp];
|
472
475
|
return client.updateDelaySet(keys.concat(args));
|
473
476
|
}
|
474
|
-
|
475
|
-
const client = await queue.client;
|
477
|
+
async promote(jobId) {
|
478
|
+
const client = await this.queue.client;
|
476
479
|
const keys = [
|
477
|
-
queue.keys.delayed,
|
478
|
-
queue.keys.wait,
|
479
|
-
queue.keys.paused,
|
480
|
-
queue.keys.priority,
|
481
|
-
queue.keys.events,
|
480
|
+
this.queue.keys.delayed,
|
481
|
+
this.queue.keys.wait,
|
482
|
+
this.queue.keys.paused,
|
483
|
+
this.queue.keys.priority,
|
484
|
+
this.queue.keys.events,
|
482
485
|
];
|
483
|
-
const args = [queue.toKey(''), jobId];
|
486
|
+
const args = [this.queue.toKey(''), jobId];
|
484
487
|
return client.promote(keys.concat(args));
|
485
488
|
}
|
486
489
|
/**
|
@@ -492,30 +495,33 @@ export class Scripts {
|
|
492
495
|
* (e.g. if the job handler keeps crashing),
|
493
496
|
* we limit the number stalled job recoveries to settings.maxStalledCount.
|
494
497
|
*/
|
495
|
-
|
496
|
-
const client = await queue.client;
|
497
|
-
const opts = queue.opts;
|
498
|
+
async moveStalledJobsToWait() {
|
499
|
+
const client = await this.queue.client;
|
500
|
+
const opts = this.queue.opts;
|
498
501
|
const keys = [
|
499
|
-
queue.keys.stalled,
|
500
|
-
queue.keys.wait,
|
501
|
-
queue.keys.active,
|
502
|
-
queue.keys.failed,
|
503
|
-
queue.keys['stalled-check'],
|
504
|
-
queue.keys.meta,
|
505
|
-
queue.keys.paused,
|
506
|
-
queue.keys.events,
|
502
|
+
this.queue.keys.stalled,
|
503
|
+
this.queue.keys.wait,
|
504
|
+
this.queue.keys.active,
|
505
|
+
this.queue.keys.failed,
|
506
|
+
this.queue.keys['stalled-check'],
|
507
|
+
this.queue.keys.meta,
|
508
|
+
this.queue.keys.paused,
|
509
|
+
this.queue.keys.events,
|
507
510
|
];
|
508
511
|
const args = [
|
509
512
|
opts.maxStalledCount,
|
510
|
-
queue.toKey(''),
|
513
|
+
this.queue.toKey(''),
|
511
514
|
Date.now(),
|
512
515
|
opts.stalledInterval,
|
513
516
|
];
|
514
517
|
return client.moveStalledJobsToWait(keys.concat(args));
|
515
518
|
}
|
516
|
-
|
517
|
-
const client = await queue.client;
|
518
|
-
const keys = [
|
519
|
+
async obliterate(opts) {
|
520
|
+
const client = await this.queue.client;
|
521
|
+
const keys = [
|
522
|
+
this.queue.keys.meta,
|
523
|
+
this.queue.toKey(''),
|
524
|
+
];
|
519
525
|
const args = [opts.count, opts.force ? 'force' : null];
|
520
526
|
const result = await client.obliterate(keys.concat(args));
|
521
527
|
if (result < 0) {
|