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:
49
app/src/Service/External.php
Normal file
49
app/src/Service/External.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class External extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected Queue $queueService)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
protected array $externalServices;
|
||||
public function register($service): self
|
||||
{
|
||||
if (!isset($this->externalServices)) {
|
||||
$this->externalServices = [$service];
|
||||
return $this;
|
||||
}
|
||||
if (!in_array($service, $this->externalServices)) {
|
||||
$this->externalServices []= $service;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function check(): bool
|
||||
{
|
||||
$errors = [];
|
||||
foreach ($this->externalServices as $externalService) {
|
||||
if (!method_exists($externalService, 'check')) {
|
||||
continue;
|
||||
}
|
||||
$queueData = [
|
||||
'type' => 'checkExternal',
|
||||
'service' => get_class($externalService),
|
||||
'action' => 'check',
|
||||
];
|
||||
if (!$this->queueService->enqueue($queueData)) {
|
||||
$errors []= get_class($externalService);
|
||||
}
|
||||
}
|
||||
if (count($errors) > 0) {
|
||||
$this->logger->error('Could not enqueue check of external services', ['services' => $errors]);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user