async
@webda/async
Durable asynchronous job orchestration for Webda — queue a service method call, track its status, and optionally schedule it for later execution.
When to use it
- You need to offload long-running work (report generation, data imports) to a background worker without blocking the HTTP response.
- You want to schedule a recurring or time-delayed operation (cron-based or timestamp-based).
- You need a persistent audit trail of job executions with status, logs, and results stored in a Webda Store.
Install
pnpm add @webda/async
Configuration
{
"services": {
"AsyncActionsQueue": {
"type": "MemoryQueue"
},
"asyncJobService": {
"type": "AsyncJobService",
"queue": "AsyncActionsQueue",
"url": "/async",
"runners": ["serviceRunner"],
"includeCron": true,
"logsLimit": 500
},
"serviceRunner": {
"type": "ServiceRunner"
}
}
}
| Parameter | Type | Default | Required | Description |
|---|---|---|---|---|
queue | string | "AsyncActionsQueue" | Yes | Name of the Queue service to dispatch jobs through |
url | string | "/async" | No | URL prefix for the status hook endpoint |
runners | string[] | [] | Yes | List of Runner service names to execute jobs |
localLaunch | boolean | false | No | Execute jobs inline (no queue) — useful for development |
fallbackOnFirst | boolean | false | No | Use first runner if no runner matches the job type |
concurrencyLimit | number | — | No | Maximum number of jobs running concurrently |
includeCron | boolean | true | No | Auto-schedule @Cron-annotated methods as async actions |
logsLimit | number | 500 | No | Max log lines retained per job in the store |
asyncOperationDefinition | string | — | No | Path to a JSON file of operation definitions generated by webda operations |
schedulerResolution | number | 60000 | No | Scheduler tick interval in milliseconds |
Usage
import { Service } from "@webda/core";
import { Bean, Inject } from "@webda/core";
import AsyncJobService from "@webda/async/services/asyncjobservice";
@Bean
export class ReportService extends Service {
@Inject("asyncJobService")
asyncJobService: AsyncJobService;
// Expose an HTTP endpoint that queues a job and returns immediately
async generateReport(ctx: any): Promise<void> {
const action = await this.asyncJobService.launchAsAsyncAction(
"ReportService", // service name
"runReport", // method name
ctx.getParameters().reportId
);
ctx.write({ jobId: action.getUuid(), status: action.status });
}
// This method runs inside the worker process
async runReport(reportId: string): Promise<void> {
// ... long-running work here
}
}
// Start the worker (typically in a separate process)
// asyncJobService.worker().then(() => console.log("worker stopped"));
Reference
- API reference: see the auto-generated typedoc at
docs/pages/Modules/async/. - Source:
packages/async - Related:
@webda/amqpfor a RabbitMQ-backed queue,@webda/awsfor SQS,@webda/corefor the baseQueueandStoreabstractions.
CoreServices
Other
- ActionMemoryLogger
- AsyncAction
- AsyncEvent
- AsyncJobService
- AsyncJobServiceParameters
- AsyncOperationAction
- AsyncWebdaAction
- EventServiceParameters
- LocalRunner
- LocalRunnerParameters
- Runner
- RunnerParameters
- ServiceRunner
- ServiceRunnerParameters
- AgentInfo
- AsyncActionQueueItem
- JobInfo
- NodeAgentInfo
- ProcessAction
- QueueMap
- ServiceAction
- ActionLogTarget