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: model_method
          modelIdOrName: 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.

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"