Queues
Process background jobs queued by your application.
Introduction
The Laravel queue is one of the most popular features of the framework, and Laravel Cloud makes it simple to start queue workers to process jobs that are dispatched by your application for background processing.
Creating Queue Workers
The simplest way to begin processing queued jobs is to add a queue worker background process to your environment’s App compute cluster. When running queue workers on your App compute cluster, queued jobs 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, within the “Background processes” section of your cluster settings, click “New background process”.
Next, configure your queue worker options based on your environment’s requirements and select the number of queue:work
processes within the given configuration that you would like to create. Finally, save and deploy your environment changes to start your queue worker.
When running queue workers via Laravel Cloud, there is no need to run the queue:restart
Artisan command after each deployment.
Worker Clusters
Instead of processing your application’s queued jobs on the App compute instance that also handles your application’s incoming HTTP traffic, you may add queue workers to dedicated Worker clusters. Processing queued jobs on Worker clusters allows you to scale those clusters independently of the App cluster which handles your web traffic.
To add queue workers to a dedicated Worker cluster, you should first create the Worker cluster.
Then, click on the Worker compute cluster within the infrastructure canvas dashboard. Then, within the “Background processes” section of your cluster settings, click “New background process”.
Next, configure your queue worker options based on your environment’s requirements and select the number of queue:work
processes within the given configuration that you would like to create. Finally, save and deploy your environment changes to start your queue worker.
Custom Background Processes
In addition to configuring queue:work
processes, Laravel Cloud also allows you to configure arbitrary long-lived custom background processes, such as Laravel Horizon.
To get started, click on a compute cluster within your environment’s infrastructure canvas dashboard. Then, within the “Background processes” section of your cluster settings, click “New background process”.
Next, click the “Custom worker” tab and provide your custom worker command and the number of instances of the command that should be started. For instance, for Laravel Horizon, you should provide the php artisan horizon
command and specify that Laravel Cloud should create 1
process.
Finally, save and deploy your environment changes to start your custom worker process. Laravel Cloud will automatically restart the process if it exits prematurely.
Queue Workers and Hibernation
Queue workers will be paused on environments that are currently hibernating.
Was this page helpful?