This episode is for members only

Sign up to access "Job Batching Progress with Laravel" right now.

Get started
Already a member? Sign in to continue
Playing
06. Inspecting the batch status

Transcript

00:00
There are two main ways that we can inspect the status of our batch.
00:04
The first way is to chain on any methods from bus batch, like the progress, when something failed, and there's a few others that we'll cover as well. But what we can also do is we can take the batch ID, go ahead and fetch it out, and then query it. So let's look at, first of all, implementing the progress callback from our batch.
00:27
So when we go ahead and do this, what we'll get is the batch model itself, or the batch instance itself, directly into here. What we can do then is anything in here from that batch class that we looked at earlier, remember with that list of methods that give us the percentage,
00:44
if it has failures, we can just do anything with that. So in here, let's just go ahead and log out something from here, just so we can see this working behind the scenes. So let's go ahead and use log info, and let's go back over to the batch,
00:57
and look at this progress method. So this is just going to return the percentage progress of all of the jobs that we have. So let's log that out. So batch and progress, and we'll see that in our log file.
01:08
Let's go ahead and open up our log file, and let's get rid of this, and we're going to go over to the database and just clear everything out, so we can start fresh, and we'll get rid of this server as well. Okay, so it's at this point, we want to go ahead and start our queue.
01:21
So let's go php artisan queue work, and let's run that to start our queue. Okay, great. So we're going to go back over and hit create server. We're going to come over to our Laravel log file,
01:31
and let's just wait for the percentage progress for this to roll in. We might need to go ahead and close this off, and just reopen it. And there we go. So we know that we have got three jobs in there, so we get a 33% progress,
01:45
67, and then finally, when this is finished, we get 100. Now, what we're going to be doing in the next couple of episodes is using the progress callback just here to work out how far along each of the jobs are, and we're going to log a model state for each of our jobs in the database.
02:02
What this means is that we'll have a list of all of the jobs within this batch, so the jobs that we get through from our server type. We're going to store these per system in the database, and then we're going to update the state of each one.
02:13
But we're also going to use batch on the UI to work out whether this has been cancelled, or any of the other states that we have for this. So now that we know how to actually get when something progresses, we can use that to start to log the state for each of the jobs that we have.
18 episodes1 hr 37 mins

Overview

Let’s tackle how to batch tasks in Laravel, change their state as they complete, and display step-by-step progress in the UI.

Using job batching we’ll create, dispatch and monitor a list of sequential jobs — changing their state using model states. We’ll also take this a step further to allow batch variations based on different tasks, and the ability to easy swap around the order of tasks.

At the end of the course, we’ll set up a UI with Livewire to poll the state of our batch, displaying progress to the user (and if anything goes wrong).

Simply put, if you’re building something that requires step-by-step jobs to be run and you need to display progress to the user — this course covers absolutely everything you’ll need to know.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!