Skip to content

Commit

Permalink
GITBOOK-8: No subject
Browse files Browse the repository at this point in the history
  • Loading branch information
code-xhyun authored and gitbook-bot committed May 2, 2024
1 parent c253074 commit ec7a7e8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gitbook/docs/defining-job-processors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<T>`): 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<T>`): 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`.
Expand Down

0 comments on commit ec7a7e8

Please sign in to comment.