Skip to main content

Method failed(): Inform Admin About Failure and Perform Cleanup

Premium
3 min read

In the previous lessons, we've learned how to set up and use Laravel queues. Now, let's explore what happens when jobs fail and how we can handle these failures properly using the failed() method.


Implementing the failed() Method

You can define a failed() method directly in your job class. This method will be automatically called by Laravel when the job fails to process.

Let's add a simple implementation to our SendRegisteredUserNotification job:

use Throwable;
 
class SendRegisteredUserNotification implements ShouldQueue
{
// ...
 
public function failed(?Throwable $exception): void
{
info('Failed to process notification: ' . get_class($exception) . ' - ' . $exception->getMessage());
}
}

The failed() method receives the exception that caused the job to fail as its parameter, giving you access to all the details about what went wrong.


How It Works in Practice

When a job fails and you have...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 09 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.