Hora en output

This commit is contained in:
Juan Pablo Vial
2025-05-13 15:40:32 -04:00
parent dfb0ff7aea
commit 5ac324de6a
2 changed files with 22 additions and 12 deletions

View File

@ -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}");
}
}

View File

@ -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}");