feature/cierres (#25)
Varios cambios Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #25
This commit is contained in:
@ -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');
|
||||
|
@ -1,18 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
'commands' => function() {
|
||||
return [
|
||||
'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,
|
||||
];
|
||||
'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();
|
||||
}
|
||||
];
|
||||
|
@ -6,10 +6,6 @@ return [
|
||||
$arr['base'],
|
||||
'resources'
|
||||
]);
|
||||
$arr['commands'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['resources'],
|
||||
'commands'
|
||||
]);
|
||||
$arr['cache'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['base'],
|
||||
'cache'
|
||||
|
9
cli/setup/settings/other.php
Normal file
9
cli/setup/settings/other.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
DateTimeZone::class => function(ContainerInterface $container) {
|
||||
return new DateTimeZone($container->get('TZ') ?? 'America/Santiago');
|
||||
},
|
||||
'loopFrequency' => 60
|
||||
];
|
@ -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->get('API_URL'),
|
||||
'base_uri' => $uri,
|
||||
'headers' => [
|
||||
'Authorization' => [
|
||||
'Bearer ' . md5($container->get('API_KEY'))
|
||||
@ -16,18 +17,39 @@ return [
|
||||
$container->get(Psr\Log\LoggerInterface::class),
|
||||
implode(DIRECTORY_SEPARATOR, [$container->get('folders')->cache, 'token']),
|
||||
$container->get('API_USERNAME'),
|
||||
$container->get('API_PASSWORD')
|
||||
$container->get('API_PASSWORD'),
|
||||
$container->get('API_KEY')
|
||||
);
|
||||
},
|
||||
GuzzleHttp\HandlerStack::class => function(ContainerInterface $container) {
|
||||
$stack = new GuzzleHttp\HandlerStack();
|
||||
$stack->setHandler($container->get(GuzzleHttp\Handler\CurlHandler::class));
|
||||
$stack->push(GuzzleHttp\Middleware::mapRequest(function(Psr\Http\Message\RequestInterface $request) use ($container) {
|
||||
$login = $container->get(Incoviba\Service\Login::class);
|
||||
return $request->withHeader('Authorization', "Bearer {$login->getKey()}");
|
||||
}));
|
||||
$stack->push(GuzzleHttp\Middleware::mapRequest(function(Psr\Http\Message\RequestInterface $request) use ($container) {
|
||||
if (!$request->hasHeader('Authorization')) {
|
||||
return false;
|
||||
}
|
||||
return $request;
|
||||
}));
|
||||
return $stack;
|
||||
},
|
||||
Psr\Http\Client\ClientInterface::class => function(ContainerInterface $container) {
|
||||
$login = $container->get(Incoviba\Service\Login::class);
|
||||
return new GuzzleHttp\Client([
|
||||
'base_uri' => $container->get('API_URL'),
|
||||
'headers' => [
|
||||
'Authorization' => [
|
||||
"Bearer {$login->getKey($container->get('API_KEY'))}"
|
||||
]
|
||||
]
|
||||
'base_uri' => $container->has('API_URL') ? $container->get('API_URL') : 'http://proxy/api',
|
||||
'handler' => $container->get(GuzzleHttp\HandlerStack::class),
|
||||
]);
|
||||
}
|
||||
},
|
||||
Incoviba\Service\FastCGI::class => function(ContainerInterface $container) {
|
||||
$fcgi = new Incoviba\Service\FastCGI(
|
||||
$container->get(Incoviba\Service\Login::class),
|
||||
$container->has('SOCKET_HOST') ? $container->get('SOCKET_HOST') : 'web',
|
||||
$container->has('SOCKET_PORT') ? $container->get('SOCKET_PORT') : 9090,
|
||||
$container->has('SOCKET_ROOT') ? $container->get('SOCKET_ROOT') : '/code/public/index.php'
|
||||
);
|
||||
$fcgi->setLogger($container->get(Psr\Log\LoggerInterface::class));
|
||||
return $fcgi;
|
||||
},
|
||||
];
|
||||
|
@ -11,5 +11,21 @@ return [
|
||||
$container->get(Psr\Log\LoggerInterface::class),
|
||||
$container->get('commands')
|
||||
);
|
||||
},
|
||||
Incoviba\Command\BaseLoop::class => function(ContainerInterface $container) {
|
||||
return new Incoviba\Command\BaseLoop(
|
||||
$container->get('LoopLogger'),
|
||||
$container->get(Incoviba\Service\Schedule::class),
|
||||
$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)
|
||||
);
|
||||
}
|
||||
];
|
||||
|
@ -3,35 +3,124 @@ use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
|
||||
return new Monolog\Logger('incoviba', [
|
||||
new Monolog\Handler\FilterHandler(
|
||||
(new Monolog\Handler\RotatingFileHandler('/logs/debug.log', 10))
|
||||
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
|
||||
Monolog\Level::Debug,
|
||||
Monolog\Level::Debug
|
||||
),
|
||||
new Monolog\Handler\FilterHandler(
|
||||
(new Monolog\Handler\RotatingFileHandler('/logs/info.log', 10))
|
||||
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
|
||||
Monolog\Level::Info,
|
||||
Monolog\Level::Warning,
|
||||
),
|
||||
new Monolog\Handler\FilterHandler(
|
||||
(new Monolog\Handler\RotatingFileHandler('/logs/error.log', 10))
|
||||
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
|
||||
Monolog\Level::Error,
|
||||
Monolog\Level::Error
|
||||
),
|
||||
new Monolog\Handler\FilterHandler(
|
||||
(new Monolog\Handler\RotatingFileHandler('/logs/critical.log', 10))
|
||||
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
|
||||
Monolog\Level::Critical
|
||||
)
|
||||
], [
|
||||
$minLogLevel = Monolog\Level::Debug;
|
||||
if ($container->has('DEBUG') and $container->get('DEBUG') === 'false') {
|
||||
$minLogLevel = Monolog\Level::Warning;
|
||||
}
|
||||
$handlers = [];
|
||||
switch($minLogLevel) {
|
||||
case Monolog\Level::Debug:
|
||||
$handlers []= new Monolog\Handler\FilterHandler(
|
||||
($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development')
|
||||
? (new Monolog\Handler\StreamHandler('/logs/debug.log'))
|
||||
->setFormatter($container->get(Monolog\Formatter\LineFormatter::class))
|
||||
: (new Monolog\Handler\RotatingFileHandler('/logs/debug.log', 10))
|
||||
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
|
||||
Monolog\Level::Debug,
|
||||
Monolog\Level::Debug,
|
||||
false
|
||||
);
|
||||
case Monolog\Level::Info:
|
||||
case Monolog\Level::Notice:
|
||||
$handlers []= new Monolog\Handler\FilterHandler(
|
||||
($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development')
|
||||
? (new Monolog\Handler\StreamHandler('/logs/notices.log'))
|
||||
->setFormatter($container->get(Monolog\Formatter\LineFormatter::class))
|
||||
: (new Monolog\Handler\RotatingFileHandler('/logs/info.log', 10))
|
||||
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
|
||||
Monolog\Level::Info,
|
||||
Monolog\Level::Notice,
|
||||
false
|
||||
);
|
||||
case Monolog\Level::Warning:
|
||||
case Monolog\Level::Error:
|
||||
$handlers []= new Monolog\Handler\FilterHandler(
|
||||
($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development')
|
||||
? (new Monolog\Handler\StreamHandler('/logs/error.log'))
|
||||
->setFormatter($container->get(Monolog\Formatter\LineFormatter::class))
|
||||
: (new Monolog\Handler\RotatingFileHandler('/logs/error.log', 10))
|
||||
->setFormatter($container->get(Monolog\Formatter\LineFormatter::class)),
|
||||
Monolog\Level::Warning,
|
||||
Monolog\Level::Error,
|
||||
false
|
||||
);
|
||||
case Monolog\Level::Critical:
|
||||
case Monolog\Level::Alert:
|
||||
case Monolog\Level::Emergency:
|
||||
$handlers []= new Monolog\Handler\FilterHandler(
|
||||
($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development')
|
||||
? (new Monolog\Handler\StreamHandler('/logs/critical.log'))
|
||||
->setFormatter($container->get(Monolog\Formatter\LineFormatter::class))
|
||||
: (new Monolog\Handler\RotatingFileHandler('/logs/critical.log', 10))
|
||||
->setFormatter($container->get(Monolog\Formatter\LineFormatter::class)),
|
||||
Monolog\Level::Critical
|
||||
);
|
||||
}
|
||||
return new Monolog\Logger('incoviba', $handlers, [
|
||||
$container->get(Monolog\Processor\PsrLogMessageProcessor::class),
|
||||
$container->get(Monolog\Processor\IntrospectionProcessor::class),
|
||||
$container->get(Monolog\Processor\MemoryUsageProcessor::class),
|
||||
$container->get(Monolog\Processor\MemoryPeakUsageProcessor::class)
|
||||
]);
|
||||
], $container->get(DateTimeZone::class));
|
||||
},
|
||||
'LoopLogger' => function(ContainerInterface $container) {
|
||||
$handlers = [
|
||||
'warning' => new Monolog\Handler\FilterHandler(
|
||||
new Monolog\Handler\RotatingFileHandler('/logs/loop-error.log', 10),
|
||||
Monolog\Level::Warning
|
||||
),
|
||||
'notice' => new Monolog\Handler\FilterHandler(
|
||||
new Monolog\Handler\RotatingFileHandler('/logs/loop.log', 10),
|
||||
Monolog\Level::Notice,
|
||||
Monolog\Level::Notice
|
||||
),
|
||||
'debug' => new Monolog\Handler\FilterHandler(
|
||||
new Monolog\Handler\RotatingFileHandler('/logs/loop-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/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));
|
||||
}
|
||||
];
|
||||
|
30
cli/setup/setups/services.php
Normal file
30
cli/setup/setups/services.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
Predis\ClientInterface::class => function(ContainerInterface $container) {
|
||||
$options = [
|
||||
'scheme' => 'tcp',
|
||||
'host' => $container->has('REDIS_HOST') ? $container->get('REDIS_HOST') : 'redis',
|
||||
'port' => $container->has('REDIS_PORT') ? $container->get('REDIS_PORT') : 6379
|
||||
];
|
||||
if ($container->has('REDIS_USER')) {
|
||||
$options['username'] = $container->get('REDIS_USER');
|
||||
}
|
||||
if ($container->has('REDIS_PASSWORD')) {
|
||||
$options['password'] = $container->get('REDIS_PASSWORD');
|
||||
}
|
||||
return new Predis\Client($options);
|
||||
},
|
||||
Pheanstalk\Pheanstalk::class => function(ContainerInterface $container) {
|
||||
return Pheanstalk\Pheanstalk::create(
|
||||
$container->get('BEANSTALKD_HOST'),
|
||||
$container->has('BEANSTALKD_PORT') ? $container->get('BEANSTALKD_PORT') : 11300
|
||||
);
|
||||
},
|
||||
Incoviba\Service\MQTT\MQTTInterface::class => function(ContainerInterface $container) {
|
||||
$service = new Incoviba\Service\MQTT($container->get(Psr\Log\LoggerInterface::class));
|
||||
$service->register('default', $container->get(Incoviba\Service\MQTT\Pheanstalk::class));
|
||||
return $service;
|
||||
}
|
||||
];
|
Reference in New Issue
Block a user