Fixes
This commit is contained in:
@ -7,6 +7,7 @@ use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\StyleInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use function Safe\shell_exec;
|
||||
|
||||
@ -27,24 +28,37 @@ class Watch extends Command
|
||||
$io->title('Watch');
|
||||
|
||||
$period = new DateInterval($this->period);
|
||||
$current = new DateTimeImmutable();
|
||||
$current = $this->updateTime($period);
|
||||
$io->info('Starting');
|
||||
$io->info("Start: {$current->format('Y-m-d H:i:s')}");
|
||||
while(true) {
|
||||
$now = new DateTimeImmutable();
|
||||
if ($now->diff($current) === $period) {
|
||||
$io->info('Running Update');
|
||||
$this->runUpdate();
|
||||
$current = $now;
|
||||
}
|
||||
$wait = (new DateTimeImmutable((new DateTimeImmutable())->format('Y-m-d H:i:0')))->add(new DateInterval('PT1M'));
|
||||
$io->info('Running Update');
|
||||
$this->runUpdate();
|
||||
$current = $this->updateTime($period);
|
||||
$wait = $current->add($period);
|
||||
$io->text("Waiting until {$wait->format('Y-m-d H:i:s')}");
|
||||
time_sleep_until($wait->getTimestamp());
|
||||
}
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
protected function runUpdate(): void
|
||||
protected function updateTime(DateInterval $interval): DateTimeImmutable
|
||||
{
|
||||
$t0 = new DateTimeImmutable((new DateTimeImmutable())->format('Y-m-d 00:00:00'));
|
||||
$tf = new DateTimeImmutable((new DateTimeImmutable())->add(new DateInterval('P1D'))->format('Y-m-d 00:00:00'));
|
||||
$now = new DateTimeImmutable();
|
||||
for ($t = $t0; $t < $tf; $t = $t->add($interval)) {
|
||||
$t1 = $t->add($interval);
|
||||
if ($t < $now and $now < $t1) {
|
||||
return $t;
|
||||
}
|
||||
}
|
||||
return $now;
|
||||
}
|
||||
protected function runUpdate(StyleInterface $io): void
|
||||
{
|
||||
$command = "{$this->command} update";
|
||||
$this->logger->info("Running '{$command}'");
|
||||
shell_exec($command);
|
||||
$result = shell_exec($command);
|
||||
$io->note($result);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user