Upsun User Documentation

Set up cron jobs

Try Upsun for 15 days
After that, enjoy the same, game-changing Upsun features for less with the First Project Incentive!ยน A monthly $19 perk!
ยนTerms and conditions apply
Activate your 15-day trial

Cron jobs allow you to run scheduled tasks at specified times or intervals.

While you can run your own custom tasks, Laravel provides a scheduler to simplify the implementation. To implement it, see the Laravel Task Scheduling documentation.

Set up a cron job Anchor to this heading

To set up a cron job, update your Upsun configuration as follows:

.upsun/config.yaml
applications:
    myapp:
        [...]
        crons:
            snapshot:
                spec: "* * * * *"
                commands: 
                    start: |
                        php artisan schedule:run >> /dev/null 2>&1                        

Run cron jobs based on environment type Anchor to this heading

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

.upsun/config.yaml
applications:
    myapp:
        [...]
        crons:
            snapshot:
                spec: 0 5 * * *
                commands: 
                    start: |
                        # only run for the production environment, aka main branch
                        if [ "$PLATFORM_ENVIRONMENT_TYPE" = "production" ]; then
                            php artisan schedule:run >> /dev/null 2>&1
                        fi                        

Run the Laravel scheduler every minute Anchor to this heading

Cron job execution on the default Upsun offering are limited to once every 5 minutes. For more information, see the documentation on crons.

However, you can add a worker and specify a start command that runs the scheduler every minute. To do so, use the following configuration:

.upsun/config.yaml
applications:
    [...]
        APP_NAME:
            [...]
            workers:
                scheduler:
                    commands:
                        start: |
                            php artisan schedule:work                            

Is this page helpful?