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