2016-12-30 382 views
0

我有一个队列向我的用户端点运行一些回调请求。laravel queue(重试作业5次)并将作业标记为失败“手动”

下面是我的队列的代码。

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分钟内再次尝试。

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

回答

0

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

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

 
    public $tries = 5;

。 。 。