Skip to content

Commit a99435f

Browse files
committed
docs: add section on handling completion of background jobs
1 parent 7dc653c commit a99435f

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,25 @@ After registering a handler, you can create a job. For example:
288288
...
289289

290290
```
291+
292+
## Run code after all tasks are done
293+
If you need to react when the whole job is finished, pass `onAllTasksDone` to `registerTaskHandler`.
294+
295+
```ts title="./index.ts"
296+
...
297+
298+
backgroundJobsPlugin.registerTaskHandler({
299+
jobHandlerName: 'import-users',
300+
handler: async ({ jobId, setTaskStateField, getTaskStateField }) => {
301+
// task logic
302+
},
303+
onAllTasksDone: async ({ jobId, failedTasks, succeededTasks }) => {
304+
console.log('job finished', { jobId, failedTasks, succeededTasks });
305+
},
306+
});
307+
308+
```
309+
291310
## Custom job state renderer
292311
There may be cases when you need to display the state of job tasks. For this, you can register a custom component.
293312

0 commit comments

Comments
 (0)