Optimized connection to db

This commit is contained in:
2023-06-18 19:20:06 -04:00
parent 781858a905
commit 8d8eb84e20
13 changed files with 128 additions and 39 deletions

View File

@ -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\SymfonyStyle;
use function Safe\shell_exec;
#[AsCommand(
@ -15,27 +16,35 @@ use function Safe\shell_exec;
)]
class Watch extends Command
{
public function __construct(protected string $period, string $name = 'watch')
public function __construct(protected string $command, protected string $period, protected LoggerInterface $logger, string $name = 'watch')
{
parent::__construct($name);
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Watch');
$period = new DateInterval($this->period);
$current = new DateTimeImmutable();
$io->info('Starting');
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'));
time_sleep_until($wait->getTimestamp());
}
return Command::SUCCESS;
}
protected function runUpdate(): void
{
$command = '/app/bin/console update';
$command = "{$this->command} update";
$this->logger->info("Running '{$command}'");
shell_exec($command);
}
}