Version Show
Laravel Horizon
Introduction
Laravel Horizon provides a beautiful dashboard and code-driven configuration for your Laravel powered Redis queues. Horizon allows you to easily monitor key metrics of your queue system such as job throughput, runtime, and job failures. When using Horizon, all of your queue worker configuration is stored in a single, simple configuration file. By defining your application's worker configuration in a version controlled file, you may easily scale or modify your application's queue workers when deploying your application. Installation
You may install Horizon into your project using the Composer package manager:
After installing Horizon, publish its assets using the
ConfigurationAfter publishing Horizon's assets, its primary configuration file will be
located at
EnvironmentsAfter installation, the primary Horizon configuration option that you should familiarize yourself with is the
When you start Horizon, it will use the worker process configuration options for the environment that your application is running on. Typically, the environment is determined by the value of the
SupervisorsAs you can see in Horizon's default configuration file. Each environment can contain one or more "supervisors". By default, the configuration file defines this supervisor as You may add additional supervisors to a given environment if you would like to define a new group of worker processes that should run in that environment. You may choose to do this if you would like to define a different balancing strategy or worker process count for a given queue used by your application. Default ValuesWithin Horizon's default configuration file, you will notice a Balancing StrategiesUnlike Laravel's default queue system, Horizon allows you to choose from three worker balancing strategies:
The When using the
The When the Dashboard AuthorizationHorizon exposes a dashboard at the
Alternative Authentication StrategiesRemember that Laravel automatically injects the authenticated user into the gate closure. If your application is providing Horizon security via another method, such as IP restrictions, then your Horizon users may not need to "login". Therefore, you will need to change Upgrading HorizonWhen upgrading to a new major version of Horizon, it's important that you carefully review the upgrade guide. In addition, when upgrading to any new Horizon version, you should re-publish Horizon's assets:
To keep the assets up-to-date and avoid issues in future updates, you may add the
Running HorizonOnce you have configured your supervisors and workers in your application's
You may pause the Horizon process and instruct it to continue processing jobs using the
You may also pause
and continue specific Horizon supervisors using the
You may check the current status of the Horizon process using the
You may gracefully terminate the Horizon process using the
Deploying HorizonWhen
you're ready to deploy Horizon to your application's actual server, you should configure a process monitor to monitor the During your application's deployment process, you should instruct the Horizon process to terminate so that it will be restarted by your process monitor and receive your code changes:
Installing SupervisorSupervisor is a
process monitor for the Linux operating system and will automatically restart your
Supervisor ConfigurationSupervisor configuration files are typically stored within your server's
When defining your Supervisor
configuration, you should ensure that the value of
Starting SupervisorOnce the configuration file has been created, you may update the Supervisor configuration and start the monitored processes using the following commands:
TagsHorizon allows you to assign “tags” to jobs, including mailables, broadcast events, notifications, and queued event listeners. In fact, Horizon will intelligently and automatically tag most jobs depending on the Eloquent models that are attached to the job. For example, take a look at the following job:
If this job is queued with an
Manually Tagging JobsIf you would like to manually define the tags for one of your queueable objects, you may define a
Notifications
If you would like to be notified when one of your queues has a long wait time, you may use the
Configuring Notification Wait Time ThresholdsYou may configure how many seconds are considered a "long wait"
within your application's
MetricsHorizon includes a metrics dashboard which provides information regarding your job and queue wait times and throughput. In order to populate this dashboard, you should configure Horizon's
Deleting Failed JobsIf you would like to delete a failed job, you may use the
Clearing Jobs From QueuesIf you would like to delete all jobs from your application's default queue, you may do so using the
You may provide the |