Improvements and ensured LocateVisitsCommand does not swallow exceptions

This commit is contained in:
Alejandro Celaya 2019-07-23 16:36:56 +02:00
parent 0ec7e8c41b
commit c6fdd8a59f
3 changed files with 44 additions and 10 deletions

View File

@ -1,16 +1,40 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
use Monolog\Handler\StreamHandler;
use Monolog\Logger; use Monolog\Logger;
return [ $isSwoole = extension_loaded('swoole');
'logger' => [ // For swoole, send logs to standard output
'handlers' => [ $logger = $isSwoole ? [
'shlink_rotating_handler' => [ 'handlers' => [
'level' => Logger::DEBUG, 'shlink_rotating_handler' => [
], 'level' => Logger::EMERGENCY, // This basically disables regular file logs
],
'shlink_stdout_handler' => [
'class' => StreamHandler::class,
'level' => Logger::INFO,
'stream' => 'php://stdout',
'formatter' => 'dashed',
], ],
], ],
'loggers' => [
'Shlink' => [
'handlers' => ['shlink_stdout_handler'],
],
],
] : [
'handlers' => [
'shlink_rotating_handler' => [
'level' => Logger::DEBUG,
],
],
];
return [
'logger' => $logger,
]; ];

View File

@ -84,7 +84,9 @@ WORKDIR /home/shlink
# Expose swoole port # Expose swoole port
EXPOSE 8080 EXPOSE 8080
CMD /usr/local/bin/composer update && \ CMD \
# Install dependencies if the vendor dir does not exist
if [[ ! -d "./vendor" ]]; then /usr/local/bin/composer install ; fi && \
# When restarting the container, swoole might think it is already in execution # When restarting the container, swoole might think it is already in execution
# This forces the app to be started every second until the exit code is 0 # This forces the app to be started every second until the exit code is 0
until php ./vendor/bin/zend-expressive-swoole start; do sleep 1 ; done until php ./vendor/bin/zend-expressive-swoole start; do sleep 1 ; done

View File

@ -3,6 +3,7 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\CLI\Command\Visit; namespace Shlinkio\Shlink\CLI\Command\Visit;
use Exception;
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException; use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
use Shlinkio\Shlink\CLI\Util\ExitCodes; use Shlinkio\Shlink\CLI\Util\ExitCodes;
use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface; use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface;
@ -78,8 +79,8 @@ class LocateVisitsCommand extends Command
$this->visitService->locateUnlocatedVisits( $this->visitService->locateUnlocatedVisits(
[$this, 'getGeolocationDataForVisit'], [$this, 'getGeolocationDataForVisit'],
function (VisitLocation $location) use ($output) { static function (VisitLocation $location) use ($output) {
if (! $location->isEmpty()) { if (!$location->isEmpty()) {
$output->writeln( $output->writeln(
sprintf(' [<info>Address located at "%s"</info>]', $location->getCountryName()) sprintf(' [<info>Address located at "%s"</info>]', $location->getCountryName())
); );
@ -88,9 +89,16 @@ class LocateVisitsCommand extends Command
); );
$this->io->success('Finished processing all IPs'); $this->io->success('Finished processing all IPs');
return ExitCodes::EXIT_SUCCESS;
} catch (Exception $e) {
$this->io->error($e->getMessage());
if ($this->io->isVerbose()) {
$this->getApplication()->renderException($e, $this->io);
}
return ExitCodes::EXIT_FAILURE;
} finally { } finally {
$lock->release(); $lock->release();
return ExitCodes::EXIT_SUCCESS;
} }
} }