【问题标题】:laravel queue (retry jobs 5 times) & mark job as failed "manually"laravel 队列(重试作业 5 次)& 将作业标记为“手动”失败
【发布时间】:2016-12-30 13:16:39
【问题描述】:

我有一个队列运行一些回调请求到我的用户端点。

这是我队列的代码。

    public function handle()
{
    //send webrequest here....

//check the response of user backend
    if ($res->getStatusCode() != 200 || $res->getBody()->getContents() != "*received*")
        throw new Exception('callback url not reachable');
}

public function failed(Exception $exception)
{
    //check tries and try again if needed

//check if job failed for 5 times
//if not ->retry again in 5 minutes, increment the times tried
//if yes ->disable API access, send email

    Log::info("user email send,  callback disabled!");
}

当 webrequest answer 为 != "received" 并检查某个作业是否失败 5 次时,如何让作业失败(我当前的异常使整个作业结束)? 如果作业失败,则应在 5 分钟内重试。

关于这些点我不明白文档。

【问题讨论】:

    标签: exception laravel-5.3 task-queue


    【解决方案1】:

    我知道为时已晚,但昨天我在队列中遇到了同样的问题,当我抛出一个新异常时,队列一次又一次地运行它,直到我的 VM 挂断。实际上,您做得对,您唯一需要添加到代码中的就是为您的作业类的公共区域定义一个尝试变量,它应该只运行 5 次并推送到失败的作业;)

    class NewCustomer implements ShouldQueue
    {
        use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    
        public $tries = 5;

    。 . .

    【讨论】:

      猜你喜欢
      • 2014-11-19
      • 1970-01-01
      • 2017-12-23
      • 2018-08-16
      • 1970-01-01
      • 2021-01-05
      • 2020-11-04
      • 2019-07-10
      • 2021-02-26
      相关资源
      最近更新 更多