Cron Jobs
Schedule recurring tasks that run inside your containers. From database cleanups to report generation, cron jobs automate repetitive operations on a defined schedule.
Creating a Cron Job
Cron jobs are created at the service level. Each job executes a command inside the service's running container.
- Navigate to your service within its stack.
- Click the Cron Jobs tab.
- Click Add Cron Job.
- Enter a descriptive name (e.g., "Daily database cleanup").
- Enter the cron expression for the schedule.
- Enter the command to execute (e.g.,
python manage.py cleanup). - Click Create.
Cron Expression Syntax
sh0 uses standard 5-field cron expressions. Each field represents a time unit:
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, Sunday = 0)
│ │ │ │ │
* * * * *| Symbol | Meaning | Example |
|---|---|---|
| * | Every value | * * * * * = every minute |
| , | List of values | 0 8,12,18 * * * = 8am, noon, 6pm |
| - | Range | 0 9-17 * * * = hourly from 9am to 5pm |
| / | Step | */15 * * * * = every 15 minutes |
Common Patterns
# Every minute
* * * * *
# Every 5 minutes
*/5 * * * *
# Every hour at minute 0
0 * * * *
# Every day at midnight
0 0 * * *
# Every day at 3:30 AM
30 3 * * *
# Every Monday at 9:00 AM
0 9 * * 1
# First day of every month at midnight
0 0 1 * *
# Every weekday (Mon-Fri) at 6:00 AM
0 6 * * 1-5Selecting the Target Container
When a service has multiple replicas, you need to decide which container runs the cron job. sh0 offers two execution modes:
- Single instance (default) -- The job runs in one container only, preventing duplicate execution. This is the right choice for database migrations, report generation, or any task that should not run concurrently.
- All instances -- The job runs in every replica. Use this for cache warming, local file cleanup, or tasks that need to run on each instance.
Execution History & Logs
Every cron job execution is recorded with its start time, end time, exit code, and output. View execution history from the cron job detail page.
Click on any execution to see the full stdout and stderr output. This is invaluable for debugging failed jobs or verifying that a task completed correctly.
Enabling & Disabling Jobs
You can temporarily disable a cron job without deleting it. This is useful during maintenance windows or when debugging an issue caused by a scheduled task.
- Toggle the Enabled switch on the cron job card to disable or re-enable it.
- Disabled jobs retain their configuration and history -- nothing is lost.
- You can also trigger a manual run by clicking Run Now, regardless of the schedule.
Error Handling & Retries
When a cron job exits with a non-zero status code, sh0 marks the execution as failed. You can configure automatic retries and failure notifications:
- Retries -- Set the number of retry attempts (0-5) and the delay between retries.
- Timeout -- Set a maximum execution time. Jobs that exceed this limit are killed.
- Failure alerts -- Configure alerts to be notified when a job fails. Works with the same notification channels as metric alerts.