[00:00]
welcome to bed films and let me
[00:01]
introduce you with an official package
[00:04]
of level which is called larval horizon
[00:07]
this is a great package and let's first
[00:10]
quickly get started with this package by
[00:12]
using this composer command to have this
[00:16]
inside our level application so he'll is
[00:19]
a fresh installation of lateral and I
[00:21]
will say composer require level /
[00:23]
horizon-- so this package is very useful
[00:27]
when you are using cues with cue driver
[00:31]
as readies so it provides a beautiful
[00:34]
dashboard and some configuration for
[00:36]
your level power red excu so very
[00:39]
important thing is you need to use cue
[00:42]
driver as reddit's this package provides
[00:44]
this kind of cool dashboard where you
[00:47]
can have number of jobs number of fill
[00:49]
job number of processes and you can also
[00:51]
retry some field job but let's first see
[00:55]
why we need this kind of package so yeah
[01:00]
it is installed so here I am and I will
[01:02]
create a simple notification so make
[01:05]
notification called user notification
[01:08]
and this notification is just a simple
[01:10]
notification which is sending an email
[01:12]
to a user so I will open web dot PHP
[01:16]
file and here I will go and send this
[01:20]
notification to our user so find with
[01:24]
the idea of one and notify user notify
[01:28]
with new notify user notification okay
[01:34]
so we need to grab this user also and at
[01:37]
last we are going to return simply done
[01:40]
so I have already configured my dot e
[01:43]
and we file so with the test database
[01:46]
and inside our test database we also
[01:49]
have a one user with the ID of 1 this
[01:51]
means if I start the server and if I go
[01:55]
to localhost 8000
[01:58]
you will see it is taking long time and
[02:02]
by the way I also have configured this
[02:05]
mail trap on our dot env file so here
[02:08]
you can see I
[02:10]
have configured so it always take time
[02:13]
so even if I have one small refresh it
[02:15]
take time to send an email because it's
[02:18]
processing the sending part email
[02:20]
sending part and now we have the to
[02:22]
email we can make this sending of email
[02:26]
or sending notification in a queue so I
[02:29]
will open notify user and here we just
[02:33]
need to say simply implementing so like
[02:36]
implements should queue just by using
[02:41]
this we have now moved this notification
[02:44]
into queue
[02:45]
okay so if i refresh this page still it
[02:49]
is taking time because now if I go and
[02:53]
on this dot Ian we file I said that
[02:56]
queue connection is sync so this means
[03:01]
it is thinking the queue we need to
[03:04]
change it to red is because now we want
[03:06]
the queue to be used by Redis once more
[03:11]
restart the server and refresh this page
[03:14]
and you can see instantly it's giving
[03:17]
error because level by default uses PHP
[03:21]
Redis
[03:22]
so either you can install PHP Redis or P
[03:26]
Redis so once more go to level
[03:28]
documentation and on this documentation
[03:31]
you can search for Redis and on this
[03:36]
Redis part you can see we can you either
[03:38]
use red Pierre IDs or PHP IDs but I
[03:41]
personally like P Redis and it is very
[03:43]
easy because it is also given here so
[03:45]
you need to run this command composer
[03:48]
command so let's stop the server run
[03:51]
this composer command finally our peer
[03:54]
Eddy's is installed so now once more we
[03:57]
can start the server and go to localhost
[04:01]
8080 in this error but why we are
[04:06]
getting this error because we need to
[04:08]
tell to level that level don't use PHP
[04:11]
Redis you need to use the period is how
[04:14]
we can do that for that we need to go to
[04:18]
the configuration of Redis so let's go
[04:20]
and here inside config we have a
[04:24]
spot inside this database at the last we
[04:28]
can see we have this red spot and ready
[04:31]
is using PHP Redis you can simply define
[04:34]
it on env files so instead of doing this
[04:37]
from here I will go here and define
[04:40]
Redis client so like here right if
[04:44]
client is P Redis very nice we have made
[04:49]
changes in dot E and V file so we need
[04:51]
to restart the server and one more try
[04:54]
and this time with no error and super
[04:58]
quickly no delay we have moved our email
[05:01]
into this queues but once more if I
[05:06]
delete everything from here refresh this
[05:08]
page you can see we don't have any email
[05:11]
this means our queues are not processed
[05:14]
so how we can generally process so we
[05:17]
can say PHP artisan queue work and then
[05:21]
if I do this yes now I'm having the
[05:25]
email because now these notification are
[05:28]
processed that good but now comes our
[05:32]
level horizon so let's now continue our
[05:35]
installation of level horizon so we have
[05:38]
installed it via this composer command
[05:41]
but we need to run this command to
[05:43]
install its effects so I will stop this
[05:46]
queue worker and then I will say PHP
[05:49]
artisan horizon : installed so it has
[05:52]
done three things published the service
[05:54]
provider some assets and the
[05:56]
configuration so let's start with the
[05:58]
configuration on this config folder we
[06:00]
have this horizontal Asian and in this
[06:03]
horizontal figuration the unique thing
[06:06]
you can see we have this path which is
[06:08]
horizon this means if you have server
[06:12]
running you can simply go on localhost
[06:16]
8004 as on and then you can see you have
[06:20]
a cool dashboard and instantly you can
[06:23]
see it has picked two job because
[06:26]
previously we have ran two jobs so
[06:29]
without using queue worker and this
[06:33]
means so we can simply see the recent
[06:35]
job and other
[06:37]
things like monitor and matrix but from
[06:41]
where this dashboard came from the UI
[06:44]
came from so you can see we have
[06:46]
published the effects so we have the
[06:49]
effects inside public vendor assets this
[06:52]
is just for all the UI it is made
[06:55]
overview GS and this is because of that
[06:58]
one more thing we have published is
[07:01]
service provider which is inside app
[07:04]
provider and horizontals provider so in
[07:08]
this horizontal provider we have a boot
[07:10]
method and a gate method so you can see
[07:13]
generally we can access this horizon--
[07:16]
route even if I am not logged in but
[07:20]
when you want to give access to this
[07:21]
horizon dashboard just to one or two
[07:24]
people you can just define the email
[07:27]
here like this and then the user with
[07:31]
this email ID when they are logged in
[07:34]
then only they can able to access this
[07:38]
route otherwise they will get 404 that's
[07:41]
a simple configuration kind of things
[07:43]
are related to resin but more is inside
[07:47]
this horizon-- configuration file so we
[07:51]
have seen that part next is it is going
[07:54]
to use the connection so default
[07:56]
connection of Redis and this by default
[07:59]
prefix everything related to your
[08:03]
application with horizontal in' if you
[08:06]
want to make changes in this you need to
[08:09]
give this information inside your dot
[08:12]
env file and we can prove this also so I
[08:15]
will go here and I will say red is CLI
[08:18]
and if you don't have ready you can
[08:21]
simply say brew install Redis if you are
[08:25]
using Mac and for window you can I think
[08:27]
you can simply find it so ready CLI and
[08:30]
in this you can simply say keys and X
[08:35]
tricks you can see we have this horizont
[08:38]
notifier user and last snapshot this is
[08:42]
just because of this horizon and this is
[08:45]
actually the prefix we have we are
[08:47]
talking about here that's cool there
[08:50]
middleware and wait time then the most
[08:52]
important thing here is this environment
[08:56]
so we have this production environment
[08:58]
and local end moment so let's talk about
[09:01]
these things first so what about the
[09:05]
previous two jobs we have put inside the
[09:08]
queue so even if I go on localhost 8080
[09:13]
processed it processed the notification
[09:17]
but we are not getting any email inside
[09:20]
our mail trap so you can see we don't
[09:22]
have any email say it was eight minutes
[09:25]
ago okay so to process the queue on this
[09:29]
Redis with the help of horizon what you
[09:32]
need to do you need to run the command
[09:34]
which is PHP artisan horizon-- so it's
[09:38]
just like you run command PHP artisan
[09:40]
queue work similar to that we are using
[09:43]
PHP artisan horizont so horizont started
[09:46]
successfully and this means now we can
[09:49]
see it is now converted to active so our
[09:52]
dashboard is active cool so now because
[09:57]
it is active you can see now but one
[10:01]
previous notification is processed and
[10:03]
once more if I clear this and refresh
[10:07]
this page you can see now it says the
[10:10]
for in the past one in the minute and it
[10:14]
is now processed so it is very very cool
[10:18]
and you can actually check the failed
[10:21]
job so how we can check the failed job
[10:23]
how we can fail a job one crazy thing I
[10:26]
am going to do here is I'm going to say
[10:29]
firstly inside tinker so PHP artisan
[10:32]
tinker and I will say hey tinker create
[10:36]
50 user for me ok so now we have a 50
[10:40]
user inside our database and this means
[10:43]
now I can simply say grab me every user
[10:47]
and for each user notify user very nice
[10:51]
so let's see what's going to happen this
[10:53]
is going to be very very interesting so
[10:56]
now if I say refresh this page instantly
[10:59]
we are getting done but now we have 50
[11:03]
five jobs 54 now and five for the
[11:07]
previous one so you can see it says 45
[11:10]
jobs are in queue it's currently
[11:13]
actually working four and then eight are
[11:16]
failed because we have too much of jobs
[11:20]
and we have just three processes so
[11:24]
while this is processing let's go once
[11:26]
again to the horizon-- configuration and
[11:29]
you can see we can define the number of
[11:31]
process so currently we have three
[11:34]
processes and we have one retry
[11:36]
that's why failed job comes here because
[11:39]
they are just retried once so if I go to
[11:44]
the failed jobs you can see we have a
[11:46]
retry button so if I click here it's now
[11:49]
read trying this so that's cool and now
[11:53]
totally we have 35 and still four are
[11:57]
inside the processes now total zero and
[12:00]
if i refresh out of 50 40 jobs are
[12:04]
failed this is not good so you can see
[12:08]
we just have 10 email here so once again
[12:10]
clear this and now what I'm going to do
[12:13]
I'm going to make processes as 10 and
[12:16]
retry as 5 and whenever you made change
[12:21]
in horizontal you need to restart the
[12:24]
horizon this is very important whenever
[12:26]
you made changes in horizon-- or even in
[12:30]
your notification you need to make
[12:33]
restart this horizont process ok
[12:37]
so for the sake of safety nets I'm also
[12:41]
going to restart the server okay so we
[12:43]
have 56 jobs here 40 are failed and now
[12:47]
because we have restarted it's picked up
[12:49]
that we are working with 10 processes
[12:53]
cool refresh this page and now we have
[12:57]
form 0 7 tasks and after completion you
[13:00]
can see we have total 75 fail previously
[13:03]
it was 40 and now it is 75 that means 35
[13:06]
still feeling okay one more
[13:09]
configuration you can do is like here it
[13:12]
is defined that yeah so you can give the
[13:18]
balance as simple it is given balance as
[13:21]
simple so you can also say Auto so
[13:25]
simple is very simple which configure it
[13:28]
splits incoming job evenly into the
[13:31]
process but if you say auto auto
[13:34]
strategy adjust the number of vocal
[13:37]
processors per cube based on the current
[13:40]
workload ok so I am going to make it
[13:43]
auto and then because we have made
[13:46]
changes let's restart the horizon-- and
[13:49]
now I'm going to say refresh and
[13:54]
refreshing with that and now we have 168
[13:58]
jobs so 50 more is now added so now we
[14:02]
have 1 1 10 field job is still having 35
[14:05]
failing but the processes took less time
[14:08]
to processing all these queues so in
[14:11]
that way you can actually define the
[14:14]
last one which is false which is just a
[14:16]
simple first-come first out kind of
[14:19]
things on notifications or in the queues
[14:22]
so this is a simple demonstration of how
[14:26]
you can use level horizon and how you
[14:28]
can configure with different
[14:30]
configurations there are some more
[14:32]
things on this horizontal continue or
[14:37]
even terminate the horizon simply but in
[14:40]
the next episode we are going to see how
[14:42]
we can actually deploy this horizon
[14:44]
error actually use this horizon on a
[14:47]
server are you going to server with the
[14:50]
supervisor as our client to run the PHP
[14:53]
artisan horizon command ok if you liked
[14:56]
this episode please give it a thumbs up
[14:58]
and comment your views about level
[15:00]
horizont is it a good when you have used
[15:03]
and what makes you to use this package
[15:08]
and don't forget to subscribe to this
[15:10]
channel and like which films on Facebook
[15:12]
Twitter Instagram LinkedIn and feeble
[15:14]
meet in the next episode till then good
[15:15]
bye