Scheduled Tasks
Introduction
The Laravel framework includes a built-in “cron” system for task scheduling, making it easy to run tasks every minute, hour, day, or other custom frequency. Laravel Cloud allows you to easily enable support for this feature via the Laravel Cloud dashboard.
Enabling the Task Scheduler
The simplest way to begin handling scheduled tasks is to enable the task scheduler on your environment’s App compute cluster. When running the task scheduler on your App compute cluster, schedule tasks will be processed on the same compute instances that handle your application’s incoming HTTP traffic.
To get started, click on your environment’s App compute cluster within the infrastructure canvas dashboard. Then, enable the “Scheduler” toggle. Finally, save and re-deploy the changes to your App compute cluster.
After your deployment is completed, the schedule:run
Artisan command will automatically be invoked every minute on your App compute cluster, allowing your Laravel application to process its scheduled tasks.
If you would like to run scheduled tasks on infrastructure that is separate from the compute that handles your incoming web traffic, you may also enable the task scheduler on a Worker cluster.
Scheduled Tasks and Multiple Replicas
If you have scaled your environment’s compute to use multiple replicas, make sure you are using Laravel’s onOneServer
method when scheduling your tasks. Otherwise, your tasks will run on every replica, which may lead to unexpected behavior in your application. If you intend for a scheduled task to run on all replicas, you may omit the onOneServer
method when scheduling the task.
For more information on Laravel task scheduling, please consult the Laravel task scheduler documentation.
Scheduled Tasks and Hibernation
Scheduled tasks will not be executed on environments that are currently hibernating.
Was this page helpful?