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
+25-2Lines changed: 25 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -308,6 +308,12 @@ After registering a handler, you can create a job. For example:
308
308
## Run code after all tasks are done
309
309
If you need to react when the whole job is finished, pass `onAllTasksDone` to `registerTaskHandler`.
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`.
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.
314
+
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
+
311
317
```tstitle="./index.ts"
312
318
...
313
319
@@ -316,13 +322,30 @@ If you need to react when the whole job is finished, pass `onAllTasksDone` to `r
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.
348
+
326
349
## Custom job state renderer
327
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