diff --git a/types/bull/bull-tests.tsx b/types/bull/bull-tests.tsx index dd484ce1d1..46c146272e 100644 --- a/types/bull/bull-tests.tsx +++ b/types/bull/bull-tests.tsx @@ -98,11 +98,17 @@ const pdfQueue = new Queue('pdf transcoding', { // ////////////////////////////////////////////////////////////////////////////////// -pdfQueue.process((job) => { +pdfQueue.process((job: Queue.Job) => { // Processors can also return promises instead of using the done callback return Promise.resolve(); }); +async function pfdPromise(job: Queue.Job) { + return Promise.resolve(); +} + +pdfQueue.process(1, pfdPromise); + videoQueue.add({ video: 'http://example.com/video1.mov' }, { jobId: 1 }) .then((video1Job) => { // When job has successfully be placed in the queue the job is returned diff --git a/types/bull/index.d.ts b/types/bull/index.d.ts index dd5723f2d2..c08048f1d7 100644 --- a/types/bull/index.d.ts +++ b/types/bull/index.d.ts @@ -12,6 +12,7 @@ // Alec Brunelle // Dan Manastireanu // Kjell-Morten Bratsberg Thorsen +// Christian D. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -342,50 +343,39 @@ declare namespace Bull { * The callback is called everytime a job is placed in the queue. * It is passed an instance of the job as first argument. * + * If the callback signature contains the second optional done argument, + * the callback will be passed a done callback to be called after the job has been completed. * The done callback can be called with an Error instance, to signal that the job did not complete successfully, - * or with a result as second argument as second argument (e.g.: done(null, result);) when the job is successful. - * Errors will be passed as a second argument to the "failed" event; - * results, as a second argument to the "completed" event. - */ - process(callback: (job: Job, done: DoneCallback) => void): void; - - /** - * Defines a processing function for the jobs placed into a given Queue. + * or with a result as second argument (e.g.: done(null, result);) when the job is successful. + * Errors will be passed as a second argument to the "failed" event; results, as a second argument to the "completed" event. * - * The callback is called everytime a job is placed in the queue. - * It is passed an instance of the job as first argument. - * The callback can also be defined as the string path to a module - * exporting the callback function. Using a path has several advantages: - * - The process is sandboxed so if it crashes it does not affect the worker. - * - You can run blocking code without affecting the queue (jobs will not stall). - * - Much better utilization of multi-core CPUs. - * - Less connections to redis. - * - * A promise must be returned to signal job completion. + * If, however, the callback signature does not contain the done argument, + * a promise must be returned to signal job completion. * If the promise is rejected, the error will be passed as a second argument to the "failed" event. * If it is resolved, its value will be the "completed" event's second argument. */ - process(callback: ((job: Job) => void) | string): Promise; + process(callback: ((job: Job, done: DoneCallback) => void) | ((job: Job) => Promise) | string): void; /** * Defines a processing function for the jobs placed into a given Queue. * * The callback is called everytime a job is placed in the queue. * It is passed an instance of the job as first argument. - * The callback can also be defined as the string path to a module - * exporting the callback function. Using a path has several advantages: - * - The process is sandboxed so if it crashes it does not affect the worker. - * - You can run blocking code without affecting the queue (jobs will not stall). - * - Much better utilization of multi-core CPUs. - * - Less connections to redis. * - * A promise must be returned to signal job completion. + * If the callback signature contains the second optional done argument, + * the callback will be passed a done callback to be called after the job has been completed. + * The done callback can be called with an Error instance, to signal that the job did not complete successfully, + * or with a result as second argument (e.g.: done(null, result);) when the job is successful. + * Errors will be passed as a second argument to the "failed" event; results, as a second argument to the "completed" event. + * + * If, however, the callback signature does not contain the done argument, + * a promise must be returned to signal job completion. * If the promise is rejected, the error will be passed as a second argument to the "failed" event. * If it is resolved, its value will be the "completed" event's second argument. * - * @param concurrency Bull will then call you handler in parallel respecting this max number. + * @param concurrency Bull will then call your handler in parallel respecting this maximum value. */ - process(concurrency: number, callback: ((job: Job) => void) | string): Promise; + process(concurrency: number, callback: ((job: Job, done: DoneCallback) => void) | ((job: Job) => Promise) | string): void; /** * Defines a processing function for the jobs placed into a given Queue. @@ -393,35 +383,21 @@ declare namespace Bull { * The callback is called everytime a job is placed in the queue. * It is passed an instance of the job as first argument. * + * If the callback signature contains the second optional done argument, + * the callback will be passed a done callback to be called after the job has been completed. * The done callback can be called with an Error instance, to signal that the job did not complete successfully, - * or with a result as second argument as second argument (e.g.: done(null, result);) when the job is successful. - * Errors will be passed as a second argument to the "failed" event; - * results, as a second argument to the "completed" event. + * or with a result as second argument (e.g.: done(null, result);) when the job is successful. + * Errors will be passed as a second argument to the "failed" event; results, as a second argument to the "completed" event. * - * @param concurrency Bull will then call you handler in parallel respecting this max number. - */ - process(concurrency: number, callback: (job: Job, done: DoneCallback) => void): void; - - /** - * Defines a named processing function for the jobs placed into a given Queue. - * - * The callback is called everytime a job is placed in the queue. - * It is passed an instance of the job as first argument. - * The callback can also be defined as the string path to a module - * exporting the callback function. Using a path has several advantages: - * - The process is sandboxed so if it crashes it does not affect the worker. - * - You can run blocking code without affecting the queue (jobs will not stall). - * - Much better utilization of multi-core CPUs. - * - Less connections to redis. - * - * A promise must be returned to signal job completion. + * If, however, the callback signature does not contain the done argument, + * a promise must be returned to signal job completion. * If the promise is rejected, the error will be passed as a second argument to the "failed" event. * If it is resolved, its value will be the "completed" event's second argument. * * @param name Bull will only call the handler if the job name matches */ // tslint:disable-next-line:unified-signatures - process(name: string, callback: ((job: Job) => void) | string): Promise; + process(name: string, callback: ((job: Job, done: DoneCallback) => void) | ((job: Job) => Promise) | string): void; /** * Defines a processing function for the jobs placed into a given Queue. @@ -429,52 +405,21 @@ declare namespace Bull { * The callback is called everytime a job is placed in the queue. * It is passed an instance of the job as first argument. * + * If the callback signature contains the second optional done argument, + * the callback will be passed a done callback to be called after the job has been completed. * The done callback can be called with an Error instance, to signal that the job did not complete successfully, - * or with a result as second argument as second argument (e.g.: done(null, result);) when the job is successful. - * Errors will be passed as a second argument to the "failed" event; - * results, as a second argument to the "completed" event. + * or with a result as second argument (e.g.: done(null, result);) when the job is successful. + * Errors will be passed as a second argument to the "failed" event; results, as a second argument to the "completed" event. * - * @param name Bull will only call the handler if the job name matches - */ - // tslint:disable-next-line:unified-signatures - process(name: string, callback: (job: Job, done: DoneCallback) => void): void; - - /** - * Defines a named processing function for the jobs placed into a given Queue. - * - * The callback is called everytime a job is placed in the queue. - * It is passed an instance of the job as first argument. - * The callback can also be defined as the string path to a module - * exporting the callback function. Using a path has several advantages: - * - The process is sandboxed so if it crashes it does not affect the worker. - * - You can run blocking code without affecting the queue (jobs will not stall). - * - Much better utilization of multi-core CPUs. - * - Less connections to redis. - * - * A promise must be returned to signal job completion. + * If, however, the callback signature does not contain the done argument, + * a promise must be returned to signal job completion. * If the promise is rejected, the error will be passed as a second argument to the "failed" event. * If it is resolved, its value will be the "completed" event's second argument. * * @param name Bull will only call the handler if the job name matches - * @param concurrency Bull will then call you handler in parallel respecting this max number. + * @param concurrency Bull will then call your handler in parallel respecting this maximum value. */ - process(name: string, concurrency: number, callback: ((job: Job) => void) | string): Promise; - - /** - * Defines a processing function for the jobs placed into a given Queue. - * - * The callback is called everytime a job is placed in the queue. - * It is passed an instance of the job as first argument. - * - * The done callback can be called with an Error instance, to signal that the job did not complete successfully, - * or with a result as second argument as second argument (e.g.: done(null, result);) when the job is successful. - * Errors will be passed as a second argument to the "failed" event; - * results, as a second argument to the "completed" event. - * - * @param name Bull will only call the handler if the job name matches - * @param concurrency Bull will then call you handler in parallel respecting this max number. - */ - process(name: string, concurrency: number, callback: (job: Job, done: DoneCallback) => void): void; + process(name: string, concurrency: number, callback: ((job: Job, done: DoneCallback) => void) | ((job: Job) => Promise) | string): void; /** * Creates a new job and adds it to the queue.