In this episode, we roll up our sleeves and dive into updating the progress for each job in a Laravel batch. Previously, we set up our batch and knew that the progress
callback gets called each time a job runs—so now we're making use of that to update task statuses in our database.
First, we look at how to grab the current task that's marked as "in progress." We use a handy Eloquent scope provided by a package to fetch it easily. Once a job is completed, we transition this task's state to "complete." Afterwards, we move on to the next task in the ordered batch, setting its state to "in progress." For this, we add a next()
method on our model, fetching the next task based on its order value.
We do a few test runs: queuing up the jobs, watching the database change as jobs move from "in progress" to "complete", and debugging a little typo that threw us an error (classic dev life). Once fixed, we see everything smoothly update—the tasks transition as expected, one after another.
Finally, we mention that soon we’ll handle what happens if a job fails, getting ready for more robust logic in the next episode. For now, you’ll see exactly how to update and track batch job progress step-by-step.