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:
Juan Pablo Vial
2025-05-15 19:32:25 -04:00
parent 8d32aecd09
commit 8965354528
21 changed files with 687 additions and 65 deletions

View File

@ -14,7 +14,8 @@ return [
'ventas:cuotas:pendientes' => Incoviba\Command\Ventas\Cuotas\Pendientes::class,
'ventas:cuotas:vencer' => Incoviba\Command\Ventas\Cuotas\PorVencer::class,
'queue' => Incoviba\Command\Queue::class,
'loop' => Incoviba\Command\BaseLoop::class
'loop' => Incoviba\Command\BaseLoop::class,
'external:services' => Incoviba\Command\ExternalServices::class
];
}
];

View File

@ -0,0 +1,22 @@
<?php
namespace Incoviba\Command;
use Symfony\Component\Console;
use Incoviba\Common\Alias;
#[Console\Attribute\AsCommand(
name: 'external:services',
description: 'Check external services',
)]
class ExternalServices extends Alias\Command
{
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
{
$url = '/api/external/services/check';
$output->writeln("GET {$url}");
$response = $this->client->get($url);
$output->writeln("Response Code: {$response->getStatusCode()}");
return Console\Command\Command::SUCCESS;
}
}

View File

@ -18,11 +18,48 @@ class Queue extends Command
$now = new DateTimeImmutable();
$io->title("[{$now->format('Y-m-d H:i:s e')}] Running Queue...");
$uri = '/api/queue/run';
$jobs = $this->getJobs($output);
if (is_int($jobs)) {
return $jobs;
}
return $this->runJobs($output, $jobs);
}
protected function getJobs(Console\Output\OutputInterface $output): int|array
{
$uri = '/api/queue/jobs';
$output->writeln("GET {$uri}");
$response = $this->client->get($uri);
$output->writeln("Response Code: {$response->getStatusCode()}");
if ($response->getStatusCode() !== 200) {
return Console\Command\Command::FAILURE;
}
$contents = $response->getBody()->getContents();
if (empty($contents)) {
return [];
}
return json_decode($contents, true)['jobs'];
}
protected function runJobs(Console\Output\OutputInterface $output, array $jobs): int
{
$errors = 0;
foreach ($jobs as $job) {
if ($this->runJob($output, $job) === Console\Command\Command::FAILURE) {
$errors ++;
}
}
return $errors === 0 ? Console\Command\Command::SUCCESS : Console\Command\Command::FAILURE;
}
protected function runJob(Console\Output\OutputInterface $output, int $job_id): int
{
$uri = "/api/queue/run/{$job_id}";
$output->writeln("GET {$uri}");
$response = $this->client->get($uri);
$output->writeln("Response Code: {$response->getStatusCode()}");
return Console\Command\Command::SUCCESS;
return ((int) floor($response->getStatusCode() / 100) === 2) ? Console\Command\Command::SUCCESS : Console\Command\Command::FAILURE;
}
}