Uso de request en queue

This commit is contained in:
Juan Pablo Vial
2025-05-13 20:18:40 -04:00
parent ac278ca690
commit 0f0c81e283

View File

@ -2,6 +2,7 @@
namespace Incoviba\Service; namespace Incoviba\Service;
use Exception; use Exception;
use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal; use Incoviba\Common\Ideal;
use Incoviba\Exception\ServiceAction\{Create, Read}; use Incoviba\Exception\ServiceAction\{Create, Read};
@ -34,7 +35,7 @@ class Queue extends Ideal\Service
} }
} }
public function run(): bool public function run(?RequestInterface $request): bool
{ {
try { try {
$jobs = $this->jobService->getPending(); $jobs = $this->jobService->getPending();
@ -55,20 +56,24 @@ class Queue extends Ideal\Service
} }
$worker = $this->workers[$type]; $worker = $this->workers[$type];
if (is_a($worker, Service\Worker\Request::class)) {
$worker->setRequest($request);
}
try { try {
if (!$worker->execute($job)) { if (!$worker->execute($job)) {
$errors []= $job->id; $errors []= $job->id;
} else { continue;
if (!$this->jobService->execute($job)) { }
$errors []= $job->id; if (!$this->jobService->execute($job)) {
} $errors []= $job->id;
} }
} catch (Exception $exception) { } catch (Exception $exception) {
$final = new Exception("Could not run job", 0, $exception); $final = new Exception("Could not run job", 0, $exception);
$this->logger->warning($final); $this->logger->warning($final);
$errors []= $job->id; $errors []= $job->id;
} }
break;
} }
return count($errors) === 0; return count($errors) === 0;
} }