Skip to content

Commit 56e33b9

Browse files
committed
Updates on how locking a job works
1 parent a3e6e6e commit 56e33b9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

docs/versioned_docs/version-8.0/background-jobs.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,11 @@ The runner is a sort of overseer that doesn't do any work itself, but spawns wor
327327

328328
It checks the `BackgroundJob` table every few seconds for a new job and, if it finds one, locks it so that no other workers can have it, then calls your `perform()` function, passing it the arguments you gave when you scheduled it.
329329

330-
If the job succeeds then by default it's removed from the database (using the `PrismaAdapter`, other adapters behavior may vary). If the job fails, the job is un-locked in the database, the `runAt` is set to an incremental backoff time in the future, and `lastError` is updated with the error that occurred. The job will now be picked up in the future once the `runAt` time has passed and it'll try again.
330+
**Locking** a job consists of setting two fields: `lockedBy` which contains the process name of the worker, and `lockedAt` which is a timestamp. As long as these are set no other workers will pick up that same job.
331+
332+
In addition to locking the job, the `attempts` column is incremented so it can keep track of how many times this job has been attempted and can properly reschedule it in the future if it errors out (see [Job Errors & Failure](#job-errors--failure) below).
333+
334+
If the job succeeds then by default it's removed from the database (using the `PrismaAdapter`, other adapters' behavior may vary). If the job fails, the job is un-locked in the database, the `runAt` is set to an incremental backoff time in the future, and `lastError` is updated with the error that occurred. The job will now be picked up in the future once the `runAt` time has passed and a worker will lock it and try again. Again, see [Job Errors & Failure](#job-errors--failure) for details.
331335

332336
To stop the runner (and the workers it started), press `Ctrl-C` (or send `SIGINT`). The workers will gracefully shut down, waiting for their work to complete before exiting. If you don't wait to wait, hit `Ctrl-C` again (or send `SIGTERM`).
333337

0 commit comments

Comments
 (0)