Horizon: Laravel Queue Dashboard
45sQuick intro to Horizon's dashboard showing real-time job stats grabs attention for devs.
▶ Play ClipThis video demonstrates how to install, configure, and use Laravel Horizon to manage queues and jobs, including setting up Redis, running Horizon, and securing the dashboard. The presenter shows a live example from the Kodi Pals project and explains how to configure multiple supervisors for different queues.
Horizon is a Laravel package that helps manage queues and jobs with a beautiful dashboard showing running, pending, and failed jobs.
Install via Composer: `composer require laravel/horizon`. Then run `php artisan horizon:install` to publish config and assets.
The config file `config/horizon.php` contains settings for environments (production, local) and supervisors. Key is to set queue connection to Redis.
Change queue connection from database to Redis in `.env` file. Configure Redis host, password, etc. The presenter uses Docker and a PaaS with ready Redis.
Run `php artisan horizon` to start the Horizon process. The dashboard shows job statistics and auto-balances processes using `balance: auto`.
For multiple queues (e.g., slow and fast), define separate supervisors in the config. Each supervisor can be assigned specific queues and process limits.
In a job class, use `public $queue = 'queue-name';` to specify which queue the job should run on.
Any changes to job code require restarting Horizon for the changes to take effect.
In `AppServiceProvider`, use the `Horizon::auth()` gate to restrict access. Example: check if user email is in an admins array.
The dashboard shows failed jobs with error details. After fixing the error, you can retry the failed job.
Laravel Horizon simplifies queue management with a powerful dashboard and auto-balancing. Proper configuration of Redis, supervisors, and access gates ensures efficient and secure job processing.
"Title promises 'Zero to Hero' but video covers basics only; still delivers solid setup and dashboard review."
What command installs Laravel Horizon?
composer require laravel/horizon
1:15
What command publishes Horizon config and assets?
php artisan horizon:install
1:28
What queue connection does Horizon require?
Redis
2:30
How do you start the Horizon process?
Run `php artisan horizon`
3:59
What does the `balance: auto` setting do?
It automatically balances processes between multiple supervisors based on workload.
4:24
How do you assign a job to a specific queue?
Set the `public $queue` property in the job class to the queue name.
6:25
What must you do after changing job code?
Restart Horizon for the changes to take effect.
7:00
How can you restrict access to the Horizon dashboard?
Define a gate using `Horizon::auth()` in `AppServiceProvider` that checks user permissions.
8:05
What is the purpose of the `admins` array in the Horizon config?
It contains email addresses of users allowed to access the Horizon dashboard.
8:48
Auto-Balancing Processes
Explains how Horizon automatically adjusts process counts between supervisors, a key feature for efficient queue management.
4:24Securing Horizon Dashboard
Demonstrates a practical method to restrict dashboard access using Laravel gates, essential for production security.
8:05Failed Jobs Retry
Shows how to view and retry failed jobs directly from the dashboard, a valuable debugging feature.
9:57[00:00] Horizon is a awesome Laurel package
[00:03] which help you to manage your cues and
[00:06] jobs and it it has a beautiful dashboard
[00:09] which you can see how much jobs is
[00:13] running and how much phase how much runs
[00:16] pending and other things now let me show
[00:19] you in this video uh how we use it in
[00:22] Kodi Pals and also how we use it in
[00:24] other projects we can also configure it
[00:27] for yourself in any projects and I will
[00:29] just talk about the basics so this video
[00:33] should be quick and don't forget to
[00:35] subscribe and like this video if you
[00:38] like if you're interested okay let's go
[00:43] um
[00:44] so I'm in the quadri pals and uh
[00:48] installing Horizon first the mod first
[00:52] go to learn documents document
[00:55] and
[00:58] as you can see in here on the packages
[00:59] there is a horizon package in here
[01:02] there's a documentation it's completed
[01:05] and we don't need anything else but I
[01:08] will go through this document and let me
[01:10] show you how we configure it our
[01:13] application so first we need to install
[01:15] the prison so just I'm using the sale
[01:22] composite require larval Horizon and
[01:25] everything is ready in my project then
[01:28] we must do publish some configs and
[01:30] install the Horizon uh
[01:33] here so after this
[01:37] okay we just need to use the sale
[01:39] Artisan Horizon install and everything
[01:42] is ready in here so uh you may see some
[01:46] files that add to your projects uh one
[01:49] of the file is Horizon on the config
[01:51] file a config folder and this is the
[01:54] basic config of the Horizon and it's
[01:57] good to see and we will check this about
[02:00] the
[02:01] we have just something about this
[02:05] default and supervisor in here if you're
[02:07] using on production and local and
[02:10] everything else you can config the
[02:13] things in here uh the
[02:16] important things is about the production
[02:18] which we use this
[02:20] uh but for now just we are changing
[02:24] something on defaults and I will show
[02:26] you there uh but before using the person
[02:30] we must to put a change our color
[02:33] connection to Q connection to reduce as
[02:37] you may see in here on the previous
[02:39] video we did it on the database and here
[02:42] we must do change it to radius and after
[02:46] you change it to radius you must to
[02:48] configure already's host and password
[02:49] important other things uh I'm using here
[02:52] a Docker as you may see in the could we
[02:56] pass project also on production we have
[02:58] a pass a platform as a service we are
[03:01] using that and there is a ready stair
[03:05] which we can connect to that redis
[03:08] and here we are just using our cache
[03:11] sending our cues to redis and the
[03:16] Horizon View watch our cues and run them
[03:20] and it gives us good
[03:22] data so how we can run it but before
[03:27] running any commands here for running
[03:31] Horizon you must do
[03:34] go on localhost
[03:36] and
[03:38] reason address and as you can see here
[03:41] there is some jobs and activities and
[03:44] other things but this sort of you know
[03:46] and if you see I have some completed job
[03:51] but not for now
[03:53] and it's the failed job and other things
[03:56] in here but let me activate this version
[03:59] for activating Horizon we just need to
[04:03] run artisan
[04:06] Horizon
[04:08] and everything will be fine in here so
[04:12] as you can see we are using the Q
[04:15] default in here and the process will
[04:18] change why this has changed it's because
[04:21] of the on the config as you can see we
[04:24] are using balance Auto and this balance
[04:27] Auto will be balance our processes
[04:31] between the super multiple supervisor
[04:33] wizard
[04:34] and this will change this process and if
[04:38] you have a lot of jobs in EQ it will
[04:42] increase the process and manage by
[04:46] itself
[04:48] so we don't
[04:51] need to change a lot this Horizon but if
[04:55] you have multiple cues uh like we in a
[05:00] project we had a lot of cues and a lot
[05:03] of jobs fire on two queues and one queue
[05:07] was about making another jobs making
[05:11] some jobs for another queue and uh we
[05:15] had a slow q and fast and in Horizon we
[05:20] just separate them by each other and it
[05:23] helps us to gives more process to
[05:28] this queue to run faster and
[05:33] do more jobs and the slower do some more
[05:37] do some less and how we can do this in
[05:40] here as you can see we have some super
[05:42] Resort also on production and local we
[05:45] have things but I will change this
[05:47] default if your environment was the
[05:49] production this will be run in here but
[05:53] here on supervisor I can make another
[05:56] super wizard here and we can change the
[06:00] queues in here uh the Q name in here
[06:03] which will reach supervisor will run
[06:06] which cubes here so we have defaults in
[06:09] Kodi files we don't have too much cues
[06:13] but
[06:14] you can check you can Define uh which
[06:19] queue which job in run in which queue on
[06:23] the job
[06:25] let me find the job in the
[06:28] there is this is a job
[06:31] you just need to
[06:33] public
[06:36] queue let me see
[06:39] yes
[06:40] this is and just name it something like
[06:44] a Discord
[06:46] it's the job of the Discord and here I
[06:50] can just run this
[06:53] Discord in here don't forget to
[06:56] uh it's running like this
[07:00] restart the Horizon oh if you change any
[07:04] code on your jobs you need to change you
[07:07] need to restart the Horizon in your
[07:10] local
[07:11] others it will not run and as you can
[07:15] see we have a Discord and the default in
[07:17] here and if the Discord jobs increases
[07:21] the process will be increases in here
[07:24] but there is some also limitations like
[07:28] how Max process we have and other things
[07:31] that you can see in here
[07:33] so
[07:34] just one more step we are using Horizon
[07:38] also in production uh with uh as here
[07:42] let me show you
[07:44] which The Horizon in here could we Pals
[07:46] for reason and you see the Forbidden in
[07:49] here because I'm not logged in and if I
[07:53] log in by my accounts
[07:56] here
[07:58] okay
[07:59] so I can see the Horizon in here and
[08:03] everything will be fine
[08:05] but how to prevent
[08:08] other users to access this Horizon
[08:11] because we don't want to act we don't
[08:15] want them to access this
[08:18] there's an ability on Horizon service
[08:20] provider which you can see in here on
[08:23] the gate
[08:25] in this case
[08:28] as you can see there is a user and in
[08:32] email we in Array which will check which
[08:36] user can access to the Horizon by
[08:39] default it's empty so how we config this
[08:44] we made on the horizon in here
[08:48] make some make an array called admins
[08:54] and put the admins email in here which
[08:57] My email is
[09:00] this and here we can instead of the
[09:04] empty array uh called uh Verizon
[09:15] to make mistake and admins it's in here
[09:18] and by default we have a empty array in
[09:23] here
[09:23] so this little bit code will prevent
[09:27] other user to access the Horizon and
[09:31] just add means we Define will be
[09:33] accessed here also you can put a complex
[09:37] logic here like if your system has a
[09:39] rule rule and permissions you can check
[09:42] in here it's uh it's a gate and
[09:46] hopefully we could talk about the gates
[09:49] and policies in future in some video
[09:52] okay so let's check some features of the
[09:57] Horizon on the horizon dashboard as you
[10:01] can see I have a lot of failed job in
[10:04] the code V Pals and in here on the fail
[10:08] job we can see what happened and what's
[10:11] the error in here
[10:13] so there is some error and if you fix
[10:16] the error and push the codes you just
[10:19] need to retry this and it will be run
[10:22] another time and all everything will be
[10:24] fine
[10:26] and this things
[10:28] okay thank you for watching I try to
[10:31] explain how we use Horizon and go to
[10:33] vitals and some
[10:36] examples so if you interest in this kind
[10:41] of video please like And subscribe to
[10:42] the channel and in the next video I see
[10:46] you we want to talk more about the queue
[10:49] and the jobs so goodbye
⚡ Saved you time reading this? Transcribe any YouTube video for free — no signup needed.