1 | // Type definitions for bull 3.15
|
2 | // Project: https://github.com/OptimalBits/bull
|
3 | // Definitions by: Bruno Grieder <https://github.com/bgrieder>
|
4 | // Cameron Crothers <https://github.com/JProgrammer>
|
5 | // Marshall Cottrell <https://github.com/marshall007>
|
6 | // Weeco <https://github.com/weeco>
|
7 | // Oleg Repin <https://github.com/iamolegga>
|
8 | // David Koblas <https://github.com/koblas>
|
9 | // Bond Akinmade <https://github.com/bondz>
|
10 | // Wuha Team <https://github.com/wuha-team>
|
11 | // Alec Brunelle <https://github.com/aleccool213>
|
12 | // Dan Manastireanu <https://github.com/danmana>
|
13 | // Kjell-Morten Bratsberg Thorsen <https://github.com/kjellmorten>
|
14 | // Christian D. <https://github.com/pc-jedi>
|
15 | // Silas Rech <https://github.com/lenovouser>
|
16 | // DoYoung Ha <https://github.com/hados99>
|
17 | // Borys Kupar <https://github.com/borys-kupar>
|
18 | // Remko Klein <https://github.com/remko79>
|
19 | // Levi Bostian <https://github.com/levibostian>
|
20 | // Todd Dukart <https://github.com/tdukart>
|
21 | // Mix <https://github.com/mnixry>
|
22 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
23 | // TypeScript Version: 2.8
|
24 |
|
25 | import * as Redis from "ioredis";
|
26 | import { EventEmitter } from "events";
|
27 |
|
28 | /**
|
29 | * This is the Queue constructor.
|
30 | * It creates a new Queue that is persisted in Redis.
|
31 | * Everytime the same queue is instantiated it tries to process all the old jobs that may exist from a previous unfinished session.
|
32 | */
|
33 | declare const Bull: {
|
34 | /* tslint:disable:no-unnecessary-generics unified-signatures */
|
35 | <T = any>(queueName: string, opts?: Bull.QueueOptions): Bull.Queue<T>;
|
36 | <T = any>(queueName: string, url: string, opts?: Bull.QueueOptions): Bull.Queue<T>;
|
37 | new <T = any>(queueName: string, opts?: Bull.QueueOptions): Bull.Queue<T>;
|
38 | new <T = any>(queueName: string, url: string, opts?: Bull.QueueOptions): Bull.Queue<T>;
|
39 | /* tslint:enable:no-unnecessary-generics unified-signatures */
|
40 | };
|
41 |
|
42 | declare namespace Bull {
|
43 | interface RateLimiter {
|
44 | /** Max numbers of jobs processed */
|
45 | max: number;
|
46 | /** Per duration in milliseconds */
|
47 | duration: number;
|
48 | /** When jobs get rate limited, they stay in the waiting queue and are not moved to the delayed queue */
|
49 | bounceBack?: boolean | undefined;
|
50 | /** Groups jobs with the specified key from the data object passed to the Queue#add ex. "network.handle" */
|
51 | groupKey?: string | undefined;
|
52 | }
|
53 |
|
54 | interface QueueOptions {
|
55 | /**
|
56 | * Options passed into the `ioredis` constructor's `options` parameter.
|
57 | * `connectionName` is overwritten with `Queue.clientName()`. other properties are copied
|
58 | */
|
59 | redis?: Redis.RedisOptions | undefined;
|
60 |
|
61 | /**
|
62 | * When specified, the `Queue` will use this function to create new `ioredis` client connections.
|
63 | * This is useful if you want to re-use connections or connect to a Redis cluster.
|
64 | */
|
65 | createClient?(type: 'client' | 'subscriber' | 'bclient', redisOpts?: Redis.RedisOptions): Redis.Redis | Redis.Cluster;
|
66 |
|
67 | /**
|
68 | * Prefix to use for all redis keys
|
69 | */
|
70 | prefix?: string | undefined;
|
71 |
|
72 | settings?: AdvancedSettings | undefined;
|
73 |
|
74 | limiter?: RateLimiter | undefined;
|
75 |
|
76 | defaultJobOptions?: JobOptions | undefined;
|
77 | }
|
78 |
|
79 | interface AdvancedSettings {
|
80 | /**
|
81 | * Key expiration time for job locks
|
82 | */
|
83 | lockDuration?: number | undefined;
|
84 |
|
85 | /**
|
86 | * Interval in milliseconds on which to acquire the job lock.
|
87 | */
|
88 | lockRenewTime?: number | undefined;
|
89 |
|
90 | /**
|
91 | * How often check for stalled jobs (use 0 for never checking)
|
92 | */
|
93 | stalledInterval?: number | undefined;
|
94 |
|
95 | /**
|
96 | * Max amount of times a stalled job will be re-processed
|
97 | */
|
98 | maxStalledCount?: number | undefined;
|
99 |
|
100 | /**
|
101 | * Poll interval for delayed jobs and added jobs
|
102 | */
|
103 | guardInterval?: number | undefined;
|
104 |
|
105 | /**
|
106 | * Delay before processing next job in case of internal error
|
107 | */
|
108 | retryProcessDelay?: number | undefined;
|
109 |
|
110 | /**
|
111 | * Define a custom backoff strategy
|
112 | */
|
113 | backoffStrategies?: {
|
114 | [key: string]: (attemptsMade: number, err: Error, strategyOptions?: any) => number;
|
115 | } | undefined;
|
116 |
|
117 | /**
|
118 | * A timeout for when the queue is in `drained` state (empty waiting for jobs).
|
119 | * It is used when calling `queue.getNextJob()`, which will pass it to `.brpoplpush` on the Redis client.
|
120 | */
|
121 | drainDelay?: number | undefined;
|
122 | }
|
123 |
|
124 | type DoneCallback = (error?: Error | null, value?: any) => void;
|
125 |
|
126 | type JobId = number | string;
|
127 |
|
128 | type ProcessCallbackFunction<T> = (job: Job<T>, done: DoneCallback) => void;
|
129 | type ProcessPromiseFunction<T> = (job: Job<T>) => Promise<void>;
|
130 |
|
131 | interface Job<T = any> {
|
132 | id: JobId;
|
133 |
|
134 | /**
|
135 | * The custom data passed when the job was created
|
136 | */
|
137 | data: T;
|
138 |
|
139 | /**
|
140 | * Options of the job
|
141 | */
|
142 | opts: JobOptions;
|
143 |
|
144 | /**
|
145 | * How many attempts where made to run this job
|
146 | */
|
147 | attemptsMade: number;
|
148 |
|
149 | /**
|
150 | * When this job was started (unix milliseconds)
|
151 | */
|
152 | processedOn?: number | undefined;
|
153 |
|
154 | /**
|
155 | * When this job was completed (unix milliseconds)
|
156 | */
|
157 | finishedOn?: number | undefined;
|
158 |
|
159 | /**
|
160 | * Which queue this job was part of
|
161 | */
|
162 | queue: Queue<T>;
|
163 |
|
164 | timestamp: number;
|
165 |
|
166 | /**
|
167 | * The named processor name
|
168 | */
|
169 | name: string;
|
170 |
|
171 | /**
|
172 | * The stacktrace for any errors
|
173 | */
|
174 | stacktrace: string[];
|
175 |
|
176 | returnvalue: any;
|
177 |
|
178 | failedReason?: string | undefined;
|
179 |
|
180 | /**
|
181 | * Get progress on a job
|
182 | */
|
183 | progress(): any;
|
184 |
|
185 | /**
|
186 | * Report progress on a job
|
187 | */
|
188 | progress(value: any): Promise<void>;
|
189 |
|
190 | /**
|
191 | * Logs one row of log data.
|
192 | *
|
193 | * @param row String with log data to be logged.
|
194 | */
|
195 | log(row: string): Promise<any>;
|
196 |
|
197 | /**
|
198 | * Returns a promise resolving to a boolean which, if true, current job's state is completed
|
199 | */
|
200 | isCompleted(): Promise<boolean>;
|
201 |
|
202 | /**
|
203 | * Returns a promise resolving to a boolean which, if true, current job's state is failed
|
204 | */
|
205 | isFailed(): Promise<boolean>;
|
206 |
|
207 | /**
|
208 | * Returns a promise resolving to a boolean which, if true, current job's state is delayed
|
209 | */
|
210 | isDelayed(): Promise<boolean>;
|
211 |
|
212 | /**
|
213 | * Returns a promise resolving to a boolean which, if true, current job's state is active
|
214 | */
|
215 | isActive(): Promise<boolean>;
|
216 |
|
217 | /**
|
218 | * Returns a promise resolving to a boolean which, if true, current job's state is wait
|
219 | */
|
220 | isWaiting(): Promise<boolean>;
|
221 |
|
222 | /**
|
223 | * Returns a promise resolving to a boolean which, if true, current job's state is paused
|
224 | */
|
225 | isPaused(): Promise<boolean>;
|
226 |
|
227 | /**
|
228 | * Returns a promise resolving to a boolean which, if true, current job's state is stuck
|
229 | */
|
230 | isStuck(): Promise<boolean>;
|
231 |
|
232 | /**
|
233 | * Returns a promise resolving to the current job's status.
|
234 | * Please take note that the implementation of this method is not very efficient, nor is
|
235 | * it atomic. If your queue does have a very large quantity of jobs, you may want to
|
236 | * avoid using this method.
|
237 | */
|
238 | getState(): Promise<JobStatus | 'stuck'>;
|
239 |
|
240 | /**
|
241 | * Update a specific job's data. Promise resolves when the job has been updated.
|
242 | */
|
243 | update(data: T): Promise<void>;
|
244 |
|
245 | /**
|
246 | * Removes a job from the queue and from any lists it may be included in.
|
247 | * The returned promise resolves when the job has been removed.
|
248 | */
|
249 | remove(): Promise<void>;
|
250 |
|
251 | /**
|
252 | * Re-run a job that has failed. The returned promise resolves when the job
|
253 | * has been scheduled for retry.
|
254 | */
|
255 | retry(): Promise<void>;
|
256 |
|
257 | /**
|
258 | * Ensure this job is never ran again even if attemptsMade is less than job.attempts.
|
259 | */
|
260 | discard(): Promise<void>;
|
261 |
|
262 | /**
|
263 | * Returns a promise that resolves to the returned data when the job has been finished.
|
264 | * TODO: Add a watchdog to check if the job has finished periodically.
|
265 | * since pubsub does not give any guarantees.
|
266 | */
|
267 | finished(): Promise<any>;
|
268 |
|
269 | /**
|
270 | * Moves a job to the `completed` queue. Pulls a job from 'waiting' to 'active'
|
271 | * and returns a tuple containing the next jobs data and id. If no job is in the `waiting` queue, returns null.
|
272 | */
|
273 | moveToCompleted(returnValue?: string, ignoreLock?: boolean, notFetch?: boolean): Promise<[any, JobId] | null>;
|
274 |
|
275 | /**
|
276 | * Moves a job to the `failed` queue. Pulls a job from 'waiting' to 'active'
|
277 | * and returns a tuple containing the next jobs data and id. If no job is in the `waiting` queue, returns null.
|
278 | */
|
279 | moveToFailed(errorInfo: { message: string; }, ignoreLock?: boolean): Promise<[any, JobId] | null>;
|
280 |
|
281 | /**
|
282 | * Promotes a job that is currently "delayed" to the "waiting" state and executed as soon as possible.
|
283 | */
|
284 | promote(): Promise<void>;
|
285 |
|
286 | /**
|
287 | * The lock id of the job
|
288 | */
|
289 | lockKey(): string;
|
290 |
|
291 | /**
|
292 | * Releases the lock on the job. Only locks owned by the queue instance can be released.
|
293 | */
|
294 | releaseLock(): Promise<void>;
|
295 |
|
296 | /**
|
297 | * Takes a lock for this job so that no other queue worker can process it at the same time.
|
298 | */
|
299 | takeLock(): Promise<number | false>;
|
300 |
|
301 | /**
|
302 | * Get job properties as Json Object
|
303 | */
|
304 | toJSON(): {
|
305 | id: JobId,
|
306 | name: string,
|
307 | data: T,
|
308 | opts: JobOptions,
|
309 | progress: number,
|
310 | delay: number,
|
311 | timestamp: number,
|
312 | attemptsMade: number,
|
313 | failedReason: any,
|
314 | stacktrace: string[] | null,
|
315 | returnvalue: any,
|
316 | finishedOn: number | null,
|
317 | processedOn: number | null
|
318 | };
|
319 | }
|
320 |
|
321 | type JobStatus = 'completed' | 'waiting' | 'active' | 'delayed' | 'failed' | 'paused';
|
322 | type JobStatusClean = 'completed' | 'wait' | 'active' | 'delayed' | 'failed' | 'paused';
|
323 |
|
324 | interface BackoffOptions {
|
325 | /**
|
326 | * Backoff type, which can be either `fixed` or `exponential`
|
327 | */
|
328 | type: string;
|
329 |
|
330 | /**
|
331 | * Backoff delay, in milliseconds
|
332 | */
|
333 | delay?: number | undefined;
|
334 |
|
335 | /**
|
336 | * Options for custom strategies
|
337 | */
|
338 | strategyOptions?: any;
|
339 | }
|
340 |
|
341 | interface RepeatOptions {
|
342 | /**
|
343 | * Timezone
|
344 | */
|
345 | tz?: string | undefined;
|
346 |
|
347 | /**
|
348 | * End date when the repeat job should stop repeating
|
349 | */
|
350 | endDate?: Date | string | number | undefined;
|
351 |
|
352 | /**
|
353 | * Number of times the job should repeat at max.
|
354 | */
|
355 | limit?: number | undefined;
|
356 | }
|
357 |
|
358 | interface CronRepeatOptions extends RepeatOptions {
|
359 | /**
|
360 | * Cron pattern specifying when the job should execute
|
361 | */
|
362 | cron: string;
|
363 |
|
364 | /**
|
365 | * Start date when the repeat job should start repeating (only with cron).
|
366 | */
|
367 | startDate?: Date | string | number | undefined;
|
368 | }
|
369 |
|
370 | interface EveryRepeatOptions extends RepeatOptions {
|
371 | /**
|
372 | * Repeat every millis (cron setting cannot be used together with this setting.)
|
373 | */
|
374 | every: number;
|
375 | }
|
376 |
|
377 | interface JobOptions {
|
378 | /**
|
379 | * Optional priority value. ranges from 1 (highest priority) to MAX_INT (lowest priority).
|
380 | * Note that using priorities has a slight impact on performance, so do not use it if not required
|
381 | */
|
382 | priority?: number | undefined;
|
383 |
|
384 | /**
|
385 | * An amount of miliseconds to wait until this job can be processed.
|
386 | * Note that for accurate delays, both server and clients should have their clocks synchronized. [optional]
|
387 | */
|
388 | delay?: number | undefined;
|
389 |
|
390 | /**
|
391 | * The total number of attempts to try the job until it completes
|
392 | */
|
393 | attempts?: number | undefined;
|
394 |
|
395 | /**
|
396 | * Repeat job according to a cron specification
|
397 | */
|
398 | repeat?: CronRepeatOptions | EveryRepeatOptions | undefined;
|
399 |
|
400 | /**
|
401 | * Backoff setting for automatic retries if the job fails
|
402 | */
|
403 | backoff?: number | BackoffOptions | undefined;
|
404 |
|
405 | /**
|
406 | * A boolean which, if true, adds the job to the right
|
407 | * of the queue instead of the left (default false)
|
408 | */
|
409 | lifo?: boolean | undefined;
|
410 |
|
411 | /**
|
412 | * The number of milliseconds after which the job should be fail with a timeout error
|
413 | */
|
414 | timeout?: number | undefined;
|
415 |
|
416 | /**
|
417 | * Override the job ID - by default, the job ID is a unique
|
418 | * integer, but you can use this setting to override it.
|
419 | * If you use this option, it is up to you to ensure the
|
420 | * jobId is unique. If you attempt to add a job with an id that
|
421 | * already exists, it will not be added.
|
422 | */
|
423 | jobId?: JobId | undefined;
|
424 |
|
425 | /**
|
426 | * A boolean which, if true, removes the job when it successfully completes.
|
427 | * When a number, it specifies the amount of jobs to keep.
|
428 | * Default behavior is to keep the job in the completed set.
|
429 | * See KeepJobsOptions if using that interface instead.
|
430 | */
|
431 | removeOnComplete?: boolean | number | KeepJobsOptions |undefined;
|
432 |
|
433 | /**
|
434 | * A boolean which, if true, removes the job when it fails after all attempts.
|
435 | * When a number, it specifies the amount of jobs to keep.
|
436 | * Default behavior is to keep the job in the failed set.
|
437 | * See KeepJobsOptions if using that interface instead.
|
438 | */
|
439 | removeOnFail?: boolean | number | KeepJobsOptions | undefined;
|
440 |
|
441 | /**
|
442 | * Limits the amount of stack trace lines that will be recorded in the stacktrace.
|
443 | */
|
444 | stackTraceLimit?: number | undefined;
|
445 |
|
446 | /**
|
447 | * Prevents JSON data from being parsed.
|
448 | */
|
449 | preventParsingData?: boolean | undefined;
|
450 | }
|
451 |
|
452 | /**
|
453 | * Specify which jobs to keep after finishing processing this job.
|
454 | * If both age and count are specified, then the jobs kept will be the ones that satisfies both properties.
|
455 | */
|
456 | interface KeepJobsOptions {
|
457 | /**
|
458 | * Maximum age in *seconds* for job to be kept.
|
459 | */
|
460 | age?: number | undefined;
|
461 |
|
462 | /**
|
463 | * Maximum count of jobs to be kept.
|
464 | */
|
465 | count?: number | undefined;
|
466 | }
|
467 |
|
468 | interface JobCounts {
|
469 | active: number;
|
470 | completed: number;
|
471 | failed: number;
|
472 | delayed: number;
|
473 | waiting: number;
|
474 | }
|
475 |
|
476 | interface JobInformation {
|
477 | key: string;
|
478 | name: string;
|
479 | id?: string | undefined;
|
480 | endDate?: number | undefined;
|
481 | tz?: string | undefined;
|
482 | cron: string;
|
483 | every: number;
|
484 | next: number;
|
485 | }
|
486 |
|
487 | interface Queue<T = any> extends EventEmitter {
|
488 | /**
|
489 | * The name of the queue
|
490 | */
|
491 | name: string;
|
492 |
|
493 | /**
|
494 | * Queue client (used to add jobs, pause queues, etc);
|
495 | */
|
496 | client: Redis.Redis;
|
497 |
|
498 | /**
|
499 | * Returns a promise that resolves when Redis is connected and the queue is ready to accept jobs.
|
500 | * This replaces the `ready` event emitted on Queue in previous verisons.
|
501 | */
|
502 | isReady(): Promise<this>;
|
503 |
|
504 | /* tslint:disable:unified-signatures */
|
505 |
|
506 | /**
|
507 | * Defines a processing function for the jobs placed into a given Queue.
|
508 | *
|
509 | * The callback is called everytime a job is placed in the queue.
|
510 | * It is passed an instance of the job as first argument.
|
511 | *
|
512 | * If the callback signature contains the second optional done argument,
|
513 | * the callback will be passed a done callback to be called after the job has been completed.
|
514 | * The done callback can be called with an Error instance, to signal that the job did not complete successfully,
|
515 | * or with a result as second argument (e.g.: done(null, result);) when the job is successful.
|
516 | * Errors will be passed as a second argument to the "failed" event; results, as a second argument to the "completed" event.
|
517 | *
|
518 | * If, however, the callback signature does not contain the done argument,
|
519 | * a promise must be returned to signal job completion.
|
520 | * If the promise is rejected, the error will be passed as a second argument to the "failed" event.
|
521 | * If it is resolved, its value will be the "completed" event's second argument.
|
522 | */
|
523 | process(callback: ProcessCallbackFunction<T>): Promise<void>;
|
524 | process(callback: ProcessPromiseFunction<T>): Promise<void>;
|
525 | process(callback: string): Promise<void>;
|
526 |
|
527 | /**
|
528 | * Defines a processing function for the jobs placed into a given Queue.
|
529 | *
|
530 | * The callback is called everytime a job is placed in the queue.
|
531 | * It is passed an instance of the job as first argument.
|
532 | *
|
533 | * If the callback signature contains the second optional done argument,
|
534 | * the callback will be passed a done callback to be called after the job has been completed.
|
535 | * The done callback can be called with an Error instance, to signal that the job did not complete successfully,
|
536 | * or with a result as second argument (e.g.: done(null, result);) when the job is successful.
|
537 | * Errors will be passed as a second argument to the "failed" event; results, as a second argument to the "completed" event.
|
538 | *
|
539 | * If, however, the callback signature does not contain the done argument,
|
540 | * a promise must be returned to signal job completion.
|
541 | * If the promise is rejected, the error will be passed as a second argument to the "failed" event.
|
542 | * If it is resolved, its value will be the "completed" event's second argument.
|
543 | *
|
544 | * @param concurrency Bull will then call your handler in parallel respecting this maximum value.
|
545 | */
|
546 | process(concurrency: number, callback: ProcessCallbackFunction<T>): Promise<void>;
|
547 | process(concurrency: number, callback: ProcessPromiseFunction<T>): Promise<void>;
|
548 | process(concurrency: number, callback: string): Promise<void>;
|
549 |
|
550 | /**
|
551 | * Defines a processing function for the jobs placed into a given Queue.
|
552 | *
|
553 | * The callback is called everytime a job is placed in the queue.
|
554 | * It is passed an instance of the job as first argument.
|
555 | *
|
556 | * If the callback signature contains the second optional done argument,
|
557 | * the callback will be passed a done callback to be called after the job has been completed.
|
558 | * The done callback can be called with an Error instance, to signal that the job did not complete successfully,
|
559 | * or with a result as second argument (e.g.: done(null, result);) when the job is successful.
|
560 | * Errors will be passed as a second argument to the "failed" event; results, as a second argument to the "completed" event.
|
561 | *
|
562 | * If, however, the callback signature does not contain the done argument,
|
563 | * a promise must be returned to signal job completion.
|
564 | * If the promise is rejected, the error will be passed as a second argument to the "failed" event.
|
565 | * If it is resolved, its value will be the "completed" event's second argument.
|
566 | *
|
567 | * @param name Bull will only call the handler if the job name matches
|
568 | */
|
569 | process(name: string, callback: ProcessCallbackFunction<T>): Promise<void>;
|
570 | process(name: string, callback: ProcessPromiseFunction<T>): Promise<void>;
|
571 | process(name: string, callback: string): Promise<void>;
|
572 |
|
573 | /**
|
574 | * Defines a processing function for the jobs placed into a given Queue.
|
575 | *
|
576 | * The callback is called everytime a job is placed in the queue.
|
577 | * It is passed an instance of the job as first argument.
|
578 | *
|
579 | * If the callback signature contains the second optional done argument,
|
580 | * the callback will be passed a done callback to be called after the job has been completed.
|
581 | * The done callback can be called with an Error instance, to signal that the job did not complete successfully,
|
582 | * or with a result as second argument (e.g.: done(null, result);) when the job is successful.
|
583 | * Errors will be passed as a second argument to the "failed" event; results, as a second argument to the "completed" event.
|
584 | *
|
585 | * If, however, the callback signature does not contain the done argument,
|
586 | * a promise must be returned to signal job completion.
|
587 | * If the promise is rejected, the error will be passed as a second argument to the "failed" event.
|
588 | * If it is resolved, its value will be the "completed" event's second argument.
|
589 | *
|
590 | * @param name Bull will only call the handler if the job name matches
|
591 | * @param concurrency Bull will then call your handler in parallel respecting this maximum value.
|
592 | */
|
593 | process(name: string, concurrency: number, callback: ProcessCallbackFunction<T>): Promise<void>;
|
594 | process(name: string, concurrency: number, callback: ProcessPromiseFunction<T>): Promise<void>;
|
595 | process(name: string, concurrency: number, callback: string): Promise<void>;
|
596 |
|
597 | /* tslint:enable:unified-signatures */
|
598 |
|
599 | /**
|
600 | * Creates a new job and adds it to the queue.
|
601 | * If the queue is empty the job will be executed directly,
|
602 | * otherwise it will be placed in the queue and executed as soon as possible.
|
603 | */
|
604 | add(data: T, opts?: JobOptions): Promise<Job<T>>;
|
605 |
|
606 | /**
|
607 | * Creates a new named job and adds it to the queue.
|
608 | * If the queue is empty the job will be executed directly,
|
609 | * otherwise it will be placed in the queue and executed as soon as possible.
|
610 | */
|
611 | add(name: string, data: T, opts?: JobOptions): Promise<Job<T>>;
|
612 |
|
613 | /**
|
614 | * Adds an array of jobs to the queue.
|
615 | * If the queue is empty the jobs will be executed directly,
|
616 | * otherwise they will be placed in the queue and executed as soon as possible.
|
617 | * 'repeat' option is not supported in addBulk https://github.com/OptimalBits/bull/issues/1731
|
618 | */
|
619 | addBulk(jobs: Array<{name?: string | undefined, data: T, opts?: Omit<JobOptions, "repeat"> | undefined}>): Promise<Array<Job<T>>>;
|
620 |
|
621 | /**
|
622 | * Returns a promise that resolves when the queue is paused.
|
623 | *
|
624 | * A paused queue will not process new jobs until resumed, but current jobs being processed will continue until
|
625 | * they are finalized. The pause can be either global or local. If global, all workers in all queue instances
|
626 | * for a given queue will be paused. If local, just this worker will stop processing new jobs after the current
|
627 | * lock expires. This can be useful to stop a worker from taking new jobs prior to shutting down.
|
628 | *
|
629 | * If doNotWaitActive is true, pause will not wait for any active jobs to finish before resolving. Otherwise, pause
|
630 | * will wait for active jobs to finish. See Queue#whenCurrentJobsFinished for more information.
|
631 | *
|
632 | * Pausing a queue that is already paused does nothing.
|
633 | */
|
634 | pause(isLocal?: boolean, doNotWaitActive?: boolean): Promise<void>;
|
635 |
|
636 | /**
|
637 | * Returns a promise that resolves when the queue is resumed after being paused.
|
638 | *
|
639 | * The resume can be either local or global. If global, all workers in all queue instances for a given queue
|
640 | * will be resumed. If local, only this worker will be resumed. Note that resuming a queue globally will not
|
641 | * resume workers that have been paused locally; for those, resume(true) must be called directly on their
|
642 | * instances.
|
643 | *
|
644 | * Resuming a queue that is not paused does nothing.
|
645 | */
|
646 | resume(isLocal?: boolean): Promise<void>;
|
647 |
|
648 | /**
|
649 | * Returns a promise that resolves with a boolean if queue is paused
|
650 | */
|
651 | isPaused(isLocal?: boolean): Promise<boolean>;
|
652 |
|
653 | /**
|
654 | * Returns a promise that returns the number of jobs in the queue, waiting or paused.
|
655 | * Since there may be other processes adding or processing jobs, this value may be true only for a very small amount of time.
|
656 | */
|
657 | count(): Promise<number>;
|
658 |
|
659 | /**
|
660 | * Empties a queue deleting all the input lists and associated jobs.
|
661 | */
|
662 | empty(): Promise<void>;
|
663 |
|
664 | /**
|
665 | * Closes the underlying redis client. Use this to perform a graceful shutdown.
|
666 | *
|
667 | * `close` can be called from anywhere, with one caveat:
|
668 | * if called from within a job handler the queue won't close until after the job has been processed
|
669 | */
|
670 | close(doNotWaitJobs?: boolean): Promise<void>;
|
671 |
|
672 | /**
|
673 | * Returns a promise that will return the job instance associated with the jobId parameter.
|
674 | * If the specified job cannot be located, the promise callback parameter will be set to null.
|
675 | */
|
676 | getJob(jobId: JobId): Promise<Job<T> | null>;
|
677 |
|
678 | /**
|
679 | * Returns a promise that will return an array with the waiting jobs between start and end.
|
680 | */
|
681 | getWaiting(start?: number, end?: number): Promise<Array<Job<T>>>;
|
682 |
|
683 | /**
|
684 | * Returns a promise that will return an array with the active jobs between start and end.
|
685 | */
|
686 | getActive(start?: number, end?: number): Promise<Array<Job<T>>>;
|
687 |
|
688 | /**
|
689 | * Returns a promise that will return an array with the delayed jobs between start and end.
|
690 | */
|
691 | getDelayed(start?: number, end?: number): Promise<Array<Job<T>>>;
|
692 |
|
693 | /**
|
694 | * Returns a promise that will return an array with the completed jobs between start and end.
|
695 | */
|
696 | getCompleted(start?: number, end?: number): Promise<Array<Job<T>>>;
|
697 |
|
698 | /**
|
699 | * Returns a promise that will return an array with the failed jobs between start and end.
|
700 | */
|
701 | getFailed(start?: number, end?: number): Promise<Array<Job<T>>>;
|
702 |
|
703 | /**
|
704 | * Returns JobInformation of repeatable jobs (ordered descending). Provide a start and/or an end
|
705 | * index to limit the number of results. Start defaults to 0, end to -1 and asc to false.
|
706 | */
|
707 | getRepeatableJobs(start?: number, end?: number, asc?: boolean): Promise<JobInformation[]>;
|
708 |
|
709 | /**
|
710 | * ???
|
711 | */
|
712 | nextRepeatableJob(name: string, data: any, opts: JobOptions): Promise<Job<T>>;
|
713 |
|
714 | /**
|
715 | * Removes a given repeatable job. The RepeatOptions and JobId needs to be the same as the ones
|
716 | * used for the job when it was added.
|
717 | */
|
718 | removeRepeatable(repeat: (CronRepeatOptions | EveryRepeatOptions) & { jobId?: JobId | undefined }): Promise<void>;
|
719 |
|
720 | /**
|
721 | * Removes a given repeatable job. The RepeatOptions and JobId needs to be the same as the ones
|
722 | * used for the job when it was added.
|
723 | *
|
724 | * name: The name of the to be removed job
|
725 | */
|
726 | removeRepeatable(name: string, repeat: (CronRepeatOptions | EveryRepeatOptions) & { jobId?: JobId | undefined }): Promise<void>;
|
727 |
|
728 | /**
|
729 | * Removes a given repeatable job by key.
|
730 | */
|
731 | removeRepeatableByKey(key: string): Promise<void>;
|
732 |
|
733 | /**
|
734 | * Returns a promise that will return an array of job instances of the given job statuses.
|
735 | * Optional parameters for range and ordering are provided.
|
736 | */
|
737 | getJobs(types: JobStatus[], start?: number, end?: number, asc?: boolean): Promise<Array<Job<T>>>;
|
738 |
|
739 | /**
|
740 | * Returns a promise that resolves to the next job in queue.
|
741 | */
|
742 | getNextJob(): Promise<Job<T> | undefined>;
|
743 |
|
744 | /**
|
745 | * Returns a object with the logs according to the start and end arguments. The returned count
|
746 | * value is the total amount of logs, useful for implementing pagination.
|
747 | */
|
748 | getJobLogs(jobId: JobId, start?: number, end?: number): Promise<{ logs: string[], count: number }>;
|
749 |
|
750 | /**
|
751 | * Returns a promise that resolves with the job counts for the given queue.
|
752 | */
|
753 | getJobCounts(): Promise<JobCounts>;
|
754 |
|
755 | /**
|
756 | * Returns a promise that resolves with the job counts for the given queue of the given job statuses.
|
757 | */
|
758 | getJobCountByTypes(types: JobStatus[] | JobStatus): Promise<JobCounts>;
|
759 |
|
760 | /**
|
761 | * Returns a promise that resolves with the quantity of completed jobs.
|
762 | */
|
763 | getCompletedCount(): Promise<number>;
|
764 |
|
765 | /**
|
766 | * Returns a promise that resolves with the quantity of failed jobs.
|
767 | */
|
768 | getFailedCount(): Promise<number>;
|
769 |
|
770 | /**
|
771 | * Returns a promise that resolves with the quantity of delayed jobs.
|
772 | */
|
773 | getDelayedCount(): Promise<number>;
|
774 |
|
775 | /**
|
776 | * Returns a promise that resolves with the quantity of waiting jobs.
|
777 | */
|
778 | getWaitingCount(): Promise<number>;
|
779 |
|
780 | /**
|
781 | * Returns a promise that resolves with the quantity of paused jobs.
|
782 | */
|
783 | getPausedCount(): Promise<number>;
|
784 |
|
785 | /**
|
786 | * Returns a promise that resolves with the quantity of active jobs.
|
787 | */
|
788 | getActiveCount(): Promise<number>;
|
789 |
|
790 | /**
|
791 | * Returns a promise that resolves to the quantity of repeatable jobs.
|
792 | */
|
793 | getRepeatableCount(): Promise<number>;
|
794 |
|
795 | /**
|
796 | * Tells the queue remove all jobs created outside of a grace period in milliseconds.
|
797 | * You can clean the jobs with the following states: completed, wait (typo for waiting), active, delayed, and failed.
|
798 | * @param grace Grace period in milliseconds.
|
799 | * @param status Status of the job to clean. Values are completed, wait, active, delayed, and failed. Defaults to completed.
|
800 | * @param limit Maximum amount of jobs to clean per call. If not provided will clean all matching jobs.
|
801 | */
|
802 | clean(grace: number, status?: JobStatusClean, limit?: number): Promise<Array<Job<T>>>;
|
803 |
|
804 | /**
|
805 | * Returns a promise that marks the start of a transaction block.
|
806 | */
|
807 | multi(): Redis.Pipeline;
|
808 |
|
809 | /**
|
810 | * Returns the queue specific key.
|
811 | */
|
812 | toKey(queueType: string): string;
|
813 |
|
814 | /**
|
815 | * Completely destroys the queue and all of its contents irreversibly.
|
816 | * @param ops.force Obliterate the queue even if there are active jobs
|
817 | */
|
818 | obliterate(ops?: { force: boolean}): Promise<void>;
|
819 |
|
820 | /**
|
821 | * Listens to queue events
|
822 | */
|
823 | on(event: string, callback: (...args: any[]) => void): this;
|
824 |
|
825 | /**
|
826 | * An error occured
|
827 | */
|
828 | on(event: 'error', callback: ErrorEventCallback): this;
|
829 |
|
830 | /**
|
831 | * A Job is waiting to be processed as soon as a worker is idling.
|
832 | */
|
833 | on(event: 'waiting', callback: WaitingEventCallback): this;
|
834 |
|
835 | /**
|
836 | * A job has started. You can use `jobPromise.cancel()` to abort it
|
837 | */
|
838 | on(event: 'active', callback: ActiveEventCallback<T>): this;
|
839 |
|
840 | /**
|
841 | * A job has been marked as stalled.
|
842 | * This is useful for debugging job workers that crash or pause the event loop.
|
843 | */
|
844 | on(event: 'stalled', callback: StalledEventCallback<T>): this;
|
845 |
|
846 | /**
|
847 | * A job's progress was updated
|
848 | */
|
849 | on(event: 'progress', callback: ProgressEventCallback<T>): this;
|
850 |
|
851 | /**
|
852 | * A job successfully completed with a `result`
|
853 | */
|
854 | on(event: 'completed', callback: CompletedEventCallback<T>): this;
|
855 |
|
856 | /**
|
857 | * A job failed with `err` as the reason
|
858 | */
|
859 | on(event: 'failed', callback: FailedEventCallback<T>): this;
|
860 |
|
861 | /**
|
862 | * The queue has been paused
|
863 | */
|
864 | on(event: 'paused', callback: EventCallback): this;
|
865 |
|
866 | /**
|
867 | * The queue has been resumed
|
868 | */
|
869 | on(event: 'resumed', callback: EventCallback): this; // tslint:disable-line unified-signatures
|
870 |
|
871 | /**
|
872 | * A job successfully removed.
|
873 | */
|
874 | on(event: 'removed', callback: RemovedEventCallback<T>): this;
|
875 |
|
876 | /**
|
877 | * Old jobs have been cleaned from the queue.
|
878 | * `jobs` is an array of jobs that were removed, and `type` is the type of those jobs.
|
879 | *
|
880 | * @see Queue#clean() for details
|
881 | */
|
882 | on(event: 'cleaned', callback: CleanedEventCallback<T>): this;
|
883 |
|
884 | /**
|
885 | * Emitted every time the queue has processed all the waiting jobs
|
886 | * (even if there can be some delayed jobs not yet processed)
|
887 | */
|
888 | on(event: 'drained', callback: EventCallback): this; // tslint:disable-line unified-signatures
|
889 |
|
890 | /**
|
891 | * Array of Redis clients the queue uses
|
892 | */
|
893 | clients: Redis.Redis[];
|
894 |
|
895 | /**
|
896 | * Set clientName to Redis.client
|
897 | */
|
898 | setWorkerName(): Promise<any>;
|
899 |
|
900 | /**
|
901 | * Returns Redis clients array which belongs to current Queue
|
902 | */
|
903 | getWorkers(): Promise<Redis.Redis[]>;
|
904 |
|
905 | /**
|
906 | * Returns Queue name in base64 encoded format
|
907 | */
|
908 | base64Name(): string;
|
909 |
|
910 | /**
|
911 | * Returns Queue name with keyPrefix (default: 'bull')
|
912 | */
|
913 | clientName(): string;
|
914 |
|
915 | /**
|
916 | * Returns Redis clients array which belongs to current Queue from string with all redis clients
|
917 | *
|
918 | * @param list String with all redis clients
|
919 | */
|
920 | parseClientList(list: string): Redis.Redis[];
|
921 |
|
922 | /**
|
923 | * Returns a promise that resolves when active jobs are finished
|
924 | */
|
925 | whenCurrentJobsFinished(): Promise<void>;
|
926 |
|
927 | /**
|
928 | * Removes all the jobs which jobId matches the given pattern. The pattern must follow redis glob-style pattern
|
929 | * (syntax)[redis.io/commands/keys]
|
930 | */
|
931 | removeJobs(pattern: string): Promise<void>;
|
932 | }
|
933 |
|
934 | type EventCallback = () => void;
|
935 |
|
936 | type ErrorEventCallback = (error: Error) => void;
|
937 |
|
938 | interface JobPromise {
|
939 | /**
|
940 | * Abort this job
|
941 | */
|
942 | cancel(): void;
|
943 | }
|
944 |
|
945 | type ActiveEventCallback<T = any> = (job: Job<T>, jobPromise?: JobPromise) => void;
|
946 |
|
947 | type StalledEventCallback<T = any> = (job: Job<T>) => void;
|
948 |
|
949 | type ProgressEventCallback<T = any> = (job: Job<T>, progress: any) => void;
|
950 |
|
951 | type CompletedEventCallback<T = any> = (job: Job<T>, result: any) => void;
|
952 |
|
953 | type FailedEventCallback<T = any> = (job: Job<T>, error: Error) => void;
|
954 |
|
955 | type CleanedEventCallback<T = any> = (jobs: Array<Job<T>>, status: JobStatusClean) => void;
|
956 |
|
957 | type RemovedEventCallback<T = any> = (job: Job<T>) => void;
|
958 |
|
959 | type WaitingEventCallback = (jobId: JobId) => void;
|
960 | }
|
961 |
|
962 | export = Bull;
|