Docs/ Operations/ Cron Jobs

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.

  1. Navigate to your service within its stack.
  2. Click the Cron Jobs tab.
  3. Click Add Cron Job.
  4. Enter a descriptive name (e.g., "Daily database cleanup").
  5. Enter the cron expression for the schedule.
  6. Enter the command to execute (e.g., python manage.py cleanup).
  7. Click Create.
Create cron job dialog -- name field, cron expression input with a human-readable preview, and command input
Note
The command runs inside the same container as your service, using the same environment variables, filesystem, and network. This means it can access your database, configuration files, and application code.

Cron Expression Syntax

sh0 uses standard 5-field cron expressions. Each field represents a time unit:

Cron expression format
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, Sunday = 0)
│ │ │ │ │
* * * * *
SymbolMeaningExample
*Every value* * * * * = every minute
,List of values0 8,12,18 * * * = 8am, noon, 6pm
-Range0 9-17 * * * = hourly from 9am to 5pm
/Step*/15 * * * * = every 15 minutes

Common Patterns

Frequently used cron schedules
# 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-5
Tip
When you type a cron expression, sh0 shows a human-readable preview like "Every day at 3:30 AM" so you can verify it before saving.

Selecting 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 mode selector -- radio buttons for 'Single instance' and 'All instances' with descriptions

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.

Cron job execution history table -- showing timestamps, duration, exit codes (0 for success, non-zero for failure), and output preview

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.

Cron job execution detail -- showing full command output with stdout and stderr streams
Note
sh0 retains the last 100 executions per cron job. Older entries are automatically pruned to keep the database lean.

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.
Cron job card with enabled/disabled toggle and a Run Now button

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.
Warning
If a cron job is still running when the next scheduled execution arrives, sh0 skips the new execution to prevent overlap. The skipped execution is logged with a "Skipped (overlap)" status.