@types/bull Update to version 3.4.8. Closes #22673 #23965 #18911 (#29875)

* @types/bull Update to version 3.4.8. Closes #22673 #23965 #18911

* Fix return type for moveTo* methods
This commit is contained in:
Dan Manastireanu
2018-10-22 09:38:28 -07:00
committed by Sheetal Nandi
parent c6fe757c0d
commit 3ea5ad14c4
2 changed files with 108 additions and 4 deletions
+51 -1
View File
@@ -125,6 +125,7 @@ videoQueue.add({ video: 'http://example.com/video1.mov' }, { jobId: 1 })
pdfQueue
.on('error', (err: Error) => undefined)
.on('active', (job: Queue.Job, jobPromise: Queue.JobPromise) => jobPromise.cancel())
.on('waiting', (jobId: Queue.JobId) => undefined)
.on('active', (job: Queue.Job) => undefined)
.on('stalled', (job: Queue.Job) => undefined)
.on('progress', (job: Queue.Job) => undefined)
@@ -132,4 +133,53 @@ pdfQueue
.on('failed', (job: Queue.Job) => undefined)
.on('paused', () => undefined)
.on('resumed', () => undefined)
.on('cleaned', (jobs: Queue.Job[], status: Queue.JobStatus) => undefined);
.on('cleaned', (jobs: Queue.Job[], status: Queue.JobStatus) => undefined)
.on('drained', () => undefined)
.on('removed', (job: Queue.Job) => undefined);
// test different process methods
const profileQueue = new Queue('profile');
// Max concurrency for requestProfile is 100
profileQueue.process('requestProfile', 100, () => {});
profileQueue.process(100, () => {});
// other tests
const myQueue = new Queue('myQueue', {
settings: {
drainDelay: 5
},
defaultJobOptions: {
stackTraceLimit: 1,
}
});
myQueue.on('active', (job: Queue.Job) => {
job.moveToCompleted();
job.moveToCompleted('done');
job.moveToCompleted('done', true);
job.moveToCompleted('done', true).then(val => {
if (val) {
const nextJobData: any = val[0];
const nextJobId: Queue.JobId = val[1];
}
});
job.moveToFailed({ message: "Call to external service failed!" }, true);
job.moveToFailed(new Error('test error'), true);
job.moveToFailed(new Error('test error'), true).then(val => {
if (val) {
const nextJobData: any = val[0];
const nextJobId: Queue.JobId = val[1];
}
});
job.discard();
});
// test all constructor options:
new Queue('profile');
new Queue('profile', 'url');
new Queue('profile', { prefix: 'test' });
new Queue('profile', 'url', { prefix: 'test' });
+57 -3
View File
@@ -1,4 +1,4 @@
// Type definitions for bull 3.3
// Type definitions for bull 3.4
// Project: https://github.com/OptimalBits/bull
// Definitions by: Bruno Grieder <https://github.com/bgrieder>
// Cameron Crothers <https://github.com/JProgrammer>
@@ -10,6 +10,7 @@
// Bond Akinmade <https://github.com/bondz>
// Wuha Team <https://github.com/wuha-team>
// Alec Brunelle <https://github.com/aleccool213>
// Dan Manastireanu <https://github.com/danmana>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
@@ -23,9 +24,9 @@ import * as Promise from "bluebird";
*/
declare const Bull: {
(queueName: string, opts?: Bull.QueueOptions): Bull.Queue;
(queueName: string, url?: string): Bull.Queue; // tslint:disable-line unified-signatures
(queueName: string, url: string, opts?: Bull.QueueOptions): Bull.Queue; // tslint:disable-line unified-signatures
new (queueName: string, opts?: Bull.QueueOptions): Bull.Queue;
new (queueName: string, url?: string): Bull.Queue; // tslint:disable-line unified-signatures
new (queueName: string, url: string, opts?: Bull.QueueOptions): Bull.Queue; // tslint:disable-line unified-signatures
};
declare namespace Bull {
@@ -92,6 +93,12 @@ declare namespace Bull {
backoffStrategies?: {
[key: string]: (attemptsMade: number, err: typeof Error) => number;
};
/**
* A timeout for when the queue is in `drained` state (empty waiting for jobs).
* It is used when calling `queue.getNextJob()`, which will pass it to `.brpoplpush` on the Redis client.
*/
drainDelay?: number;
}
type DoneCallback = (error?: Error | null, value?: any) => void;
@@ -141,6 +148,11 @@ declare namespace Bull {
*/
retry(): Promise<void>;
/**
* Ensure this job is never ran again even if attemptsMade is less than job.attempts.
*/
discard(): Promise<void>;
/**
* Returns a promise that resolves to the returned data when the job has been finished.
* TODO: Add a watchdog to check if the job has finished periodically.
@@ -148,6 +160,18 @@ declare namespace Bull {
*/
finished(): Promise<any>;
/**
* Moves a job to the `completed` queue. Pulls a job from 'waiting' to 'active'
* and returns a tuple containing the next jobs data and id. If no job is in the `waiting` queue, returns null.
*/
moveToCompleted(returnValue?: string, ignoreLock?: boolean): Promise<[any, JobId] | null>;
/**
* Moves a job to the `failed` queue. Pulls a job from 'waiting' to 'active'
* and returns a tuple containing the next jobs data and id. If no job is in the `waiting` queue, returns null.
*/
moveToFailed(errorInfo: { message: string; }, ignoreLock?: boolean): Promise<[any, JobId] | null>;
/**
* Promotes a job that is currently "delayed" to the "waiting" state and executed as soon as possible.
*/
@@ -205,6 +229,11 @@ declare namespace Bull {
* Cron pattern specifying when the job should execute
*/
cron: string;
/**
* Start date when the repeat job should start repeating (only with cron).
*/
startDate?: Date | string | number;
}
interface EveryRepeatOptions extends RepeatOptions {
@@ -273,6 +302,11 @@ declare namespace Bull {
* Default behavior is to keep the job in the completed set.
*/
removeOnFail?: boolean;
/**
* Limits the amount of stack trace lines that will be recorded in the stacktrace.
*/
stackTraceLimit?: number;
}
interface JobCounts {
@@ -618,6 +652,11 @@ declare namespace Bull {
*/
on(event: 'error', callback: ErrorEventCallback): this;
/**
* A Job is waiting to be processed as soon as a worker is idling.
*/
on(event: 'waiting', callback: WaitingEventCallback): this;
/**
* A job has started. You can use `jobPromise.cancel()` to abort it
*/
@@ -654,6 +693,11 @@ declare namespace Bull {
*/
on(event: 'resumed', callback: EventCallback): this; // tslint:disable-line unified-signatures
/**
* A job successfully removed.
*/
on(event: 'removed', callback: RemovedEventCallback<T>): this;
/**
* Old jobs have been cleaned from the queue.
* `jobs` is an array of jobs that were removed, and `type` is the type of those jobs.
@@ -661,6 +705,12 @@ declare namespace Bull {
* @see Queue#clean() for details
*/
on(event: 'cleaned', callback: CleanedEventCallback<T>): this;
/**
* Emitted every time the queue has processed all the waiting jobs
* (even if there can be some delayed jobs not yet processed)
*/
on(event: 'drained', callback: EventCallback): this; // tslint:disable-line unified-signatures
}
type EventCallback = () => void;
@@ -685,6 +735,10 @@ declare namespace Bull {
type FailedEventCallback<T = any> = (job: Job<T>, error: Error) => void;
type CleanedEventCallback<T = any> = (jobs: Array<Job<T>>, status: JobStatus) => void;
type RemovedEventCallback<T = any> = (job: Job<T>) => void;
type WaitingEventCallback = (jobId: JobId) => void;
}
export = Bull;