Skip to content

Commit

Permalink
GITBOOK-201: change request with no subject merged in GitBook
Browse files Browse the repository at this point in the history
  • Loading branch information
manast authored and gitbook-bot committed Oct 3, 2024
1 parent 33bb091 commit 8faaf4c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 46 deletions.
6 changes: 1 addition & 5 deletions docs/gitbook/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* [Debouncing](guide/jobs/debouncing.md)
* [Delayed](guide/jobs/delayed.md)
* [Repeatable](guide/jobs/repeatable.md)
* [Job Scheduler](guide/jobs/job-scheduler.md)
* [Prioritized](guide/jobs/prioritized.md)
* [Removing jobs](guide/jobs/removing-job.md)
* [Stalled](guide/jobs/stalled.md)
Expand Down Expand Up @@ -120,11 +121,6 @@
* [Debugging](bull/patterns/debugging.md)
* [Manually fetching jobs](bull/patterns/manually-fetching-jobs.md)

## Bull 3.x Migration

* [Compatibility class](bull-3.x-migration/compatibility-class.md)
* [Migration](bull-3.x-migration/migration.md)

## Python

* [Introduction](python/introduction.md)
Expand Down
39 changes: 0 additions & 39 deletions docs/gitbook/bull-3.x-migration/compatibility-class.md

This file was deleted.

2 changes: 0 additions & 2 deletions docs/gitbook/bull-3.x-migration/migration.md

This file was deleted.

51 changes: 51 additions & 0 deletions docs/gitbook/guide/jobs/job-scheduler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
description: >-
Job Schedulers replace "repeatable jobs", and are available in v5.5.5 and
above.
---

# Job Scheduler

A Job Scheduler acts as a factory , producing jobs based on specified "repeat" settings. The Job Scheduler is highly flexible, accommodating various scenarios, including jobs produced at fixed intervals, according to cron expressions, or based on custom requirements. For historical reasons, jobs produced by the Job Scheduler are often referred to as ‘Repeatable Jobs’.

To create a scheduler, simply use the "upsertJobScheduler" method as demonstrated in the following example:

```typescript
// Creates a new Job Scheduler that generates a job every 1000 milliseconds (1 second)
const firstJob = await queue.upsertJobScheduler("my-scheduler-id", { every: 1000 });
```

This example will create a new Job Scheduler that will produce a new job every second. It will also return the first job created for this Job Scheduler, which will be in "delayed" status waiting to be processed after 1 second.

Now there are also a few important considerations that need to be explained here.:

* **Upsert vs. Add:** 'upsert' is used instead of 'add' to simplify management of recurring jobs, especially in production deployments. It ensures the scheduler is updated or created without duplications.
* **Job Production Rate:** The scheduler will only generate new jobs when the last job begins processing. Therefore, if your queue is very busy, or if you do not have enough workers or concurrency, it is possible that you will get the jobs less frequently than the specified repetition interval.
* **Job Status:** As long as a Job Scheduler is producing jobs, there will be always one job associated to the scheduler in the "Delayed" status.

### Using Job Templates

You can also define a template with standard names, data, and options for jobs added to a queue. This ensures that all jobs produced by the Job Scheduler inherit these settings:

```typescript
// Create jobs every day at 3:15 (am)
const firstJob = await queue.upsertJobScheduler(
"my-scheduler-id",
{ pattern: '0 15 3 * * *' },
{
name: "my-job-name",
data: { foo: "bar" },
opts: {
backoff: 3,
attempts: 5,
removeOnFail: 1000
},
});

```

All jobs produced by this scheduler will use the given settings. Note that in the future you could call "upsertJobScheduler" again with the given "my-scheduler-id" in order to update any settings, both the repeat options or/and the job's template settings.

{% hint style="info" %}
Since jobs produced by the Job Scheduler will get a special job ID in order to guarantee that jobs will never be created more often than the given repeat settings, you cannot choose a custom job id. However you can use the job's name if you need to discriminate these jobs from other jobs.
{% endhint %}

0 comments on commit 8faaf4c

Please sign in to comment.