Skip to main content
Workflow is a system for executing background tasks. Use it for email sending, data processing, scheduled jobs, and more.

Tasks Configuration

Options:
  • enableWorker: Whether to enable Worker (default: true only in daemon mode)
  • workerOptions.concurrency: Number of concurrent tasks (default: 1)
  • workerOptions.usePubSub: Use PostgreSQL LISTEN/NOTIFY (default: true)
  • workerOptions.listenDelay: Wait time after receiving Pub/Sub message (default: 500ms)
  • contextProvider: Function to create Context used within Workflows

WorkflowManager

Sonamu automatically creates and manages the WorkflowManager. Access it via Sonamu.workflows.

Worker Modes

1. Daemon Mode (Auto-enabled)

In daemon mode, enableWorker: true is the default.

2. Separate Worker Process

3. API Server + Worker

Distributed Workers

You can run Workers on multiple servers.
PostgreSQL acts as the task queue, and Workers communicate via Pub/Sub.

Context Provider

Customize the Context used in Workflows.
Access via Sonamu.getContext() within a Workflow function:

Table Structure

Sonamu automatically creates the following tables:

Monitoring

Check Running Workflows

Logging

Next Steps

@workflow Decorator

Define Workflows

Step

Divide tasks with Steps