diff --git a/cli/src/Command/BaseLoop.php b/cli/src/Command/BaseLoop.php index 642ba46..7251622 100644 --- a/cli/src/Command/BaseLoop.php +++ b/cli/src/Command/BaseLoop.php @@ -21,8 +21,22 @@ class BaseLoop extends Console\Command\Command public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int { - $output->writeln("Running Loop..."); + $this->write($output, 'Running loop...'); + $this->waitNextMinute($output); + + $this->write($output, 'Starting loop...'); + while (true) { + $commands = $this->scheduleService->getPending(); + foreach ($commands as $command) { + $this->runCommand($input, $output, $command); + sleep(10); + } + } + return self::SUCCESS; + } + protected function waitNextMinute(Console\Output\OutputInterface $output): void + { // wait for next minute $now = new DateTimeImmutable(); $nextMinute = new DateTimeImmutable($now->format('Y-m-d H:i:00')); @@ -32,16 +46,6 @@ class BaseLoop extends Console\Command\Command $output->writeln("Waiting {$diff} seconds..."); sleep($diff); } - - $output->writeln('Starting loop...'); - while (true) { - $commands = $this->scheduleService->getPending(); - foreach ($commands as $command) { - $this->runCommand($input, $output, $command); - sleep(10); - } - } - return self::SUCCESS; } protected function runCommand(Console\Input\InputInterface $input, Console\Output\OutputInterface $output, string $commandName): int { @@ -61,4 +65,9 @@ class BaseLoop extends Console\Command\Command return self::FAILURE; } } + protected function write(Console\Output\OutputInterface $output, string $message): void + { + $now = new DateTimeImmutable(); + $output->writeln("[{$now->format('Y-m-d H:i:s e')}] {$message}"); + } } diff --git a/cli/src/Command/Queue.php b/cli/src/Command/Queue.php index ff5b2f0..df4e736 100644 --- a/cli/src/Command/Queue.php +++ b/cli/src/Command/Queue.php @@ -14,7 +14,8 @@ class Queue extends Command { $this->logger->debug("Running {$this->getName()}"); $io = new Console\Style\SymfonyStyle($input, $output); - $io->title("Running Queue..."); + $now = new DateTimeImmutable(); + $io->title("[{$now->format('Y-m-d H:i:s e')}] Running Queue..."); $uri = '/api/queue/run'; $output->writeln("GET {$uri}");