Job retries
This commit is contained in:
@ -5,12 +5,13 @@ use Exception;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Exception\ServiceAction\{Create, Read};
|
||||
use Incoviba\Exception\ServiceAction\{Create, Delete, Read, Update};
|
||||
use Incoviba\Service;
|
||||
|
||||
class Queue extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected Service\Job $jobService, Worker $defaultWorker)
|
||||
public function __construct(LoggerInterface $logger, protected Service\Job $jobService, Worker $defaultWorker,
|
||||
protected int $maxRetries = 5)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
$this->register('default', $defaultWorker);
|
||||
@ -94,9 +95,23 @@ class Queue extends Ideal\Service
|
||||
|
||||
$errors = [];
|
||||
foreach ($jobs as $job) {
|
||||
if ($job->retries >= $this->maxRetries) {
|
||||
try {
|
||||
$this->jobService->remove($job);
|
||||
} catch (Read | Delete $exception) {
|
||||
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$this->runJob($job->id, $request);
|
||||
} catch (Exception) {
|
||||
$job->retries ++;
|
||||
try {
|
||||
$this->jobService->update($job);
|
||||
} catch (Read | Update $exception) {
|
||||
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
|
||||
}
|
||||
$errors []= $job->id;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user