Automation Worker
The Automation Worker is the background runtime for persisted automation runs. The backend creates each run and its immutable context, then places a small wake-up job containing the run ID and a stable claim ID on the automations BullMQ queue.
The worker does not connect to Postgres and does not expose HTTP endpoints. It uses the backend’s internal NestJS TCP receiver for persistence and backend-owned domain actions.
Queue Endpoint
| Queue | Job name | Producer | Consumer | Purpose |
|---|---|---|---|---|
automations | execute-run | Backend | Automation Worker | Wake the worker for a persisted run |
The queue payload contains runId and claimId. The stable claim ID lets a BullMQ retry recover a backend claim when the original TCP response was lost.
Backend RPC Endpoints
The worker connects to BACKEND_MICROSERVICE_TARGET_HOST and BACKEND_MICROSERVICE_TARGET_PORT. The backend listens on port 3103 by default.
| Pattern | Function |
|---|---|
automation.runtime.run.prepare | Normalize due state and claim or recover a run |
automation.runtime.plan.get | Load the action plan and check for resolved context |
automation.runtime.action.execute | Execute a backend-owned action or prepare an outbound request |
automation.runtime.attempt.latest | Read the latest persisted attempt for an action |
automation.runtime.attempt.create | Create a durable action attempt |
automation.runtime.attempt.update | Persist an action attempt result |
automation.runtime.run.advance | Advance the run cursor |
automation.runtime.run.wait | Store a durable WAIT checkpoint |
automation.runtime.run.succeed | Mark a run successful |
automation.runtime.run.fail | Mark a run permanently failed |
automation.runtime.run.retry | Schedule the next retry timestamp |
automation.runtime.run.dead-letter | Mark an exhausted run as dead-lettered |
automation.runtime.run.notify-failed | Request the backend’s failure notification |
Each RPC has a bounded deadline. AUTOMATIONS_BACKEND_RPC_TIMEOUT_MS defaults to 75000. A timeout is returned to BullMQ so the next job attempt can reconcile the persisted checkpoint before doing more work.
Functionality
- Claims work with stable ownership and resumes persisted checkpoints.
- Executes actions in their configured order.
- Handles
WAITactions and delayed continuations. - Applies action retries and marks exhausted runs as dead-lettered.
- Executes prepared
FORWARD_REQUESTcalls with per-target rate limiting, timeouts, response masking, and circuit breaking. - Delegates
SEND_MAIL,TRIGGER_BROADCAST, andTOGGLE_ROOM_STATEactions to the backend.
Example: Automation Sends Mail
- The backend creates the automation run and enqueues
execute-run. - The worker claims the run over
automation.runtime.run.prepare. - The worker asks the backend to execute the
SEND_MAILaction. - The backend resolves variables, renders the template, prepares attachments and tracking, then enqueues a prepared message on the
mailqueue. - The Mail Gateway sends the message and publishes its result through
mail-results. - The backend persists the result and returns the action outcome to the worker.
- The worker advances the cursor or schedules a retry.
Local Start
Start Valkey and the backend first, then run:
pnpm automation-worker:devUse packages/automation-worker/.env.example as the local environment template.