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:
46
app/src/Service/Worker/CheckExternal.php
Normal file
46
app/src/Service/Worker/CheckExternal.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Worker;
|
||||
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class CheckExternal extends Ideal\Service implements Service\Worker
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected ContainerInterface $container)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
protected Service\Queue $queueService;
|
||||
|
||||
public function execute(Model\Job $job): bool
|
||||
{
|
||||
$configuration = $job->configuration;
|
||||
$serviceClass = $configuration['service'];
|
||||
if (!$this->container->has($serviceClass)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$service = $this->container->get($serviceClass);
|
||||
} catch (NotFoundExceptionInterface | ContainerExceptionInterface) {
|
||||
return false;
|
||||
}
|
||||
$method = $configuration['method'] ?? 'check';
|
||||
|
||||
if (!method_exists($service, $method)) {
|
||||
return false;
|
||||
}
|
||||
if (!isset($this->queueService)) {
|
||||
$this->queueService = $this->container->get(Service\Queue::class);
|
||||
}
|
||||
$queues = $service->{$method}();
|
||||
foreach ($queues as $queue) {
|
||||
$this->queueService->enqueue($queue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user