Answer the question
In order to leave comments, you need to log in
Laravel, queue, database. How to repeat the same task?
How to repeat the same task?
In the task, if I myself call throw to stop its execution. But I need to add the same job back to the queue. The release($daily = 0) method does not fire inside the failed( Exception $exception) method of the Job class, but does fire in the provider
public function boot()
{
Queue::failing(function (JobFailed $event) {
if ($event->job->getQueue() == SendApiJob::QUEUE_NAME) {
// Если задача выполняется больше N раз
if($event->job->attempts() >= 3){
// Отправить пользователю уведомление о том что попытки отправить api провалились
logger()->alert('Превышен лимит повторных выполнений заданий в очереди ' . SendApiJob::QUEUE_NAME);
}else{
$event->job->release(10);
}
}
});
}
Redis::throttle('redis_queue_throttle')->allow(1)->every(5)->then(function () {
// code ...
throw new \Exception("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 1);
}, function () {
// Could not obtain lock...
return $this->release(5);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question