UNPKG

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