2021-07-16 14:31:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
2022-04-27 14:24:48 +02:00
|
|
|
namespace App\Command;
|
2021-07-16 14:31:18 +02:00
|
|
|
|
|
|
|
|
2022-04-27 14:24:48 +02:00
|
|
|
use App\Entity\Run;
|
2021-07-16 14:31:18 +02:00
|
|
|
use Doctrine\DBAL\Exception;
|
2022-04-27 14:24:48 +02:00
|
|
|
use App\Repository\RunRepository;
|
|
|
|
use Doctrine\Persistence\ManagerRegistry;
|
2021-07-16 14:31:18 +02:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2022-04-27 14:24:48 +02:00
|
|
|
use Symfony\Component\HttpKernel\KernelInterface;
|
2021-07-16 14:31:18 +02:00
|
|
|
|
|
|
|
class CleanupCommand extends Command
|
|
|
|
{
|
|
|
|
protected static $defaultName = 'cleanup';
|
|
|
|
protected $kernel;
|
2022-04-27 14:24:48 +02:00
|
|
|
protected $doctrine;
|
2021-07-16 14:31:18 +02:00
|
|
|
|
2022-04-27 14:24:48 +02:00
|
|
|
public function __construct(KernelInterface $kernel, ManagerRegistry $doctrine)
|
2021-07-16 14:31:18 +02:00
|
|
|
{
|
|
|
|
$this->kernel = $kernel;
|
2022-04-27 14:24:48 +02:00
|
|
|
$this->doctrine = $doctrine;
|
2021-07-16 14:31:18 +02:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setDescription('Cleanup runs')
|
|
|
|
->setHelp('This command cleans the runs table')
|
|
|
|
->addOption('jobid', 'j', InputOption::VALUE_IS_ARRAY + InputOption::VALUE_REQUIRED, 'The ids of the jobs to clean')
|
|
|
|
->addOption('maxage', 'm', InputOption::VALUE_REQUIRED, 'The maximum age of the oldest runs');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
$maxage = $input->getOption('maxage');
|
|
|
|
$jobs = $input->getOption('jobid');
|
2022-04-27 14:24:48 +02:00
|
|
|
$runRepo = $this->doctrine->getRepository(Run::class);
|
2021-07-16 14:31:18 +02:00
|
|
|
try {
|
|
|
|
$deleted = $runRepo->cleanupRuns($jobs, $maxage);
|
|
|
|
$output->writeln('Deleted ' . $deleted . ' runs');
|
|
|
|
return Command::SUCCESS;
|
|
|
|
} catch(Exception $exception) {
|
|
|
|
$output->writeln($exception->getMessage());
|
|
|
|
return Command::FAILURE;
|
|
|
|
}
|
|
|
|
return Command::SUCCESS;
|
|
|
|
}
|
|
|
|
}
|