2018-04-25 14:03:33 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Command;
|
|
|
|
|
|
|
|
use App\Component\NginxConfigGenerator;
|
|
|
|
use Doctrine\DBAL\Connection;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2018-04-25 17:55:06 +02:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
2018-04-25 14:03:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class CronRunnerCommand
|
|
|
|
* @author Soner Sayakci <shyim@posteo.de>
|
|
|
|
*/
|
2018-04-25 17:55:06 +02:00
|
|
|
class CronRunnerCommand extends Command implements ContainerAwareInterface
|
2018-04-25 14:03:33 +02:00
|
|
|
{
|
2018-04-25 17:55:06 +02:00
|
|
|
use ContainerAwareTrait;
|
|
|
|
|
2018-04-25 14:03:33 +02:00
|
|
|
/**
|
|
|
|
* @var Connection
|
|
|
|
*/
|
|
|
|
private $connection;
|
|
|
|
/**
|
|
|
|
* @var NginxConfigGenerator
|
|
|
|
*/
|
|
|
|
private $configGenerator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CronRunnerCommand constructor.
|
|
|
|
* @param null|string $name
|
|
|
|
* @param Connection $connection
|
|
|
|
* @param NginxConfigGenerator $configGenerator
|
|
|
|
* @author Soner Sayakci <shyim@posteo.de>
|
|
|
|
*/
|
|
|
|
public function __construct(?string $name = null, Connection $connection, NginxConfigGenerator $configGenerator)
|
|
|
|
{
|
|
|
|
parent::__construct($name);
|
|
|
|
$this->connection = $connection;
|
|
|
|
$this->configGenerator = $configGenerator;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Soner Sayakci <shyim@posteo.de>
|
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setName('recast:cron')
|
|
|
|
->setDescription('Reloads RTMP Server if needed');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param InputInterface $input
|
|
|
|
* @param OutputInterface $output
|
|
|
|
* @return int|null|void
|
|
|
|
* @author Soner Sayakci <shyim@posteo.de>
|
|
|
|
* @throws \Doctrine\DBAL\DBALException
|
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
if ($this->connection->fetchColumn('SELECT 1 FROM queue')) {
|
|
|
|
$this->configGenerator->generate();
|
2018-04-25 17:55:06 +02:00
|
|
|
system($this->container->getParameter('nginxRestartCommand'));
|
2018-04-25 14:03:33 +02:00
|
|
|
|
|
|
|
$io = new SymfonyStyle($input, $output);
|
|
|
|
$io->success('Configs generated, rtmp has been reloaded');
|
|
|
|
$this->connection->executeQuery('TRUNCATE queue');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|