workmatic 1.0.7 → 1.1.0
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 +60 -0
- package/dist/cli.cjs +903 -104
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +903 -104
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +256 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +78 -1
- package/dist/index.d.ts +78 -1
- package/dist/index.js +255 -54
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -63,6 +63,46 @@ worker.process(async (job) => {
|
|
|
63
63
|
worker.start();
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
## Multi-queue orchestration
|
|
67
|
+
|
|
68
|
+
Use `createOrchestrator` to register several queues, control all workers together, and move jobs between queues:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { createDatabase, createOrchestrator } from 'workmatic';
|
|
72
|
+
|
|
73
|
+
const db = createDatabase({ filename: './jobs.db' });
|
|
74
|
+
const orch = createOrchestrator({ db });
|
|
75
|
+
|
|
76
|
+
orch.register('emails', { worker: { concurrency: 4 } });
|
|
77
|
+
orch.register('reports', { worker: { concurrency: 1 } });
|
|
78
|
+
|
|
79
|
+
orch.process('emails', async (job) => { /* send email */ });
|
|
80
|
+
orch.process('reports', async (job) => { /* generate PDF */ });
|
|
81
|
+
|
|
82
|
+
await orch.client('emails').add({ to: 'user@example.com' });
|
|
83
|
+
|
|
84
|
+
orch.startAll();
|
|
85
|
+
|
|
86
|
+
// Move ready/dead jobs to another queue (e.g. retry pipeline)
|
|
87
|
+
await orch.transfer({ from: 'emails', to: 'emails-retry', status: 'dead', resetForRetry: true });
|
|
88
|
+
|
|
89
|
+
await orch.pause('reports');
|
|
90
|
+
await orch.resume('reports');
|
|
91
|
+
|
|
92
|
+
await orch.stopAll();
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
CLI transfer: `workmatic transfer ./jobs.db emails emails-retry --status=dead --retry`
|
|
96
|
+
|
|
97
|
+
See [`examples/orchestrator.ts`](examples/orchestrator.ts) (transfer between queues) and [`examples/orchestrator-processors.ts`](examples/orchestrator-processors.ts) (different `process()` per queue).
|
|
98
|
+
|
|
99
|
+
## Testing
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm test
|
|
103
|
+
npm run test:coverage # requires ≥90% line/branch/function coverage
|
|
104
|
+
```
|
|
105
|
+
|
|
66
106
|
## API Reference
|
|
67
107
|
|
|
68
108
|
Browsable copy with anchored sections: **[`docs/index.html`](docs/index.html)** (API from [`#api-database`](docs/index.html#api-database)).
|
|
@@ -201,6 +241,26 @@ Stop processing and wait for current jobs to finish.
|
|
|
201
241
|
await worker.stop();
|
|
202
242
|
```
|
|
203
243
|
|
|
244
|
+
### `createOrchestrator(options)`
|
|
245
|
+
|
|
246
|
+
Manage multiple queues with shared lifecycle and transfer helpers.
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
const orch = createOrchestrator({ db });
|
|
250
|
+
|
|
251
|
+
orch.register('emails', { worker: { concurrency: 4 } });
|
|
252
|
+
const client = orch.client('emails'); // or use return value of register()
|
|
253
|
+
|
|
254
|
+
orch.process('emails', async (job) => { /* ... */ });
|
|
255
|
+
orch.startAll();
|
|
256
|
+
await orch.stopAll();
|
|
257
|
+
|
|
258
|
+
await orch.transfer({ from: 'emails', to: 'retry', status: 'dead', resetForRetry: true });
|
|
259
|
+
await orch.moveJob(jobId, 'archive');
|
|
260
|
+
await orch.pause('emails');
|
|
261
|
+
await orch.resume('emails');
|
|
262
|
+
```
|
|
263
|
+
|
|
204
264
|
#### `worker.pause()` / `worker.resume()`
|
|
205
265
|
|
|
206
266
|
Pause and resume job processing.
|