v0.5.0
This commit is contained in:
36
app/common/Command/UpdateIp.php
Normal file
36
app/common/Command/UpdateIp.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace ProVM\Command;
|
||||
|
||||
use Exception;
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use ProVM\Service\Remote;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'update',
|
||||
hidden: false
|
||||
)]
|
||||
class UpdateIp extends Command
|
||||
{
|
||||
public function __construct(protected Remote $service, protected LoggerInterface $logger, ?string $name = 'update')
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
try {
|
||||
$this->service->update();
|
||||
return Command::SUCCESS;
|
||||
} catch (PDOException $e) {
|
||||
$this->logger->warning($e);
|
||||
return Command::FAILURE;
|
||||
} catch (Exception $e) {
|
||||
$this->logger->error($e);
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
40
app/common/Command/Watch.php
Normal file
40
app/common/Command/Watch.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?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;
|
||||
|
||||
#[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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user