laravel队列(重试作业5次)并将作业标记为“手动”失败

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

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

这是我队列的代码。

    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回答是!=“收到”并检查某个作业是否失败了5次?如果作业失败,应在5分钟后再次尝试。

我不明白有关这些要点的文件。

exception laravel-5.3 task-queue
1个回答
0
投票

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

class NewCustomer implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $tries = 5;

. . .

© www.soinside.com 2019 - 2024. All rights reserved.