Alex
Alex

Reputation: 6645

How to handle failed jobs on queueable notifications

When using queueable notifications:

class MyNotification extends Notification implements ShouldQueue
{

    use Queueable;
}

How do I handle failed jobs? If I'd have dispatched the email/notification via a job class I could use the failed method:

public function failed(Exception $exception) {

  Log::debug('MyNotification failed');

}

However the failed method in a notification doesn't work

Upvotes: 0

Views: 1498

Answers (2)

Alex
Alex

Reputation: 6645

Caddy DZ is correct there is a handle() method for notifications: https://github.com/illuminate/notifications/blob/master/SendQueuedNotifications.php#L92

My issue was not importing the Exception class, code should be:

public function failed(\Exception $exception) {

  Log::debug('MyNotification failed');

}

Upvotes: 1

Aleksandar Milivojsa
Aleksandar Milivojsa

Reputation: 385

You should check Laravel documentation here.

For example, in your AppServiceProvider you can add:

public function boot()
{
    Queue::failing(function (JobFailed $event) {
        // $event->connectionName
        // $event->job
        // $event->exception
    });
}

Handling of the failed job is not responsibility of the notifications but of the queues.

Upvotes: 1

Related Questions