使用 Laravel 5.1 的队列,当作业失败时我会抛出异常。
throw new \Exception('No luck');
正如 Laravel 在处理失败的作业时建议的那样,我正在“捕捉” 中的异常AppServiceProvider
,并使用它向我们的团队发送电子邮件。
public function boot()
{
Queue::failing(function ($connection, $job, $data) {
$info['data'] = $data;
\Mail::send('emails.jobs.failed', $info, function($message) {
$message->to('test@email.com')->subject('Job failed');
});
});
}
在电子邮件中,我想放置异常消息(在本例中为“不走运。”)。但我不知道如何将它传递给 Queue::failing()。
有任何想法吗?