Scheduled tasks (cron)
A cron job is used to schedule periodic tasks at specified times, dates or intervals. Cron is great for creating periodic backups, batch jobs or other types of backend processing.
Cron jobs share most of the same properties as regular containers except for the following:
- Cron jobs cannot be scaled horizontally
- Cron jobs can be suspended which temporarily pauses execution of the job
- Cron jobs run to completion (no long-running processes)
Cron jobs adhere to the same rules as application containers with regard to CI/CD pipeline, deployments and release management.
Creating jobs
Navigate to Settings > Cron jobs in your Site Dashboard. Jobs are defined using YAML syntax.
Example:
jobs:
- name: my-job
schedule: "*/5 * * * *"
command: php -f /path/to/script.php
- name: test-job
schedule: "@daily"
command: echo "hello world"
Each item in the list represents a scheduled task.
Supported fields:
Field | Type | Required | Description |
---|---|---|---|
name | String (only letters, digits, hyphens and underscores) | Yes | Unique name identifying the job |
schedule | String (valid cron expression) | Yes | The interval at which the job should run. Supports numeric notation and macros such as @daily and @every 5m . |
command | String | Yes | The command/script to run. To redirect stdout/stderr you must execute the command in a sub shell, e.g. sh -c "echo test" > /dev/null 2>&1 or use options below. |
discardStdOut | Boolean (default: false ) | No | Sends stdout to /dev/null |
discardStdErr | Boolean (default: false ) | No | Sends stderr to /dev/null |
redirectStdOut | Boolean (default: false ) | No | Prints stdout to main log |
redirectStdErr | Boolean (default: false ) | No | Prints stderr to main log |
suspend | Boolean (default: false ) | No | Pauses execution of the job |
Deleting jobs
To delete a job simply remove the item from the list of job definitions.
Debugging jobs
You can verify that a job is running by looking at the scheduler logs. Navigate to Site Dashboard > Resources and expand the Cron container.
Click on the replica instance to view the logs. Make sure that "scheduler" is selected from the container dropdown menu.
If a command returned an error or there's an error in the jobs definition it will be printed in the logs.