Home / Workflows & MCP / Four ways to schedule tasks: what's beyond cron
Four ways to schedule tasks: what's beyond cron
cron is simple but hard to monitor. systemd timers, container schedulers and in-app scheduling each trade off differently.
"Run a script at a certain time every day" is something cron can handle, but it has three weak spots: logs are hard to find, failures go unnoticed, and the timezone depends on the host.
Comparing the four options
| cron | systemd timer | Container scheduling | In-app | |
|---|---|---|---|---|
| Getting started | Simplest | Medium | Medium | Depends on framework |
| Logs | You redirect them yourself | Collected automatically by journald | Built into the platform | Application logs |
| Retry on failure | None | Limited | Yes | Customizable |
| Dependency management | None | Yes (unit dependencies) | Yes | Yes |
| Best for | Simple scripts | System-level tasks | Multi-machine deployments | Tasks inside a business app |
Using cron correctly
# Run backup daily at 03:10, write logs to disk by date
10 3 * * * /usr/local/bin/backup.sh >> /var/log/backup/$(date +\%F).log 2>&1
Two details: % must be escaped inside crontab; the environment is minimal, so use absolute paths in the script.
When to switch to a systemd timer
If you need a missed run to be caught up (Persistent=true), need the job tied to a service's startup, or need logs in one place — any one of these means switch to systemd.
[Timer]
OnCalendar=*-*-* 03:10:00
Persistent=true
Persistent=true is something cron can't give you: if the machine was off and the run was missed, it runs once after boot.
Where in-app scheduling fits
Business tasks (say, "clean up expired drafts every day") are better off inside the application, because they need access to the app's data layer and config. Putting them in cron tears the business logic in two.
Monitoring is the shared problem
Whichever you use, you have to be able to answer two questions: Did the last run succeed? How long did it take?
The cheapest approach is to write one line of status to a fixed file when the job finishes, and have a health check read it. Without this step, every option is "it ran and then who knows".
Trade-offs for the five options
- cron: only good for fire-and-forget scripts. If you want logs and retries, you write them yourself.
- systemd timer: the first choice for system-level tasks;
Persistent=truecatches up missed runs. - Container scheduling (K8s CronJob, docker timers): for multi-machine setups that need unified observability.
- In-app scheduling (Laravel Schedule, Spring Task): the first choice for business tasks; it can use the app's config and data layer directly.
- External hosting (cloud function scheduled triggers): for cases where "the machine might be off".
One rule of thumb
If a task depends on local state (reads local files, connects to a local database), keep it on the machine; if it just calls an API, external hosting is less hassle.
How to write the monitoring
# Write a status line at the end of the task
echo "$(date -Is) ok $SECONDS" >> /var/log/jobs/backup.status
The health check reads the last line: if it hasn't been updated in over 26 hours, alert. That one line is cheaper than any monitoring system.
Also, keeping the job in the codebase instead of in crontab means it's version-tracked, moving to another machine only requires reinstalling dependencies, and you never hit "this machine's crontab doesn't match the docs".