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
BackgroundJobsPlugin adds a durable background-job system to AdminForth. Jobs are stored in your data store (via a resource), executed by registered handlers, and automatically resumed after server restarts.
8
+
BackgroundJobsPlugin adds a durable backgroundjob system to AdminForth. Jobs are stored in your data store through a resource, executed by registered handlers, and automatically resumed after server restarts.
9
9
10
10
11
11
## Setup
@@ -15,7 +15,7 @@ First, install the plugin:
15
15
pnpm i @adminforth/background-jobs
16
16
```
17
17
18
-
and create a resource for jobs:
18
+
Then create a resource for jobs:
19
19
20
20
21
21
```ts title="./resources/jobs.ts"
@@ -129,7 +129,7 @@ export default {
129
129
} asAdminForthResourceInput;
130
130
```
131
131
132
-
Then make add table schema:
132
+
Then add the table schema:
133
133
134
134
```
135
135
model jobs {
@@ -145,11 +145,11 @@ model jobs {
145
145
}
146
146
```
147
147
148
-
and make migration
148
+
Then create a migration.
149
149
150
150
151
151
## Usage
152
-
The plugin saves tasks and keeps executing them even after a server restart, so you should register job task handlers at the start of the AdminForth application.
152
+
The plugin saves tasks and keeps executing them after a server restart, so you should register job task handlers when the AdminForth application starts.
153
153
154
154
```ts title="./index.ts"
155
155
//diff-add
@@ -212,7 +212,7 @@ The plugin saves tasks and keeps executing them even after a server restart, so
212
212
//diff-add
213
213
},
214
214
//diff-add
215
-
//limit of tasks, that are running in parallel
215
+
//limit of tasks that are running in parallel
216
216
//diff-add
217
217
parallelLimit: 1
218
218
//diff-add
@@ -308,7 +308,7 @@ If you need to react when the whole job is finished, pass `onAllTasksDone` to `r
308
308
```
309
309
310
310
## Custom job state renderer
311
-
There may be cases when you need to display the state of job tasks. For this, you can register a custom component.
311
+
There may be cases where you need to display the state of job tasks. For this, you can register a custom component.
312
312
313
313
314
314
```tstitle="./custom/JobCustomComponent.vue"
@@ -372,16 +372,6 @@ onUnmounted(() => {
372
372
</script>
373
373
```
374
374
375
-
Job state and task state can be reactive on the frontend and updated when something changes on the backend.
376
-
However, to avoid unnecessary high-volume backend updates that might not be needed on the frontend,
377
-
all updates are disabled out of the box, and you need to specify which fields to subscribe to.
378
-
379
-
Use `subscribeToJobStateFields(['fieldName'])` for specific job state fields and
380
-
`subscribeToJobTaskFields(['fieldName'])` for specific task state fields. The plugin applies
381
-
incoming updates to the reactive `job` prop and to the task objects returned by
382
-
`getJobTasks()`. Task field subscriptions receive updates for that field from every task
383
-
in the opened job. Both helpers return an unsubscribe function; the plugin also unsubscribes
384
-
remaining field subscriptions when the job dialog closes.
385
375
386
376
387
377
Now register this component explicitly:
@@ -461,10 +451,25 @@ Finally, register this component alongside the job task handler:
461
451
462
452
```
463
453
454
+
### Reactive updates for job state and task state
455
+
456
+
You can activate automatic reactive updates for task state and job state on the frontend when you call backend state mutation methods like `setJobField` and `setTaskStateField`.
457
+
458
+
To avoid unnecessary high-volume backend updates for data that might not be needed on the frontend, all reactive updates are disabled by default, and you need to specify which fields to subscribe to.
459
+
460
+
Use `subscribeToJobStateFields(['fieldName1', 'fieldName2'])` for specific job state fields and
461
+
`subscribeToJobTaskFields(['fieldName1', 'fieldName2'])` for specific task state fields.
462
+
463
+
The plugin applies incoming updates to the reactive `job` prop and to the task objects returned by
464
+
`getJobTasks()`. Task field subscriptions receive updates for that field from every task
465
+
in the open job. Both helpers return an unsubscribe function, though the plugin also automatically unsubscribes from
466
+
remaining field subscriptions when the job dialog closes.
467
+
468
+
464
469
465
470
## Frontend API
466
471
### Job info popup
467
-
If you want to imedeatelly open job info popup, you shoul return job id from you API, that creates job:
472
+
If you want to immediately open the job info popup, return the job ID from the API that creates the job:
468
473
469
474
For example:
470
475
@@ -496,9 +501,9 @@ For example:
496
501
497
502
```
498
503
499
-
## Backend api
504
+
## Backend API
500
505
501
-
Pluging provides some handy methods, that can be used in different situations:
506
+
The plugin provides some handy methods that can be used in different situations:
0 commit comments