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.