Skip to main content

RUN WORKFLOWS ON A SCHEDULE

Prerequisites: Swamp installed, a repository with a workflow, swamp serve running. See Create and Run a Workflow if you need to create one first.

Add a trigger block to the workflow

Open your workflow YAML and add a trigger block with a schedule field containing a cron expression:

name: nightly-report
trigger:
  schedule: "0 0 * * *"
jobs:
  - name: main
    steps:
      - name: generate
        task:
          type: behavior
          behavior: my-reporter
          methodName: execute
          inputs:
            run: "echo Running nightly report"
        dependsOn: []

Validate the workflow

swamp workflow validate nightly-report

Validation confirms the trigger schema is valid along with the usual job and step checks.

Start swamp serve

Scheduled triggers only execute when the server is running:

swamp serve

The server picks up all workflows with trigger.schedule and registers them on startup. Each scheduled run is recorded in usage telemetry with triggerSource: schedule. To turn that off, start the server with SWAMP_NO_TELEMETRY=1.

Run schedules concurrently

By default, serve runs one scheduled workflow at a time, in the order the schedules fired. A fire that arrives while another scheduled run is in progress waits in a queue. To let different workflows run at the same time, raise the limit:

swamp serve --max-concurrent-scheduled-runs 4

Or set it in .swamp/serve.yaml:

max-concurrent-scheduled-runs: 4

The environment variable SWAMP_MAX_CONCURRENT_SCHEDULED_RUNS sets the same default. Serve reads the value at startup; restart serve to change it.

This limit is separate from --max-concurrent-runs, which limits runs started through the API. Raising one does not change the other.

A workflow never overlaps itself, whatever the limit:

  • A fire that arrives while the same workflow is still running is skipped, and serve logs a warning.
  • A fire that arrives while the same workflow is queued, not yet running, waits behind it.

Two different workflows that use the same behavior still take turns on that behavior, through the per-behavior lock.

Check queue delay

With the dashboard enabled, the Schedules view shows waiting fires next to each schedule, for example 2 queued · waiting 12m, and the Overview shows the total queued.

To read the same state from a script, query GET /api/v1/health with a server token (see Monitor Server Health to mint one). It shows each token only the workflows that token may read:

curl -s http://127.0.0.1:9090/api/v1/health \
  -H "Authorization: Bearer health-monitor.secret"

Each schedule's queue state is in the response's scheduling object:

{
  "scheduling": {
    "enabled": true,
    "schedules": [
      {
        "workflowId": "a40ea282-6d3c-482c-b7de-e2ccb62c936f",
        "workflowName": "nightly-report",
        "cronExpression": "0 0 * * *",
        "nextRun": "2026-10-29T00:00:00.000Z",
        "running": true,
        "queued": 0,
        "oldestQueuedAt": null,
        "lastQueueDelayMs": 14
      }
    ],
    "timeZone": "Europe/London"
  }
}
Field Meaning
queued Fires waiting to start
oldestQueuedAt When the oldest waiting fire fired, or null if nothing is waiting
lastQueueDelayMs Milliseconds between fire and start for the last run that started, or null

An oldestQueuedAt that keeps getting older, or a lastQueueDelayMs that keeps growing, means scheduled runs are arriving faster than serve starts them. Raise --max-concurrent-scheduled-runs, or spread the schedules out.

The unauthenticated /health endpoint is a liveness check: it answers {"status": "ok", "version": "1"} and lists no schedules.

A higher limit shortens the wait in the queue, not the run itself. Each run still syncs with the datastore around its steps, and with a remote datastore such as S3 that sync can take longer than the work.

Disable scheduling

To start the server without executing any scheduled workflows:

swamp serve --no-schedule

Common cron patterns

Pattern Schedule
0 * * * * Every hour
0 0 * * * Daily at midnight
0 9 * * 1-5 Weekdays at 9:00 AM
*/15 * * * * Every 15 minutes
0 0 * * 0 Weekly on Sunday at midnight

Pass inputs to scheduled runs

If the workflow defines an inputs schema, supply default values in the trigger block:

trigger:
  schedule: "0 0 * * *"
  inputs:
    env: "production"

Override a schedule without editing the workflow

To change the schedule of a workflow — yours or one from an extension — without modifying its YAML file, use swamp workflow trigger set:

swamp workflow trigger set nightly-report --schedule "0 3 * * *"

The override is written to serve.yaml and takes precedence over the workflow's built-in trigger. To include inputs:

swamp workflow trigger set nightly-report --schedule "0 3 * * *" --input env=production

To verify the effective schedule:

swamp workflow trigger get nightly-report

To remove the override and revert to the built-in trigger:

swamp workflow trigger remove nightly-report

Refer to the Workflows reference for the full flag set.