[0:00] welcome to bed films and let me [0:01] introduce you with an official package [0:04] of level which is called larval horizon [0:07] this is a great package and let's first [0:10] quickly get started with this package by [0:12] using this composer command to have this [0:16] inside our level application so he'll is [0:19] a fresh installation of lateral and I [0:21] will say composer require level / [0:23] horizon-- so this package is very useful [0:27] when you are using cues with cue driver [0:31] as readies so it provides a beautiful [0:34] dashboard and some configuration for [0:36] your level power red excu so very [0:39] important thing is you need to use cue [0:42] driver as reddit's this package provides [0:44] this kind of cool dashboard where you [0:47] can have number of jobs number of fill [0:49] job number of processes and you can also [0:51] retry some field job but let's first see [0:55] why we need this kind of package so yeah [1:00] it is installed so here I am and I will [1:02] create a simple notification so make [1:05] notification called user notification [1:08] and this notification is just a simple [1:10] notification which is sending an email [1:12] to a user so I will open web dot PHP [1:16] file and here I will go and send this [1:20] notification to our user so find with [1:24] the idea of one and notify user notify [1:28] with new notify user notification okay [1:34] so we need to grab this user also and at [1:37] last we are going to return simply done [1:40] so I have already configured my dot e [1:43] and we file so with the test database [1:46] and inside our test database we also [1:49] have a one user with the ID of 1 this [1:51] means if I start the server and if I go [1:55] to localhost 8000 [1:58] you will see it is taking long time and [2:02] by the way I also have configured this [2:05] mail trap on our dot env file so here [2:08] you can see I [2:10] have configured so it always take time [2:13] so even if I have one small refresh it [2:15] take time to send an email because it's [2:18] processing the sending part email [2:20] sending part and now we have the to [2:22] email we can make this sending of email [2:26] or sending notification in a queue so I [2:29] will open notify user and here we just [2:33] need to say simply implementing so like [2:36] implements should queue just by using [2:41] this we have now moved this notification [2:44] into queue [2:45] okay so if i refresh this page still it [2:49] is taking time because now if I go and [2:53] on this dot Ian we file I said that [2:56] queue connection is sync so this means [3:01] it is thinking the queue we need to [3:04] change it to red is because now we want [3:06] the queue to be used by Redis once more [3:11] restart the server and refresh this page [3:14] and you can see instantly it's giving [3:17] error because level by default uses PHP [3:21] Redis [3:22] so either you can install PHP Redis or P [3:26] Redis so once more go to level [3:28] documentation and on this documentation [3:31] you can search for Redis and on this [3:36] Redis part you can see we can you either [3:38] use red Pierre IDs or PHP IDs but I [3:41] personally like P Redis and it is very [3:43] easy because it is also given here so [3:45] you need to run this command composer [3:48] command so let's stop the server run [3:51] this composer command finally our peer [3:54] Eddy's is installed so now once more we [3:57] can start the server and go to localhost [4:01] 8080 in this error but why we are [4:06] getting this error because we need to [4:08] tell to level that level don't use PHP [4:11] Redis you need to use the period is how [4:14] we can do that for that we need to go to [4:18] the configuration of Redis so let's go [4:20] and here inside config we have a [4:24] spot inside this database at the last we [4:28] can see we have this red spot and ready [4:31] is using PHP Redis you can simply define [4:34] it on env files so instead of doing this [4:37] from here I will go here and define [4:40] Redis client so like here right if [4:44] client is P Redis very nice we have made [4:49] changes in dot E and V file so we need [4:51] to restart the server and one more try [4:54] and this time with no error and super [4:58] quickly no delay we have moved our email [5:01] into this queues but once more if I [5:06] delete everything from here refresh this [5:08] page you can see we don't have any email [5:11] this means our queues are not processed [5:14] so how we can generally process so we [5:17] can say PHP artisan queue work and then [5:21] if I do this yes now I'm having the [5:25] email because now these notification are [5:28] processed that good but now comes our [5:32] level horizon so let's now continue our [5:35] installation of level horizon so we have [5:38] installed it via this composer command [5:41] but we need to run this command to [5:43] install its effects so I will stop this [5:46] queue worker and then I will say PHP [5:49] artisan horizon : installed so it has [5:52] done three things published the service [5:54] provider some assets and the [5:56] configuration so let's start with the [5:58] configuration on this config folder we [6:00] have this horizontal Asian and in this [6:03] horizontal figuration the unique thing [6:06] you can see we have this path which is [6:08] horizon this means if you have server [6:12] running you can simply go on localhost [6:16] 8004 as on and then you can see you have [6:20] a cool dashboard and instantly you can [6:23] see it has picked two job because [6:26] previously we have ran two jobs so [6:29] without using queue worker and this [6:33] means so we can simply see the recent [6:35] job and other [6:37] things like monitor and matrix but from [6:41] where this dashboard came from the UI [6:44] came from so you can see we have [6:46] published the effects so we have the [6:49] effects inside public vendor assets this [6:52] is just for all the UI it is made [6:55] overview GS and this is because of that [6:58] one more thing we have published is [7:01] service provider which is inside app [7:04] provider and horizontals provider so in [7:08] this horizontal provider we have a boot [7:10] method and a gate method so you can see [7:13] generally we can access this horizon-- [7:16] route even if I am not logged in but [7:20] when you want to give access to this [7:21] horizon dashboard just to one or two [7:24] people you can just define the email [7:27] here like this and then the user with [7:31] this email ID when they are logged in [7:34] then only they can able to access this [7:38] route otherwise they will get 404 that's [7:41] a simple configuration kind of things [7:43] are related to resin but more is inside [7:47] this horizon-- configuration file so we [7:51] have seen that part next is it is going [7:54] to use the connection so default [7:56] connection of Redis and this by default [7:59] prefix everything related to your [8:03] application with horizontal in' if you [8:06] want to make changes in this you need to [8:09] give this information inside your dot [8:12] env file and we can prove this also so I [8:15] will go here and I will say red is CLI [8:18] and if you don't have ready you can [8:21] simply say brew install Redis if you are [8:25] using Mac and for window you can I think [8:27] you can simply find it so ready CLI and [8:30] in this you can simply say keys and X [8:35] tricks you can see we have this horizont [8:38] notifier user and last snapshot this is [8:42] just because of this horizon and this is [8:45] actually the prefix we have we are [8:47] talking about here that's cool there [8:50] middleware and wait time then the most [8:52] important thing here is this environment [8:56] so we have this production environment [8:58] and local end moment so let's talk about [9:01] these things first so what about the [9:05] previous two jobs we have put inside the [9:08] queue so even if I go on localhost 8080 [9:13] processed it processed the notification [9:17] but we are not getting any email inside [9:20] our mail trap so you can see we don't [9:22] have any email say it was eight minutes [9:25] ago okay so to process the queue on this [9:29] Redis with the help of horizon what you [9:32] need to do you need to run the command [9:34] which is PHP artisan horizon-- so it's [9:38] just like you run command PHP artisan [9:40] queue work similar to that we are using [9:43] PHP artisan horizont so horizont started [9:46] successfully and this means now we can [9:49] see it is now converted to active so our [9:52] dashboard is active cool so now because [9: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