Cambio en queue para que no quede pegado esperando respuesta en cli.
Chequeo de servicios externos para agregar elementos pendientes.
This commit is contained in:
@ -35,7 +35,52 @@ class Queue extends Ideal\Service
|
||||
}
|
||||
}
|
||||
|
||||
public function run(?RequestInterface $request): bool
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getPendingJobs(): array
|
||||
{
|
||||
return $this->jobService->getPending();
|
||||
}
|
||||
public function runJob(int $job_id, ?RequestInterface $request = null): bool
|
||||
{
|
||||
try {
|
||||
$job = $this->jobService->getPendingById($job_id);
|
||||
} catch (Read $exception) {
|
||||
$this->logger->debug($exception);
|
||||
return false;
|
||||
}
|
||||
|
||||
$type = 'default';
|
||||
if (isset($job->configuration['type'])) {
|
||||
$type = strtolower($job->configuration['type']);
|
||||
}
|
||||
if (!isset($this->workers[$type])) {
|
||||
$type = 'default';
|
||||
}
|
||||
|
||||
$worker = $this->workers[$type];
|
||||
if (is_a($worker, Service\Worker\Request::class) and $request !== null) {
|
||||
$worker->setRequest($request);
|
||||
}
|
||||
|
||||
try {
|
||||
if (!$worker->execute($job)) {
|
||||
$this->logger->debug("Could not execute job {$job_id}");
|
||||
return false;
|
||||
}
|
||||
if (!$this->jobService->execute($job)) {
|
||||
$this->logger->debug("Could not remove job {$job_id}");
|
||||
return false;
|
||||
}
|
||||
} catch (Exception $exception) {
|
||||
$final = new Exception("Could not run job", 0, $exception);
|
||||
$this->logger->warning($final);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function run(?RequestInterface $request = null): bool
|
||||
{
|
||||
try {
|
||||
$jobs = $this->jobService->getPending();
|
||||
@ -47,33 +92,11 @@ class Queue extends Ideal\Service
|
||||
|
||||
$errors = [];
|
||||
foreach ($jobs as $job) {
|
||||
$type = 'default';
|
||||
if (isset($job->configuration['type'])) {
|
||||
$type = strtolower($job->configuration['type']);
|
||||
}
|
||||
if (!isset($this->workers[$type])) {
|
||||
$type = 'default';
|
||||
}
|
||||
|
||||
$worker = $this->workers[$type];
|
||||
if (is_a($worker, Service\Worker\Request::class)) {
|
||||
$worker->setRequest($request);
|
||||
}
|
||||
|
||||
try {
|
||||
if (!$worker->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);
|
||||
$this->runJob($job->id, $request);
|
||||
} catch (Exception) {
|
||||
$errors []= $job->id;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return count($errors) === 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user