如何获取 Laravel 中尝试作业的确切异常?

问题描述 投票:0回答:1

我有一个带有 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

laravel exception notifications queue jobs
1个回答
0
投票

添加一个

failed()
方法来接收导致作业失败的异常作为其参数。然后您可以记录此异常或根据需要进行处理。

public function failed(Exception $exception)
{
    // Log the exception or save it to the database
    Log::error($exception->getMessage());
}
© www.soinside.com 2019 - 2024. All rights reserved.