From 2cd2bd872694741753a201574a8168a4a913cdb2 Mon Sep 17 00:00:00 2001 From: Alex Regan Date: Tue, 20 Feb 2018 15:09:07 -0700 Subject: [PATCH 1/4] fix(bull): adds `Queue.process` overloads --- types/bull/index.d.ts | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/types/bull/index.d.ts b/types/bull/index.d.ts index a7a9ea350b..a77552cb9a 100644 --- a/types/bull/index.d.ts +++ b/types/bull/index.d.ts @@ -265,6 +265,24 @@ declare namespace Bull { */ process(callback: (job: Job, done: DoneCallback) => void): void; + /** + * Defines a processing function for the jobs placed into a given Queue. + * + * The handlerPath defines the path to the job callback. + * Using a handlerPath 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. + * + * It is passed an instance of the job as first 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(handlerPath: string): void; + /** * Defines a processing function for the jobs placed into a given Queue. * @@ -291,6 +309,26 @@ declare namespace Bull { */ process(concurrency: number, callback: (job: Job) => void): Promise; + /** + * Defines a processing function for the jobs placed into a given Queue. + * + * The handlerPath defines the path to the job callback. + * Using a handlerPath 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. + * + * It is passed an instance of the job as first 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. + */ + process(concurrency: number, handlerPath: string): void; + /** * Defines a processing function for the jobs placed into a given Queue. * @@ -337,6 +375,27 @@ declare namespace Bull { // tslint:disable-next-line:unified-signatures process(name: string, callback: (job: Job, done: DoneCallback) => void): void; + /** + * Defines a processing function for the jobs placed into a given Queue. + * + * The handlerPath defines the path to the job callback. + * Using a handlerPath 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. + * + * It is passed an instance of the job as first 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. + */ + process(name: string, concurrency: number, handlerPath: string): void; + /** * Defines a named processing function for the jobs placed into a given Queue. * From ebcbc212b7da009de20e1802c05b8f66ec7c2be5 Mon Sep 17 00:00:00 2001 From: Alex Regan Date: Tue, 20 Feb 2018 15:20:04 -0700 Subject: [PATCH 2/4] fix(bull): merge overload decls with same arity --- types/bull/index.d.ts | 87 +++++++++++++------------------------------ 1 file changed, 26 insertions(+), 61 deletions(-) diff --git a/types/bull/index.d.ts b/types/bull/index.d.ts index a77552cb9a..77317c44ff 100644 --- a/types/bull/index.d.ts +++ b/types/bull/index.d.ts @@ -257,31 +257,19 @@ 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. + * 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. * * 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. - * - * The handlerPath defines the path to the job callback. - * Using a handlerPath 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. - * - * It is passed an instance of the job as first 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(handlerPath: string): void; + process(callback: (job: Job, done: DoneCallback) => void | string): void; /** * Defines a processing function for the jobs placed into a given Queue. @@ -312,29 +300,15 @@ declare namespace Bull { /** * Defines a processing function for the jobs placed into a given Queue. * - * The handlerPath defines the path to the job callback. - * Using a handlerPath has several advantages: + * 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. * - * It is passed an instance of the job as first 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. - */ - process(concurrency: number, handlerPath: 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 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; @@ -342,7 +316,7 @@ declare namespace Bull { * * @param concurrency Bull will then call you handler in parallel respecting this max number. */ - process(concurrency: number, callback: (job: Job, done: DoneCallback) => void): void; + process(concurrency: number, callback: (job: Job, done: DoneCallback) => void | string): void; /** * Defines a named processing function for the jobs placed into a given Queue. @@ -364,6 +338,12 @@ 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. + * 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. * * 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. @@ -373,28 +353,7 @@ declare namespace Bull { * @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 processing function for the jobs placed into a given Queue. - * - * The handlerPath defines the path to the job callback. - * Using a handlerPath 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. - * - * It is passed an instance of the job as first 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. - */ - process(name: string, concurrency: number, handlerPath: string): void; + process(name: string, callback: (job: Job, done: DoneCallback) => void | string): void; /** * Defines a named processing function for the jobs placed into a given Queue. @@ -416,6 +375,12 @@ 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. + * 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. * * 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. @@ -425,7 +390,7 @@ declare namespace Bull { * @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 | string): void; /** * Creates a new job and adds it to the queue. From 1426182dcd3721e627298302f2862030626b806a Mon Sep 17 00:00:00 2001 From: Alex Regan Date: Tue, 27 Feb 2018 08:19:14 -0700 Subject: [PATCH 3/4] fix(bull): union callback param, not return val --- types/bull/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/bull/index.d.ts b/types/bull/index.d.ts index 77317c44ff..289c05d149 100644 --- a/types/bull/index.d.ts +++ b/types/bull/index.d.ts @@ -269,7 +269,7 @@ declare namespace Bull { * 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 | string): void; + process(callback: ((job: Job, done: DoneCallback) => void) | string): void; /** * Defines a processing function for the jobs placed into a given Queue. @@ -316,7 +316,7 @@ declare namespace Bull { * * @param concurrency Bull will then call you handler in parallel respecting this max number. */ - process(concurrency: number, callback: (job: Job, done: DoneCallback) => void | string): void; + process(concurrency: number, callback: ((job: Job, done: DoneCallback) => void) | string): void; /** * Defines a named processing function for the jobs placed into a given Queue. @@ -353,7 +353,7 @@ declare namespace Bull { * @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 | string): void; + process(name: string, callback: ((job: Job, done: DoneCallback) => void) | string): void; /** * Defines a named processing function for the jobs placed into a given Queue. @@ -390,7 +390,7 @@ declare namespace Bull { * @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 | string): void; + process(name: string, concurrency: number, callback: ((job: Job, done: DoneCallback) => void) | string): void; /** * Creates a new job and adds it to the queue. From c8e95cf22664e2894120a8b47a3e37d4f6e53455 Mon Sep 17 00:00:00 2001 From: Alex Regan Date: Tue, 27 Feb 2018 19:32:33 -0700 Subject: [PATCH 4/4] fix(bull): switch overload to Promise return --- types/bull/index.d.ts | 116 +++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/types/bull/index.d.ts b/types/bull/index.d.ts index 289c05d149..608460b63b 100644 --- a/types/bull/index.d.ts +++ b/types/bull/index.d.ts @@ -257,45 +257,13 @@ 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. - * 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. * * 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) | 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. - * - * 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): 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. - * - * 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. - */ - process(concurrency: number, callback: (job: Job) => void): Promise; + process(callback: (job: Job, done: DoneCallback) => void): void; /** * Defines a processing function for the jobs placed into a given Queue. @@ -309,6 +277,38 @@ declare namespace Bull { * - Much better utilization of multi-core CPUs. * - Less connections to redis. * + * 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; + + /** + * 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 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. + */ + process(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; @@ -316,13 +316,19 @@ declare namespace Bull { * * @param concurrency Bull will then call you handler in parallel respecting this max number. */ - process(concurrency: number, callback: ((job: Job, done: DoneCallback) => void) | string): void; + 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 the promise is rejected, the error will be passed as a second argument to the "failed" event. @@ -331,19 +337,13 @@ declare namespace Bull { * @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): Promise; + process(name: string, 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 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. * * 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. @@ -353,28 +353,13 @@ declare namespace Bull { * @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) | string): void; + 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. - * - * 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. - */ - process(name: string, concurrency: number, callback: (job: Job) => void): 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 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. @@ -382,6 +367,21 @@ declare namespace Bull { * - Much better utilization of multi-core CPUs. * - Less connections to redis. * + * 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. + */ + 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; @@ -390,7 +390,7 @@ declare namespace Bull { * @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) | string): void; + process(name: string, concurrency: number, callback: (job: Job, done: DoneCallback) => void): void; /** * Creates a new job and adds it to the queue.