@unchainedshop/core-worker 5.0.0-alpha.5 → 5.0.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -82
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -13,96 +13,27 @@ npm install @unchainedshop/core-worker
|
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
import { configureWorkerModule, WorkStatus } from '@unchainedshop/core-worker';
|
|
16
|
+
The platform initializes this module as `platform.unchainedAPI.modules.worker`. Register worker plugins before platform startup; the base preset includes the `EMAIL` worker.
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
```typescript
|
|
19
|
+
import { WorkStatus } from '@unchainedshop/core-worker';
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
type: '
|
|
21
|
+
const { worker } = platform.unchainedAPI.modules;
|
|
22
|
+
const work = await worker.addWork({
|
|
23
|
+
type: 'EMAIL',
|
|
24
24
|
input: {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
from: 'shop@example.com',
|
|
26
|
+
to: 'customer@example.com',
|
|
27
|
+
subject: 'Order update',
|
|
28
|
+
text: 'Your order is ready.',
|
|
27
29
|
},
|
|
28
30
|
});
|
|
29
|
-
|
|
30
|
-
// Find pending work
|
|
31
|
-
const pendingWork = await workerModule.findWork({
|
|
32
|
-
status: WorkStatus.NEW,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// Process work (typically done by worker plugins)
|
|
36
|
-
await workerModule.processWork(workId, {
|
|
37
|
-
success: true,
|
|
38
|
-
result: { messageId: 'abc123' },
|
|
39
|
-
});
|
|
31
|
+
const pending = await worker.findWorkQueue({ status: [WorkStatus.NEW] });
|
|
40
32
|
```
|
|
41
33
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
### Module Configuration
|
|
45
|
-
|
|
46
|
-
| Export | Description |
|
|
47
|
-
|--------|-------------|
|
|
48
|
-
| `configureWorkerModule` | Configure and return the worker module |
|
|
49
|
-
|
|
50
|
-
### Queries
|
|
51
|
-
|
|
52
|
-
| Method | Description |
|
|
53
|
-
|--------|-------------|
|
|
54
|
-
| `findWork` | Find work item by ID |
|
|
55
|
-
| `findWorkQueue` | Find work items with filtering |
|
|
56
|
-
| `count` | Count work items matching query |
|
|
57
|
-
|
|
58
|
-
### Mutations
|
|
59
|
-
|
|
60
|
-
| Method | Description |
|
|
61
|
-
|--------|-------------|
|
|
62
|
-
| `addWork` | Add work item to queue |
|
|
63
|
-
| `allocateWork` | Allocate work to a worker |
|
|
64
|
-
| `processWork` | Mark work as processed |
|
|
65
|
-
| `rescheduleWork` | Reschedule failed work |
|
|
66
|
-
| `deleteWork` | Delete a work item |
|
|
67
|
-
|
|
68
|
-
### Constants
|
|
69
|
-
|
|
70
|
-
| Export | Description |
|
|
71
|
-
|--------|-------------|
|
|
72
|
-
| `WorkStatus` | Status values (NEW, ALLOCATED, SUCCESS, FAILED, DELETED) |
|
|
73
|
-
|
|
74
|
-
### Types
|
|
75
|
-
|
|
76
|
-
| Export | Description |
|
|
77
|
-
|--------|-------------|
|
|
78
|
-
| `Work` | Work item document type |
|
|
79
|
-
| `WorkerModule` | Module interface type |
|
|
80
|
-
|
|
81
|
-
## Work Types
|
|
82
|
-
|
|
83
|
-
Work types are linked to worker plugins. Common built-in types:
|
|
84
|
-
|
|
85
|
-
| Type | Description |
|
|
86
|
-
|------|-------------|
|
|
87
|
-
| `SEND_EMAIL` | Send email notifications |
|
|
88
|
-
| `HEARTBEAT` | Keep-alive jobs |
|
|
89
|
-
| `EXTERNAL` | External service calls |
|
|
90
|
-
|
|
91
|
-
## Worker Plugins
|
|
92
|
-
|
|
93
|
-
Workers process jobs by type. The plugin is responsible for:
|
|
94
|
-
- Handling retries on failure
|
|
95
|
-
- Processing the work input
|
|
96
|
-
- Returning success/failure results
|
|
97
|
-
|
|
98
|
-
## Events
|
|
34
|
+
`addWork` returns the work document. The platform's work loop allocates, executes, and finishes internal jobs through `WorkerDirector`. External workers claim jobs with `allocateWork` and report results with `finishWork`; allocation alone does not execute them. Higher numeric priorities are processed first.
|
|
99
35
|
|
|
100
|
-
|
|
101
|
-
|-------|-------------|
|
|
102
|
-
| `WORK_ADDED` | Work item added to queue |
|
|
103
|
-
| `WORK_ALLOCATED` | Work allocated to worker |
|
|
104
|
-
| `WORK_FINISHED` | Work processing completed |
|
|
105
|
-
| `WORK_FAILED` | Work processing failed |
|
|
36
|
+
See the [module settings](https://docs.unchained.shop/platform-configuration/modules/worker), [worker extension guide](https://docs.unchained.shop/extend/worker), [public exports](src/worker-index.ts), and [module implementation](src/module/configureWorkerModule.ts).
|
|
106
37
|
|
|
107
38
|
## License
|
|
108
39
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-worker",
|
|
3
3
|
"description": "Background job and task queue module for the Unchained Engine",
|
|
4
|
-
"version": "5.0.0-alpha.
|
|
4
|
+
"version": "5.0.0-alpha.8",
|
|
5
5
|
"main": "lib/worker-index.js",
|
|
6
6
|
"types": "lib/worker-index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@unchainedshop/events": "^5.0.0-alpha.
|
|
39
|
-
"@unchainedshop/logger": "^5.0.0-alpha.
|
|
40
|
-
"@unchainedshop/mongodb": "^5.0.0-alpha.
|
|
41
|
-
"@unchainedshop/utils": "^5.0.0-alpha.
|
|
38
|
+
"@unchainedshop/events": "^5.0.0-alpha.8",
|
|
39
|
+
"@unchainedshop/logger": "^5.0.0-alpha.8",
|
|
40
|
+
"@unchainedshop/mongodb": "^5.0.0-alpha.8",
|
|
41
|
+
"@unchainedshop/utils": "^5.0.0-alpha.8"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^26.2.0",
|