使用可排队通知时:
class MyNotification extends Notification implements ShouldQueue
{
use Queueable;
}
我该如何处理失败的工作?如果我已经通过工作类别发送了电子邮件/通知,则可以使用失败的方法:
public function failed(Exception $exception) {
Log::debug('MyNotification failed');
}
但是通知中失败的方法不起作用
答案 0 :(得分:1)
您应该查看Laravel文档here。
例如,在您的AppServiceProvider中,您可以添加:
public function boot()
{
Queue::failing(function (JobFailed $event) {
// $event->connectionName
// $event->job
// $event->exception
});
}
处理失败的作业不是通知的责任,而是队列的责任。
答案 1 :(得分:0)
Caddy DZ是正确的,有一个handle()方法用于通知: https://github.com/illuminate/notifications/blob/master/SendQueuedNotifications.php#L92
我的问题不是导入Exception类,代码应为:
public function failed(\Exception $exception) {
Log::debug('MyNotification failed');
}