Platform.sh User Documentation

Cron Jobs

Back to home

On this page

Try for 30 days
Flexible, version-controlled infrastructure provisioning and development-to-production workflows
Activate your trial

Cron jobs allow you to run scheduled tasks at specified times or intervals. To set up a cron job, add a configuration similar to the following:

.platform.app.yaml
crons:
    snapshot:
        spec: 0 5 * * *
        commands: |
            croncape symfony ...            

To run a command in a cron hook for specific environment types, use the PLATFORM_ENVIRONMENT_TYPE environment variable:

.platform.app.yaml
crons:
    snapshot:
        spec: 0 5 * * *
        commands: |
            # only run for the production environment, aka main branch
            if [ "$PLATFORM_ENVIRONMENT_TYPE" = "production" ]; then
                croncape symfony ...
            fi            

Use croncape Anchor to this heading

When using the Symfony integration, you can use croncape to get feedback through emails when something goes wrong.

To specify which email address croncape must send the feedback emails to, add a MAILTO environment variable. To do so, run the following command:

symfony var:create -y --level=project --name=env:MAILTO --value=sysadmin@example.com

To ensure better reliability, croncape sends the emails using:

  • project-id@cron.noreply.platformsh.site as the sender address (project-id+branch@cron.noreply.platformsh.site for non-main environments)
  • the provided Platform.sh SMTP service, even if you define your own MAILER_* environment variables

To use a custom SMTP and/or custom sender address, follow these steps:

  1. To specify a sender address, define a MAILFROM environment variable.

  2. Define the mandatory environment variables to use your own email service. Note that only SMTP connections are supported.

  3. To disable the provided SMTP service, run symfony cloud:env:info enable_smtp false.

Is this page helpful?