Files
remote_ip/app/common/Command/Watch.php
2023-06-16 22:35:41 -04:00

42 lines
1.0 KiB
PHP

<?php
namespace ProVM\Command;
use DateTimeImmutable;
use DateInterval;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use function Safe\shell_exec;
#[AsCommand(
name: 'watch',
hidden: false
)]
class Watch extends Command
{
public function __construct(protected string $period, string $name = 'watch')
{
parent::__construct($name);
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$period = new DateInterval($this->period);
$current = new DateTimeImmutable();
while(true) {
$now = new DateTimeImmutable();
if ($now->diff($current) === $period) {
$this->runUpdate();
$current = $now;
}
}
return Command::SUCCESS;
}
protected function runUpdate(): void
{
$command = '/app/bin/console update';
shell_exec($command);
}
}