
Overview
Running on a schedule: itās not just for trains. If your app needs to rebuild a cache every night, prune old data, or email a weekly newsletter to your users, youāre probably looking for a way to run a cron job. Fly.io gives you a few ways to get that done. Weāll walk through options for task scheduling, starting with the most robust and ending with the āit works, okay?ā tier.Cron Manager
Cron Manager is our ābatteries-includedā solution for running scheduled jobs. Itās a small Fly app that spins up temporary Machinesāone per jobāand tears them down afterward. Think of it as a very polite butler that rings a bell and quietly disappears before you remember you donāt have a butler.How It Works
You deploy Cron Manager as its own Fly app. It stays online, watching aschedules.json file. When a jobās scheduled time hits, it boots a one-off Machine with whatever image, region, and resources you specify. That Machine runs the command, exits, and disappears like a good container should.
Jobs run in complete isolationāno shared environment, no weird state carried over from the last job. And because theyāre just Fly Machines, you get all the perks: region placement, resource control, image selection, and clean logs.
Why Use This
- Isolation: Each job gets its own Machine. Nothing leaks.
- Central config:
schedules.jsonlives in Git. Changes are versioned, auditable, and deployable. - Easy updates: Want to change a command or schedule? Update the file and redeploy.
- Job logs: Each Machine has its own logs and lifecycle. Debugging isnāt a treasure hunt.
Setup
- Clone cron-manager
- Create a new Fly app and deploy it with
fly deploy - Set your
FLY_API_TOKENas a secret for the app - Define your job schedules in
schedules.json
Managing Jobs
Once deployed, you can:- List jobs:
cm schedules list - Check history:
cm jobs list <schedule-id> - Peek at details:
cm jobs show <job-id> - Trigger one manually:
cm jobs trigger <schedule-id>
Supercronic
Sometimes you donāt need a full orchestration layerāyou just want a crontab to run inside your app container. Supercronic does that. Itās a container-friendly cron runner that handles environment variables correctly.How It Works
Supercronic runs as a background process inside your app. You add acrontab file, install Supercronic in your Dockerfile, and define a cron process in fly.toml. Done.
Well, almost doneāremember to scale it correctly.
Setup
- Add a crontab file (
/app/crontab) using standard syntax - Install Supercronic in your Dockerfile
- In
fly.toml:
- Scale it:
Scheduled Machines
Fly Machines support basic scheduling out of the box: you can tell a Machine to start hourly, daily, weekly, or monthly. The API is simple. The downside? You donāt get fine-grained controlājust interval buckets. This is fine for non-critical cleanup tasks or anything where āroughly once a dayā is good enough.In-App Scheduling
If youāre already using a scheduler likeapscheduler in a Python appāor youāve duct-taped one together in Nodeāyou can use it to call fly machine run --rm and spin up ephemeral Machines manually.
This gives you full control and is technically elegant, though it does require some careful footwork. Itās the ābuild your own trigger systemā option, best for when youāre already halfway there.
Additional Options
In addition to the options above, you can use an external scheduling service, like GitHub Actions schedule, or easycron, an online cron service which can send out API requests to wake machines up.Summary
If youāre not sure where to start, Cron Manager is the most production-hardened option. But Supercronic gets you 80% of the way with almost no setup, and sometimes thatās all you need.