diff --git a/cli/setup/setups/commands.php b/cli/setup/setups/commands.php index 2f78fa6..c9b1609 100644 --- a/cli/setup/setups/commands.php +++ b/cli/setup/setups/commands.php @@ -15,7 +15,8 @@ return [ Incoviba\Command\BaseLoop::class => function(ContainerInterface $container) { return new Incoviba\Command\BaseLoop( $container->get('LoopLogger'), - $container->get(Incoviba\Service\Schedule::class) + $container->get(Incoviba\Service\Schedule::class), + $container->get(DateTimeZone::class), ); } ]; diff --git a/cli/src/Command/BaseLoop.php b/cli/src/Command/BaseLoop.php index f2ad1e6..cb06b58 100644 --- a/cli/src/Command/BaseLoop.php +++ b/cli/src/Command/BaseLoop.php @@ -15,12 +15,12 @@ use Incoviba\Service\Schedule; )] class BaseLoop extends Console\Command\Command { - public function __construct(protected LoggerInterface $logger, protected Schedule $scheduleService, ?string $name = null) + public function __construct(protected LoggerInterface $logger, protected Schedule $scheduleService, + protected DateTimeZone $timezone, + ?string $name = null) { parent::__construct($name); - $this->timezone = new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago'); } - protected DateTimeZone $timezone; public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int { @@ -59,6 +59,7 @@ class BaseLoop extends Console\Command\Command $command = $this->getApplication()->find($commandName); } catch (Console\Exception\CommandNotFoundException $exception) { $this->logger->warning($exception); + return self::FAILURE; } $cmd = new Console\Input\ArrayInput([ diff --git a/cli/src/Command/Queue.php b/cli/src/Command/Queue.php index ddd4e5e..8dbf632 100644 --- a/cli/src/Command/Queue.php +++ b/cli/src/Command/Queue.php @@ -16,7 +16,9 @@ use Incoviba\Common\Alias\Command; class Queue extends Command { public function __construct(ClientInterface $client, LoggerInterface $logger, - protected Job $jobService, ?string $name = null) + protected Job $jobService, + protected DateTimeZone $timezone, + ?string $name = null) { parent::__construct($client, $logger, $name); } @@ -25,7 +27,7 @@ class Queue extends Command { $this->logger->debug("Running {$this->getName()}"); $io = new Console\Style\SymfonyStyle($input, $output); - $now = new DateTimeImmutable('now', new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago')); + $now = new DateTimeImmutable('now', $this->timezone); $io->title("[{$now->format('Y-m-d H:i:s e')}] Running Queue..."); $jobs = $this->getJobs($output);