You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: adminforth/documentation/docs/tutorial/08-Plugins/23-background-jobs.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -305,12 +305,12 @@ After registering a handler, you can create a job. For example:
305
305
306
306
```
307
307
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.
310
310
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.
312
312
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.
314
314
315
315
`finishAttemptNumber` starts from `1` and increments every time the job reaches this candidate-finish point again. Use it to avoid accidental infinite continuations.
316
316
@@ -322,7 +322,7 @@ After those new tasks finish, `onAllTasksDone` is called again.
@@ -343,8 +343,8 @@ After those new tasks finish, `onAllTasksDone` is called again.
343
343
344
344
```
345
345
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.
348
348
349
349
## Custom job state renderer
350
350
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