Skip to content

Commit 7ac6637

Browse files
committed
docs: beforeJobFinish
1 parent a7648cf commit 7ac6637

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

adminforth/documentation/docs/tutorial/08-Plugins/23-background-jobs.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,12 @@ After registering a handler, you can create a job. For example:
305305

306306
```
307307
308-
## Run code after all tasks are done
309-
If you need to react when the whole job is finished, pass `onAllTasksDone` to `registerTaskHandler`.
308+
## Run more tasks before job finishes
309+
If you need to react when the whole job is almost finished and add more tasks, use the `beforeJobFinish` callback.
310310
311-
The callback is called when all currently scheduled tasks are done, before the job is marked as `DONE` or `DONE_WITH_ERRORS`.
311+
The callback is called when all currently scheduled tasks are done, before the job is marked as `DONE` or `DONE_WITH_ERRORS`, and before `onAllTasksDone` is called.
312312
This means you can use it as a continuation hook: add more tasks with `addNewTasksToExistingJob`, and the same job will keep running.
313-
After those new tasks finish, `onAllTasksDone` is called again.
313+
After those new tasks finish, `beforeJobFinish` is called again.
314314
315315
`finishAttemptNumber` starts from `1` and increments every time the job reaches this candidate-finish point again. Use it to avoid accidental infinite continuations.
316316
@@ -322,7 +322,7 @@ After those new tasks finish, `onAllTasksDone` is called again.
322322
handler: async ({ jobId, setTaskStateField, getTaskStateField, getState }) => {
323323
// task logic
324324
},
325-
onAllTasksDone: async ({ jobId, failedTasks, succeededTasks, finishAttemptNumber }) => {
325+
beforeJobFinish: async ({ jobId, failedTasks, succeededTasks, finishAttemptNumber }) => {
326326
console.log('job reached finish point', {
327327
jobId,
328328
failedTasks,
@@ -343,8 +343,8 @@ After those new tasks finish, `onAllTasksDone` is called again.
343343

344344
```
345345
346-
In this example, the job runs its initial tasks, calls `onAllTasksDone` with `finishAttemptNumber: 1`, appends two more tasks, runs them, and then calls `onAllTasksDone` again with `finishAttemptNumber: 2`.
347-
If the second callback does not add more tasks, the job is marked as finished.
346+
In this example, the job runs its initial tasks, calls `beforeJobFinish` with `finishAttemptNumber: 1`, appends two more tasks, runs them, and then calls `beforeJobFinish` again with `finishAttemptNumber: 2`.
347+
If the second callback does not add more tasks, the job is marked as finished and `onAllTasksDone` is called if it was registered.
348348
349349
## Custom job state renderer
350350
There may be cases where you need to display the state of job tasks. For this, you can register a custom component.

0 commit comments

Comments
 (0)