✦ Sprites 2 Docs

Cron Automations

Run a command on a schedule. A sleeping Sprite is woken for it, and nothing stays on between runs.

On this page

What it is

An automation runs an action on a Sprite on a cron schedule. The schedule can be every minute, every hour, every day, or any other cron interval. If the Sprite is asleep, the automation wakes it and runs the job. If it’s already running, the scheduled job is still delivered and runs as normal. Afterwards the Sprite can go straight back to sleep.

Why it matters: you get recurring work (reports, syncs, health checks, cleanup) without paying for a machine that sits on between runs.

There are two kinds of action:

ActionWhat it does
execRuns a command in the Sprite.
wakeJust wakes the Sprite and keeps it awake for a set time, for example to warm it up before business hours.

Automations can also trigger on a mailbox instead of a schedule; see Mailbox Automations.

Step by step: a scheduled job

We’ll create a job on the Sprite worker that checks a website every five minutes. The safe pattern is: create it paused, test it once, inspect the result, then turn the schedule on.

1. Create the automation, paused

ssh my-org@sprites.dev "automation create worker check-site \
  --cron '*/5 * * * *' \
  --paused \
  --exec \
  --after sleep_if_woken \
  -- curl -fsS https://example.org"
# HTTP API
curl -sS -X PUT "https://api.sprites.dev/v1/sprites/worker/automations/check-site" \
  -H "Authorization: Bearer $SPRITES_TOKEN" -H "Content-Type: application/json" -d '{
    "when": {"type": "cron", "expression": "*/5 * * * *"},
    "action": {"type": "exec", "argv": ["curl", "-fsS", "https://example.org"],
               "after": "sleep_if_woken"},
    "enabled": false}'

What each part means:

  • --cron '*/5 * * * *': a standard five-field cron expression, in UTC unless you add --timezone (e.g. --timezone America/New_York).
  • --paused: save it without enabling the schedule.
  • --exec: the action runs a command.
  • --after sleep_if_woken: put the Sprite back to sleep afterwards, but only if this job is what woke it.
  • --: everything after this is the command.
Watch out

Wrap the whole remote command in double quotes and the cron expression in single quotes. The control plane re-splits the line, and an unquoted * will break it.

2. Run it once by hand

Manual runs work even while the automation is paused:

ssh my-org@sprites.dev automation run worker check-site
# HTTP API (returns 202)
curl -sS -X POST "https://api.sprites.dev/v1/sprites/worker/automations/check-site/run" \
  -H "Authorization: Bearer $SPRITES_TOKEN"

A successful run means the job was accepted, not that it has finished.

3. Check the result

ssh my-org@sprites.dev automation get worker check-site
# HTTP API
curl -sS "https://api.sprites.dev/v1/sprites/worker/automations/check-site" \
  -H "Authorization: Bearer $SPRITES_TOKEN"

Look at:

  • last_finished_at: when it last completed.
  • last_exit_code: 0 means the command succeeded.
  • last_error: any error running it.
  • next_runs: upcoming scheduled times. This is empty while the automation is paused and fills in once you resume it in step 4.

4. Turn the schedule on

ssh my-org@sprites.dev automation resume worker check-site
# HTTP API
curl -sS -X PATCH "https://api.sprites.dev/v1/sprites/worker/automations/check-site" \
  -H "Authorization: Bearer $SPRITES_TOKEN" -H "Content-Type: application/json" -d '{"enabled":true}'

That’s it. The job now runs every five minutes, waking worker if needed.

Common schedules

Cron expressions have five fields: minute, hour, day of month, month, day of week.

ScheduleExpression
Every minute* * * * *
Every 5 minutes*/5 * * * *
Every hour, on the hour0 * * * *
Every day at 02:000 2 * * *
Weekdays at 08:000 8 * * MON-FRI
Every Sunday at midnight0 0 * * SUN
First of the month at 06:3030 6 1 * *

Times are UTC unless you create the automation with --timezone ZONE.

Choosing what happens afterwards

--after (HTTP "after") controls the Sprite once an exec job finishes:

ValueBehavior
noneDo nothing special; the Sprite idles out normally.
sleep_if_wokenSleep, but only if this automation woke it. Recommended for most jobs.
sleepAlways sleep afterwards.

Running shell scripts

Automation commands are argv, not shell syntax. Pipes, &&, variables, and globbing won’t work on their own. Wrap them in a shell:

ssh my-org@sprites.dev "automation create worker nightly-report \
  --cron '0 2 * * *' --exec --after sleep_if_woken \
  -- /bin/sh -lc 'cd /home/sprite/app && ./report.sh > /tmp/report.log 2>&1'"

Or with --argv, which takes a JSON array:

argv='["/bin/sh","-lc","cd /home/sprite/app && ./report.sh"]'
ssh my-org@sprites.dev "automation create worker nightly-report --cron '0 2 * * *' --exec --argv '$argv'"
Tip

A job’s stdout and stderr aren’t kept anywhere you can read them later: not in automation get and not in logs. If you want a job’s output, redirect it to a file as above.

Jobs that call your services

An exec job waits for the Sprite’s services to finish starting before running, so your command can call them. It waits up to 60 seconds, or half the job’s timeout if that’s shorter. If services are still starting after that, the job runs anyway and names the slow services on stderr.

A wake-only schedule

Wake a Sprite at 08:00 UTC on weekdays and keep it awake for 15 minutes:

ssh my-org@sprites.dev "automation create api morning-warmup \
  --cron '0 8 * * MON-FRI' --wake --timeout 900"
# HTTP API
curl -sS -X PUT "https://api.sprites.dev/v1/sprites/api/automations/morning-warmup" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"when":{"type":"cron","expression":"0 8 * * MON-FRI"},"action":{"type":"wake","timeout":900}}'

Managing automations

# List all automations on a Sprite
ssh my-org@sprites.dev automation list worker

# Change only the schedule; the action and history are kept.
ssh my-org@sprites.dev "automation update worker check-site --cron '*/10 * * * *'"

# Pause and resume the schedule
ssh my-org@sprites.dev automation pause worker check-site
ssh my-org@sprites.dev automation resume worker check-site

# Delete it
ssh my-org@sprites.dev automation delete worker check-site
# HTTP API
curl -sS "https://api.sprites.dev/v1/sprites/worker/automations" \
  -H "Authorization: Bearer $SPRITES_TOKEN"
curl -sS -X PATCH "https://api.sprites.dev/v1/sprites/worker/automations/check-site" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"when":{"type":"cron","expression":"*/10 * * * *"}}'
curl -sS -X PATCH "https://api.sprites.dev/v1/sprites/worker/automations/check-site" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"enabled":false}'
curl -sS -X DELETE "https://api.sprites.dev/v1/sprites/worker/automations/check-site" \
  -H "Authorization: Bearer $SPRITES_TOKEN"

When updating, fields you leave out keep their values, but a when or action you supply replaces that whole object.

Good to know

  • Up to 10 automations per Sprite by default (your organization may set a different limit). The 11th is refused with org_limit_exceeded.
  • Pausing, editing, or deleting an automation doesn’t cancel a job that was already accepted.
  • For a Sprite outside the default cluster, use CLUSTER/NAME (e.g. automation list builds/worker).
  • To watch automation state change live, follow the Sprite’s changefeed: ssh my-org@sprites.dev changefeed worker.