Optimized connection to db
This commit is contained in:
@ -3,6 +3,10 @@ use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
ProVM\Command\Watch::class => function(ContainerInterface $container) {
|
||||
return new ProVM\Command\Watch($container->get('period'));
|
||||
}
|
||||
return new ProVM\Command\Watch(
|
||||
$container->get('command'),
|
||||
$container->get('period'),
|
||||
$container->get(Psr\Log\LoggerInterface::class)
|
||||
);
|
||||
},
|
||||
];
|
||||
|
@ -5,12 +5,12 @@ return [
|
||||
Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
|
||||
return new Monolog\Logger('file', [
|
||||
new Monolog\Handler\FilterHandler(
|
||||
new Monolog\Handler\RotatingFileHandler('/var/log/remote.debug.log'),
|
||||
new Monolog\Handler\RotatingFileHandler($container->get('debug_logs_file')),
|
||||
Monolog\Level::Debug,
|
||||
Monolog\Level::Warning
|
||||
),
|
||||
new Monolog\Handler\FilterHandler(
|
||||
new Monolog\Handler\RotatingFileHandler('/var/log/remote.error.log'),
|
||||
new Monolog\Handler\RotatingFileHandler($container->get('error_logs_file')),
|
||||
Monolog\Level::Error
|
||||
)
|
||||
], [
|
||||
@ -32,28 +32,20 @@ return [
|
||||
$container->get(Psr\Log\LoggerInterface::class)
|
||||
);
|
||||
},
|
||||
PDO::class => function(ContainerInterface $container) {
|
||||
ProVM\Service\Connector::class => function(ContainerInterface $container) {
|
||||
$database = $container->get('database');
|
||||
$retries = $container->get('retries');
|
||||
$r = 0;
|
||||
$exception = null;
|
||||
while($r < $retries) {
|
||||
try {
|
||||
$dsn = "mysql:host={$database->get('host')};dbname={$database->get('name')}";
|
||||
return new PDO($dsn, $database->get('user')->get('name'), $database->get('user')->get('password'));
|
||||
} catch (PDOException $e) {
|
||||
if ($exception !== null) {
|
||||
$e = new PDOException($e->getMessage(), $e->getCode(), $exception);
|
||||
}
|
||||
$exception = $e;
|
||||
$container->get(Psr\Log\LoggerInterface::class)->debug('Retrying Connection');
|
||||
}
|
||||
}
|
||||
throw $exception;
|
||||
return new ProVM\Service\Connector(
|
||||
$database->get('host'),
|
||||
$database->get('name'),
|
||||
$database->get('user')->get('name'),
|
||||
$database->get('user')->get('password'),
|
||||
$container->get('retries'),
|
||||
$container->get(Psr\Log\LoggerInterface::class)
|
||||
);
|
||||
},
|
||||
ProVM\Service\Repository::class => function(ContainerInterface $container) {
|
||||
return new ProVM\Service\Repository(
|
||||
$container->get(PDO::class),
|
||||
$container->get(ProVM\Service\Connector::class),
|
||||
$container->get('database')->get('table'),
|
||||
$container->get(Psr\Log\LoggerInterface::class)
|
||||
);
|
||||
|
Reference in New Issue
Block a user