UNPKG

33 kBTypeScriptView Raw
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
25import * as Redis from "ioredis";
26import { 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 */
33declare 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
42declare 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) => 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 interface RepeatOptions {
337 /**
338 * Timezone
339 */
340 tz?: string | undefined;
341
342 /**
343 * End date when the repeat job should stop repeating
344 */
345 endDate?: Date | string | number | undefined;
346
347 /**
348 * Number of times the job should repeat at max.
349 */
350 limit?: number | undefined;
351 }
352
353 interface CronRepeatOptions extends RepeatOptions {
354 /**
355 * Cron pattern specifying when the job should execute
356 */
357 cron: string;
358
359 /**
360 * Start date when the repeat job should start repeating (only with cron).
361 */
362 startDate?: Date | string | number | undefined;
363 }
364
365 interface EveryRepeatOptions extends RepeatOptions {
366 /**
367 * Repeat every millis (cron setting cannot be used together with this setting.)
368 */
369 every: number;
370 }
371
372 interface JobOptions {
373 /**
374 * Optional priority value. ranges from 1 (highest priority) to MAX_INT (lowest priority).
375 * Note that using priorities has a slight impact on performance, so do not use it if not required
376 */
377 priority?: number | undefined;
378
379 /**
380 * An amount of miliseconds to wait until this job can be processed.
381 * Note that for accurate delays, both server and clients should have their clocks synchronized. [optional]
382 */
383 delay?: number | undefined;
384
385 /**
386 * The total number of attempts to try the job until it completes
387 */
388 attempts?: number | undefined;
389
390 /**
391 * Repeat job according to a cron specification
392 */
393 repeat?: CronRepeatOptions | EveryRepeatOptions | undefined;
394
395 /**
396 * Backoff setting for automatic retries if the job fails
397 */
398 backoff?: number | BackoffOptions | undefined;
399
400 /**
401 * A boolean which, if true, adds the job to the right
402 * of the queue instead of the left (default false)
403 */
404 lifo?: boolean | undefined;
405
406 /**
407 * The number of milliseconds after which the job should be fail with a timeout error
408 */
409 timeout?: number | undefined;
410
411 /**
412 * Override the job ID - by default, the job ID is a unique
413 * integer, but you can use this setting to override it.
414 * If you use this option, it is up to you to ensure the
415 * jobId is unique. If you attempt to add a job with an id that
416 * already exists, it will not be added.
417 */
418 jobId?: JobId | undefined;
419
420 /**
421 * A boolean which, if true, removes the job when it successfully completes.
422 * When a number, it specifies the amount of jobs to keep.
423 * Default behavior is to keep the job in the completed set.
424 * See KeepJobsOptions if using that interface instead.
425 */
426 removeOnComplete?: boolean | number | KeepJobsOptions |undefined;
427
428 /**
429 * A boolean which, if true, removes the job when it fails after all attempts.
430 * When a number, it specifies the amount of jobs to keep.
431 * Default behavior is to keep the job in the failed set.
432 * See KeepJobsOptions if using that interface instead.
433 */
434 removeOnFail?: boolean | number | KeepJobsOptions | undefined;
435
436 /**
437 * Limits the amount of stack trace lines that will be recorded in the stacktrace.
438 */
439 stackTraceLimit?: number | undefined;
440
441 /**
442 * Prevents JSON data from being parsed.
443 */
444 preventParsingData?: boolean | undefined;
445 }
446
447 /**
448 * Specify which jobs to keep after finishing processing this job.
449 * If both age and count are specified, then the jobs kept will be the ones that satisfies both properties.
450 */
451 interface KeepJobsOptions {
452 /**
453 * Maximum age in *seconds* for job to be kept.
454 */
455 age?: number | undefined;
456
457 /**
458 * Maximum count of jobs to be kept.
459 */
460 count?: number | undefined;
461 }
462
463 interface JobCounts {
464 active: number;
465 completed: number;
466 failed: number;
467 delayed: number;
468 waiting: number;
469 }
470
471 interface JobInformation {
472 key: string;
473 name: string;
474 id?: string | undefined;
475 endDate?: number | undefined;
476 tz?: string | undefined;
477 cron: string;
478 every: number;
479 next: number;
480 }
481
482 interface Queue<T = any> extends EventEmitter {
483 /**
484 * The name of the queue
485 */
486 name: string;
487
488 /**
489 * Queue client (used to add jobs, pause queues, etc);
490 */
491 client: Redis.Redis;
492
493 /**
494 * Returns a promise that resolves when Redis is connected and the queue is ready to accept jobs.
495 * This replaces the `ready` event emitted on Queue in previous verisons.
496 */
497 isReady(): Promise<this>;
498
499 /* tslint:disable:unified-signatures */
500
501 /**
502 * Defines a processing function for the jobs placed into a given Queue.
503 *
504 * The callback is called everytime a job is placed in the queue.
505 * It is passed an instance of the job as first argument.
506 *
507 * If the callback signature contains the second optional done argument,
508 * the callback will be passed a done callback to be called after the job has been completed.
509 * The done callback can be called with an Error instance, to signal that the job did not complete successfully,
510 * or with a result as second argument (e.g.: done(null, result);) when the job is successful.
511 * Errors will be passed as a second argument to the "failed" event; results, as a second argument to the "completed" event.
512 *
513 * If, however, the callback signature does not contain the done argument,
514 * a promise must be returned to signal job completion.
515 * If the promise is rejected, the error will be passed as a second argument to the "failed" event.
516 * If it is resolved, its value will be the "completed" event's second argument.
517 */
518 process(callback: ProcessCallbackFunction<T>): Promise<void>;
519 process(callback: ProcessPromiseFunction<T>): Promise<void>;
520 process(callback: string): Promise<void>;
521
522 /**
523 * Defines a processing function for the jobs placed into a given Queue.
524 *
525 * The callback is called everytime a job is placed in the queue.
526 * It is passed an instance of the job as first argument.
527 *
528 * If the callback signature contains the second optional done argument,
529 * the callback will be passed a done callback to be called after the job has been completed.
530 * The done callback can be called with an Error instance, to signal that the job did not complete successfully,
531 * or with a result as second argument (e.g.: done(null, result);) when the job is successful.
532 * Errors will be passed as a second argument to the "failed" event; results, as a second argument to the "completed" event.
533 *
534 * If, however, the callback signature does not contain the done argument,
535 * a promise must be returned to signal job completion.
536 * If the promise is rejected, the error will be passed as a second argument to the "failed" event.
537 * If it is resolved, its value will be the "completed" event's second argument.
538 *
539 * @param concurrency Bull will then call your handler in parallel respecting this maximum value.
540 */
541 process(concurrency: number, callback: ProcessCallbackFunction<T>): Promise<void>;
542 process(concurrency: number, callback: ProcessPromiseFunction<T>): Promise<void>;
543 process(concurrency: number, callback: string): Promise<void>;
544
545 /**
546 * Defines a processing function for the jobs placed into a given Queue.
547 *
548 * The callback is called everytime a job is placed in the queue.
549 * It is passed an instance of the job as first argument.
550 *
551 * If the callback signature contains the second optional done argument,
552 * the callback will be passed a done callback to be called after the job has been completed.
553 * The done callback can be called with an Error instance, to signal that the job did not complete successfully,
554 * or with a result as second argument (e.g.: done(null, result);) when the job is successful.
555 * Errors will be passed as a second argument to the "failed" event; results, as a second argument to the "completed" event.
556 *
557 * If, however, the callback signature does not contain the done argument,
558 * a promise must be returned to signal job completion.
559 * If the promise is rejected, the error will be passed as a second argument to the "failed" event.
560 * If it is resolved, its value will be the "completed" event's second argument.
561 *
562 * @param name Bull will only call the handler if the job name matches
563 */
564 process(name: string, callback: ProcessCallbackFunction<T>): Promise<void>;
565 process(name: string, callback: ProcessPromiseFunction<T>): Promise<void>;
566 process(name: string, callback: string): Promise<void>;
567
568 /**
569 * Defines a processing function for the jobs placed into a given Queue.
570 *
571 * The callback is called everytime a job is placed in the queue.
572 * It is passed an instance of the job as first argument.
573 *
574 * If the callback signature contains the second optional done argument,
575 * the callback will be passed a done callback to be called after the job has been completed.
576 * The done callback can be called with an Error instance, to signal that the job did not complete successfully,
577 * or with a result as second argument (e.g.: done(null, result);) when the job is successful.
578 * Errors will be passed as a second argument to the "failed" event; results, as a second argument to the "completed" event.
579 *
580 * If, however, the callback signature does not contain the done argument,
581 * a promise must be returned to signal job completion.
582 * If the promise is rejected, the error will be passed as a second argument to the "failed" event.
583 * If it is resolved, its value will be the "completed" event's second argument.
584 *
585 * @param name Bull will only call the handler if the job name matches
586 * @param concurrency Bull will then call your handler in parallel respecting this maximum value.
587 */
588 process(name: string, concurrency: number, callback: ProcessCallbackFunction<T>): Promise<void>;
589 process(name: string, concurrency: number, callback: ProcessPromiseFunction<T>): Promise<void>;
590 process(name: string, concurrency: number, callback: string): Promise<void>;
591
592 /* tslint:enable:unified-signatures */
593
594 /**
595 * Creates a new job and adds it to the queue.
596 * If the queue is empty the job will be executed directly,
597 * otherwise it will be placed in the queue and executed as soon as possible.
598 */
599 add(data: T, opts?: JobOptions): Promise<Job<T>>;
600
601 /**
602 * Creates a new named job and adds it to the queue.
603 * If the queue is empty the job will be executed directly,
604 * otherwise it will be placed in the queue and executed as soon as possible.
605 */
606 add(name: string, data: T, opts?: JobOptions): Promise<Job<T>>;
607
608 /**
609 * Adds an array of jobs to the queue.
610 * If the queue is empty the jobs will be executed directly,
611 * otherwise they will be placed in the queue and executed as soon as possible.
612 * 'repeat' option is not supported in addBulk https://github.com/OptimalBits/bull/issues/1731
613 */
614 addBulk(jobs: Array<{name?: string | undefined, data: T, opts?: Omit<JobOptions, "repeat"> | undefined}>): Promise<Array<Job<T>>>;
615
616 /**
617 * Returns a promise that resolves when the queue is paused.
618 *
619 * A paused queue will not process new jobs until resumed, but current jobs being processed will continue until
620 * they are finalized. The pause can be either global or local. If global, all workers in all queue instances
621 * for a given queue will be paused. If local, just this worker will stop processing new jobs after the current
622 * lock expires. This can be useful to stop a worker from taking new jobs prior to shutting down.
623 *
624 * If doNotWaitActive is true, pause will not wait for any active jobs to finish before resolving. Otherwise, pause
625 * will wait for active jobs to finish. See Queue#whenCurrentJobsFinished for more information.
626 *
627 * Pausing a queue that is already paused does nothing.
628 */
629 pause(isLocal?: boolean, doNotWaitActive?: boolean): Promise<void>;
630
631 /**
632 * Returns a promise that resolves when the queue is resumed after being paused.
633 *
634 * The resume can be either local or global. If global, all workers in all queue instances for a given queue
635 * will be resumed. If local, only this worker will be resumed. Note that resuming a queue globally will not
636 * resume workers that have been paused locally; for those, resume(true) must be called directly on their
637 * instances.
638 *
639 * Resuming a queue that is not paused does nothing.
640 */
641 resume(isLocal?: boolean): Promise<void>;
642
643 /**
644 * Returns a promise that resolves with a boolean if queue is paused
645 */
646 isPaused(isLocal?: boolean): Promise<boolean>;
647
648 /**
649 * Returns a promise that returns the number of jobs in the queue, waiting or paused.
650 * Since there may be other processes adding or processing jobs, this value may be true only for a very small amount of time.
651 */
652 count(): Promise<number>;
653
654 /**
655 * Empties a queue deleting all the input lists and associated jobs.
656 */
657 empty(): Promise<void>;
658
659 /**
660 * Closes the underlying redis client. Use this to perform a graceful shutdown.
661 *
662 * `close` can be called from anywhere, with one caveat:
663 * if called from within a job handler the queue won't close until after the job has been processed
664 */
665 close(doNotWaitJobs?: boolean): Promise<void>;
666
667 /**
668 * Returns a promise that will return the job instance associated with the jobId parameter.
669 * If the specified job cannot be located, the promise callback parameter will be set to null.
670 */
671 getJob(jobId: JobId): Promise<Job<T> | null>;
672
673 /**
674 * Returns a promise that will return an array with the waiting jobs between start and end.
675 */
676 getWaiting(start?: number, end?: number): Promise<Array<Job<T>>>;
677
678 /**
679 * Returns a promise that will return an array with the active jobs between start and end.
680 */
681 getActive(start?: number, end?: number): Promise<Array<Job<T>>>;
682
683 /**
684 * Returns a promise that will return an array with the delayed jobs between start and end.
685 */
686 getDelayed(start?: number, end?: number): Promise<Array<Job<T>>>;
687
688 /**
689 * Returns a promise that will return an array with the completed jobs between start and end.
690 */
691 getCompleted(start?: number, end?: number): Promise<Array<Job<T>>>;
692
693 /**
694 * Returns a promise that will return an array with the failed jobs between start and end.
695 */
696 getFailed(start?: number, end?: number): Promise<Array<Job<T>>>;
697
698 /**
699 * Returns JobInformation of repeatable jobs (ordered descending). Provide a start and/or an end
700 * index to limit the number of results. Start defaults to 0, end to -1 and asc to false.
701 */
702 getRepeatableJobs(start?: number, end?: number, asc?: boolean): Promise<JobInformation[]>;
703
704 /**
705 * ???
706 */
707 nextRepeatableJob(name: string, data: any, opts: JobOptions): Promise<Job<T>>;
708
709 /**
710 * Removes a given repeatable job. The RepeatOptions and JobId needs to be the same as the ones
711 * used for the job when it was added.
712 */
713 removeRepeatable(repeat: (CronRepeatOptions | EveryRepeatOptions) & { jobId?: JobId | undefined }): Promise<void>;
714
715 /**
716 * Removes a given repeatable job. The RepeatOptions and JobId needs to be the same as the ones
717 * used for the job when it was added.
718 *
719 * name: The name of the to be removed job
720 */
721 removeRepeatable(name: string, repeat: (CronRepeatOptions | EveryRepeatOptions) & { jobId?: JobId | undefined }): Promise<void>;
722
723 /**
724 * Removes a given repeatable job by key.
725 */
726 removeRepeatableByKey(key: string): Promise<void>;
727
728 /**
729 * Returns a promise that will return an array of job instances of the given job statuses.
730 * Optional parameters for range and ordering are provided.
731 */
732 getJobs(types: JobStatus[], start?: number, end?: number, asc?: boolean): Promise<Array<Job<T>>>;
733
734 /**
735 * Returns a promise that resolves to the next job in queue.
736 */
737 getNextJob(): Promise<Job<T> | undefined>;
738
739 /**
740 * Returns a object with the logs according to the start and end arguments. The returned count
741 * value is the total amount of logs, useful for implementing pagination.
742 */
743 getJobLogs(jobId: JobId, start?: number, end?: number): Promise<{ logs: string[], count: number }>;
744
745 /**
746 * Returns a promise that resolves with the job counts for the given queue.
747 */
748 getJobCounts(): Promise<JobCounts>;
749
750 /**
751 * Returns a promise that resolves with the job counts for the given queue of the given job statuses.
752 */
753 getJobCountByTypes(types: JobStatus[] | JobStatus): Promise<JobCounts>;
754
755 /**
756 * Returns a promise that resolves with the quantity of completed jobs.
757 */
758 getCompletedCount(): Promise<number>;
759
760 /**
761 * Returns a promise that resolves with the quantity of failed jobs.
762 */
763 getFailedCount(): Promise<number>;
764
765 /**
766 * Returns a promise that resolves with the quantity of delayed jobs.
767 */
768 getDelayedCount(): Promise<number>;
769
770 /**
771 * Returns a promise that resolves with the quantity of waiting jobs.
772 */
773 getWaitingCount(): Promise<number>;
774
775 /**
776 * Returns a promise that resolves with the quantity of paused jobs.
777 */
778 getPausedCount(): Promise<number>;
779
780 /**
781 * Returns a promise that resolves with the quantity of active jobs.
782 */
783 getActiveCount(): Promise<number>;
784
785 /**
786 * Returns a promise that resolves to the quantity of repeatable jobs.
787 */
788 getRepeatableCount(): Promise<number>;
789
790 /**
791 * Tells the queue remove all jobs created outside of a grace period in milliseconds.
792 * You can clean the jobs with the following states: completed, wait (typo for waiting), active, delayed, and failed.
793 * @param grace Grace period in milliseconds.
794 * @param status Status of the job to clean. Values are completed, wait, active, delayed, and failed. Defaults to completed.
795 * @param limit Maximum amount of jobs to clean per call. If not provided will clean all matching jobs.
796 */
797 clean(grace: number, status?: JobStatusClean, limit?: number): Promise<Array<Job<T>>>;
798
799 /**
800 * Returns a promise that marks the start of a transaction block.
801 */
802 multi(): Redis.Pipeline;
803
804 /**
805 * Returns the queue specific key.
806 */
807 toKey(queueType: string): string;
808
809 /**
810 * Completely destroys the queue and all of its contents irreversibly.
811 * @param ops.force Obliterate the queue even if there are active jobs
812 */
813 obliterate(ops?: { force: boolean}): Promise<void>;
814
815 /**
816 * Listens to queue events
817 */
818 on(event: string, callback: (...args: any[]) => void): this;
819
820 /**
821 * An error occured
822 */
823 on(event: 'error', callback: ErrorEventCallback): this;
824
825 /**
826 * A Job is waiting to be processed as soon as a worker is idling.
827 */
828 on(event: 'waiting', callback: WaitingEventCallback): this;
829
830 /**
831 * A job has started. You can use `jobPromise.cancel()` to abort it
832 */
833 on(event: 'active', callback: ActiveEventCallback<T>): this;
834
835 /**
836 * A job has been marked as stalled.
837 * This is useful for debugging job workers that crash or pause the event loop.
838 */
839 on(event: 'stalled', callback: StalledEventCallback<T>): this;
840
841 /**
842 * A job's progress was updated
843 */
844 on(event: 'progress', callback: ProgressEventCallback<T>): this;
845
846 /**
847 * A job successfully completed with a `result`
848 */
849 on(event: 'completed', callback: CompletedEventCallback<T>): this;
850
851 /**
852 * A job failed with `err` as the reason
853 */
854 on(event: 'failed', callback: FailedEventCallback<T>): this;
855
856 /**
857 * The queue has been paused
858 */
859 on(event: 'paused', callback: EventCallback): this;
860
861 /**
862 * The queue has been resumed
863 */
864 on(event: 'resumed', callback: EventCallback): this; // tslint:disable-line unified-signatures
865
866 /**
867 * A job successfully removed.
868 */
869 on(event: 'removed', callback: RemovedEventCallback<T>): this;
870
871 /**
872 * Old jobs have been cleaned from the queue.
873 * `jobs` is an array of jobs that were removed, and `type` is the type of those jobs.
874 *
875 * @see Queue#clean() for details
876 */
877 on(event: 'cleaned', callback: CleanedEventCallback<T>): this;
878
879 /**
880 * Emitted every time the queue has processed all the waiting jobs
881 * (even if there can be some delayed jobs not yet processed)
882 */
883 on(event: 'drained', callback: EventCallback): this; // tslint:disable-line unified-signatures
884
885 /**
886 * Array of Redis clients the queue uses
887 */
888 clients: Redis.Redis[];
889
890 /**
891 * Set clientName to Redis.client
892 */
893 setWorkerName(): Promise<any>;
894
895 /**
896 * Returns Redis clients array which belongs to current Queue
897 */
898 getWorkers(): Promise<Redis.Redis[]>;
899
900 /**
901 * Returns Queue name in base64 encoded format
902 */
903 base64Name(): string;
904
905 /**
906 * Returns Queue name with keyPrefix (default: 'bull')
907 */
908 clientName(): string;
909
910 /**
911 * Returns Redis clients array which belongs to current Queue from string with all redis clients
912 *
913 * @param list String with all redis clients
914 */
915 parseClientList(list: string): Redis.Redis[];
916
917 /**
918 * Returns a promise that resolves when active jobs are finished
919 */
920 whenCurrentJobsFinished(): Promise<void>;
921
922 /**
923 * Removes all the jobs which jobId matches the given pattern. The pattern must follow redis glob-style pattern
924 * (syntax)[redis.io/commands/keys]
925 */
926 removeJobs(pattern: string): Promise<void>;
927 }
928
929 type EventCallback = () => void;
930
931 type ErrorEventCallback = (error: Error) => void;
932
933 interface JobPromise {
934 /**
935 * Abort this job
936 */
937 cancel(): void;
938 }
939
940 type ActiveEventCallback<T = any> = (job: Job<T>, jobPromise?: JobPromise) => void;
941
942 type StalledEventCallback<T = any> = (job: Job<T>) => void;
943
944 type ProgressEventCallback<T = any> = (job: Job<T>, progress: any) => void;
945
946 type CompletedEventCallback<T = any> = (job: Job<T>, result: any) => void;
947
948 type FailedEventCallback<T = any> = (job: Job<T>, error: Error) => void;
949
950 type CleanedEventCallback<T = any> = (jobs: Array<Job<T>>, status: JobStatusClean) => void;
951
952 type RemovedEventCallback<T = any> = (job: Job<T>) => void;
953
954 type WaitingEventCallback = (jobId: JobId) => void;
955}
956
957export = Bull;