diff --git a/gitbook/docs/defining-job-processors.md b/gitbook/docs/defining-job-processors.md index edcba2d..c6ceca1 100644 --- a/gitbook/docs/defining-job-processors.md +++ b/gitbook/docs/defining-job-processors.md @@ -20,9 +20,13 @@ const pulse = new Pulse(); pulse.define('sendEmail', async (job, done) => { try { await sendEmail(job.data); - done(); // Mark the job as completed + + // Mark the job as completed + done(); // or done(undefined, 'Success'); + } catch (error) { console.error('Failed to send email:', error); + done(error); } }, { concurrency: 5, @@ -40,6 +44,8 @@ pulse.define('sendEmail', async (job, done) => { * **`name`** (`string`): The unique name for the job type. This name is used to refer to and manage jobs of this type throughout their lifecycle. * **`processor`** (`Processor`): The function that contains the logic to be executed when a job of this type is processed. The function receives a `Job` object and an optional `done` callback that should be called when the job processing completes. + * **`job`** (`Job`): The job instance being processed. This object contains all data and methods related to the specific job, allowing the processor to access job data and interact with the job's lifecycle. + * **`done`** (`(error?: Error, result?: unknown) => void`): A callback function that should be called once the job processing is completed or if an error occurs. Calling `done` with an `Error` object indicates that the job has failed, whereas calling it with no parameters or a result indicates successful completion. * **`options`** (`DefineOptions` - optional): Configuration options for the job, which include: * **`concurrency`** (`number`): Maximum number of instances of the job that can run simultaneously. Defaults to `Pulse`'s `_defaultConcurrency`. * **`lockLimit`** (`number`): Maximum number of instances of the job that can be locked at once. Defaults to `Pulse`'s `_defaultLockLimit`.