Background job and task queue module for the Unchained Engine
npm install @unchainedshop/core-worker

Background job queue module for the Unchained Engine. Provides a work queue system for async task processing with plugin-based workers.
``bash`
npm install @unchainedshop/core-worker
`typescript
import { configureWorkerModule, WorkStatus } from '@unchainedshop/core-worker';
const workerModule = await configureWorkerModule({ db });
// Add a work item to the queue
const workId = await workerModule.addWork({
type: 'SEND_EMAIL',
input: {
to: 'user@example.com',
template: 'order-confirmation',
},
});
// Find pending work
const pendingWork = await workerModule.findWork({
status: WorkStatus.NEW,
});
// Process work (typically done by worker plugins)
await workerModule.processWork(workId, {
success: true,
result: { messageId: 'abc123' },
});
`
| Export | Description |
|--------|-------------|
| configureWorkerModule | Configure and return the worker module |
| Method | Description |
|--------|-------------|
| findWork | Find work item by ID |findWorkQueue
| | Find work items with filtering |count
| | Count work items matching query |
| Method | Description |
|--------|-------------|
| addWork | Add work item to queue |allocateWork
| | Allocate work to a worker |processWork
| | Mark work as processed |rescheduleWork
| | Reschedule failed work |deleteWork
| | Delete a work item |
| Export | Description |
|--------|-------------|
| WorkStatus | Status values (NEW, ALLOCATED, SUCCESS, FAILED, DELETED) |
| Export | Description |
|--------|-------------|
| Work | Work item document type |WorkerModule
| | Module interface type |
Work types are linked to worker plugins. Common built-in types:
| Type | Description |
|------|-------------|
| SEND_EMAIL | Send email notifications |HEARTBEAT
| | Keep-alive jobs |EXTERNAL
| | External service calls |
Workers process jobs by type. The plugin is responsible for:
- Handling retries on failure
- Processing the work input
- Returning success/failure results
| Event | Description |
|-------|-------------|
| WORK_ADDED | Work item added to queue |WORK_ALLOCATED
| | Work allocated to worker |WORK_FINISHED
| | Work processing completed |WORK_FAILED` | Work processing failed |
|
EUPL-1.2