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:

FieldTypeRequiredDescription
nameString (only letters, digits, hyphens and underscores)YesUnique name identifying the job
scheduleString (valid cron expression)YesThe interval at which the job should run. Supports numeric notation and macros such as @daily and @every 5m.
commandStringYesThe 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.
discardStdOutBoolean
(default: false)
NoSends stdout to /dev/null
discardStdErrBoolean
(default: false)
NoSends stderr to /dev/null
redirectStdOutBoolean
(default: false)
NoPrints stdout to main log
redirectStdErrBoolean
(default: false)
NoPrints stderr to main log
suspendBoolean
(default: false)
NoPauses 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.

Cron job logs