我有一个带有 retryUntil 方法的通知类。当通过代码或通知服务器发生异常时,它会尝试直到指定时间,然后使作业失败并显示 MaxAttemptsExceededException (登录到数据库的异常字段)
Illuminate\Queue\MaxAttemptsExceededException: Modules\Insurance\Notifications\IssuePolicyInsuredNotif has been attempted too many times or run too long. The job may have previously timed out.
class InstallmentReminderNotif extends Notification implements ShouldQueue
{
use Queueable;
public $backoff = 20;
protected $message;
public function via($notifiable)
{
return [SmsChannel::class];
}
public function retryUntil(): \DateTime
{
return now()->addMinute();
}
}
我希望它保存每次尝试的每个确切异常,而不是 MaxAttemptsExceededException
添加一个
failed()
方法来接收导致作业失败的异常作为其参数。然后您可以记录此异常或根据需要进行处理。
public function failed(Exception $exception)
{
// Log the exception or save it to the database
Log::error($exception->getMessage());
}