Batch queue

This commit is contained in:
Juan Pablo Vial
2025-06-30 15:52:28 -04:00
parent 5f4d8a4bc2
commit d4f8804fbb
29 changed files with 525 additions and 134 deletions

View File

@ -1,13 +1,3 @@
<?php
/*function loadCommands(&$app): void {
$files = new FilesystemIterator($app->getContainer()->get('folders')->commands);
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
include_once $file->getRealPath();
}
}
loadCommands($app);*/
$app->setCommandLoader($app->getContainer()->get(Symfony\Component\Console\CommandLoader\CommandLoaderInterface::class));
$app->setDefaultCommand('run:full');
$app->setDefaultCommand('loop');

View File

@ -1,23 +1,26 @@
<?php
use Psr\Container\ContainerInterface;
return [
'commands' => function() {
return [
'loop' => Incoviba\Command\BaseLoop::class,
'comunas' => Incoviba\Command\Comunas::class,
'contabilidad:cartolas:update' => Incoviba\Command\Contabilidad\Cartolas\Update::class,
'money:ipc' => Incoviba\Command\Money\IPC::class,
'money:uf' => Incoviba\Command\Money\UF::class,
'money:uf:update' => Incoviba\Command\Money\UF\Update::class,
'proyectos:activos' => Incoviba\Command\Proyectos\Activos::class,
'run:full' => Incoviba\Command\Full::class,
'ventas:cierres:vigentes' => Incoviba\Command\Ventas\Cierres\Vigentes::class,
'ventas:cuotas:hoy' => Incoviba\Command\Ventas\Cuotas\Hoy::class,
'ventas:cuotas:pendientes' => Incoviba\Command\Ventas\Cuotas\Pendientes::class,
'ventas:cuotas:vencer' => Incoviba\Command\Ventas\Cuotas\PorVencer::class,
'queue' => Incoviba\Command\Queue::class,
'external:services' => Incoviba\Command\ExternalServices::class,
'external:toku:reset' => Incoviba\Command\Ventas\MedioPagos\Toku\Reset::class,
'external:toku:enqueue' => Incoviba\Command\Ventas\MedioPagos\Toku\Enqueue::class
];
'commands' => function(ContainerInterface $container) {
$service = $container->get(Incoviba\Service\Commands::class);
if ($container->has('folders')) {
$folders = $container->get('folders');
if (is_array($folders)) {
if (array_key_exists('commands', $folders)) {
$service->baseCommandsPath = $folders['commands'];
}
} elseif (isset($folders->commands)) {
$service->baseCommandsPath = $folders->commands;
}
}
if ($container->has('skip_commands')) {
$service->skipCommands = $container->get('skip_commands');
}
if ($container->has('skipCommands')) {
$service->skipCommands = $container->get('skipCommands');
}
return $service->getCommandsList();
}
];

View File

@ -6,10 +6,6 @@ return [
$arr['base'],
'resources'
]);
$arr['commands'] = implode(DIRECTORY_SEPARATOR, [
$arr['resources'],
'commands'
]);
$arr['cache'] = implode(DIRECTORY_SEPARATOR, [
$arr['base'],
'cache'

View File

@ -2,7 +2,7 @@
use Psr\Container\ContainerInterface;
return [
DateTimeZone::class => function (ContainerInterface $container) {
DateTimeZone::class => function(ContainerInterface $container) {
return new DateTimeZone($container->get('TZ') ?? 'America/Santiago');
},
'loopFrequency' => 60

View File

@ -3,8 +3,9 @@ use Psr\Container\ContainerInterface;
return [
Incoviba\Service\Login::class => function(ContainerInterface $container) {
$uri = $container->has('API_URL') ? $container->get('API_URL') : 'http://proxy/api';
$client = new GuzzleHttp\Client([
'base_uri' => $container->has('API_URL') ? $container->get('API_URL') : 'http://proxy/api',
'base_uri' => $uri,
'headers' => [
'Authorization' => [
'Bearer ' . md5($container->get('API_KEY'))

View File

@ -19,5 +19,13 @@ return [
$container->get(DateTimeZone::class),
$container->get('loopFrequency'),
);
},
Incoviba\Command\Queue::class => function(ContainerInterface $container) {
return new Incoviba\Command\Queue(
$container->get(Psr\Http\Client\ClientInterface::class),
$container->get('QueueLogger'),
$container->get(Incoviba\Service\Job::class),
$container->get(DateTimeZone::class)
);
}
];

View File

@ -64,27 +64,63 @@ return [
], $container->get(DateTimeZone::class));
},
'LoopLogger' => function(ContainerInterface $container) {
return new Monolog\Logger('loop', [
new Monolog\Handler\FilterHandler(
($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development')
? new Monolog\Handler\StreamHandler('/logs/loop-error.log')
: new Monolog\Handler\RotatingFileHandler('/logs/loop-error.log', 10),
$handlers = [
'warning' => new Monolog\Handler\FilterHandler(
new Monolog\Handler\RotatingFileHandler('/logs/loop-error.log', 10),
Monolog\Level::Warning
),
new Monolog\Handler\FilterHandler(
($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development')
? new Monolog\Handler\StreamHandler('/logs/loop.log')
: new Monolog\Handler\RotatingFileHandler('/logs/loop.log', 10),
'notice' => new Monolog\Handler\FilterHandler(
new Monolog\Handler\RotatingFileHandler('/logs/loop.log', 10),
Monolog\Level::Notice,
Monolog\Level::Notice
),
new Monolog\Handler\FilterHandler(
($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development')
? new Monolog\Handler\StreamHandler('/logs/loop-debug.log')
: new Monolog\Handler\RotatingFileHandler('/logs/loop-debug.log', 10),
'debug' => new Monolog\Handler\FilterHandler(
new Monolog\Handler\RotatingFileHandler('/logs/loop-debug.log', 10),
Monolog\Level::Debug,
Monolog\Level::Debug
)
], [], $container->get(DateTimeZone::class));
];
if ($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development') {
$handlers['warning'] = new Monolog\Handler\FilterHandler(
new Monolog\Handler\StreamHandler('/logs/loop-error.log'),
Monolog\Level::Warning);
$handlers['notice'] = new Monolog\Handler\FilterHandler(
new Monolog\Handler\StreamHandler('/logs/loop.log'),
Monolog\Level::Notice, Monolog\Level::Notice);
$handlers['debug'] = new Monolog\Handler\FilterHandler(
new Monolog\Handler\StreamHandler('/logs/loop-debug.log'),
Monolog\Level::Debug, Monolog\Level::Debug);
}
return new Monolog\Logger('loop', $handlers, [], $container->get(DateTimeZone::class));
},
'QueueLogger' => function(ContainerInterface $container) {
$handlers = [
'warning' => new Monolog\Handler\FilterHandler(
new Monolog\Handler\RotatingFileHandler('/logs/queue-error.log', 10),
Monolog\Level::Warning
),
'notice' => new Monolog\Handler\FilterHandler(
new Monolog\Handler\RotatingFileHandler('/logs/queue.log', 10),
Monolog\Level::Notice,
Monolog\Level::Notice
),
'debug' => new Monolog\Handler\FilterHandler(
new Monolog\Handler\RotatingFileHandler('/logs/queue-debug.log', 10),
Monolog\Level::Debug,
Monolog\Level::Debug
)
];
if ($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development') {
$handlers['warning'] = new Monolog\Handler\FilterHandler(
new Monolog\Handler\StreamHandler('/logs/queue-error.log'),
Monolog\Level::Warning);
$handlers['notice'] = new Monolog\Handler\FilterHandler(
new Monolog\Handler\StreamHandler('/logs/queue.log'),
Monolog\Level::Notice, Monolog\Level::Notice);
$handlers['debug'] = new Monolog\Handler\FilterHandler(
new Monolog\Handler\StreamHandler('/logs/queue-debug.log'),
Monolog\Level::Debug, Monolog\Level::Debug);
}
return new Monolog\Logger('queue', $handlers, [], $container->get(DateTimeZone::class));
}
];