In this episode, we tackle how to handle failed jobs anywhere in a batch job chain. Sometimes, you want the entire batch process to halt if even a single job fails. We walk through forcing a failure in the middle of our chain—specifically on the "install nginx" job—just to see what happens and make sure everything responds as expected.
We use exception throwing to simulate the failure, and then we dive into using the catch
callback for the batch. This callback is invoked as soon as any job in the batch fails. Within this callback, we grab the task currently in progress and explicitly mark it as failed in our system.
After running the queue and setting things up, we observe the batch results: only one job is in a failed state, the rest stop running, and everything is neatly marked so we can later show this info in the UI. Basically, by following along, you’ll see how to ensure failed jobs are properly recorded and the whole chain stops running as soon as any hiccup happens.