diff --git a/src/Cron/CronCommand.php b/src/Cron/CronCommand.php index cf5b996e18f0a1cfbc9671a0bfee8ccb870d7186..521484da8a45ece609c32c42642318f22f80e8ac 100644 --- a/src/Cron/CronCommand.php +++ b/src/Cron/CronCommand.php @@ -10,6 +10,7 @@ use Psr\Log\LoggerAwareTrait; use Psr\Log\NullLogger; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; final class CronCommand extends Command implements LoggerAwareInterface @@ -34,19 +35,25 @@ final class CronCommand extends Command implements LoggerAwareInterface protected function configure() { $this->setDescription('Runs various tasks which need to be executed periodically'); + $this->addOption('force', null, InputOption::VALUE_NONE, 'Run the cron job even if it\'s not due'); } protected function execute(InputInterface $input, OutputInterface $output): int { // We need to pass the prune command to CachePrune since I didn't find an alternative $app = $this->getApplication(); + $force = $input->getOption('force'); assert($app !== null); $command = $app->find('cache:pool:prune'); CachePrune::setPruneCommand($command); // Now run all jobs - $dueJobs = $this->manager->getDueJobs(); - foreach ($dueJobs as $job) { + if ($force) { + $jobsToRun = $this->manager->getAllJobs(); + } else { + $jobsToRun = $this->manager->getDueJobs(); + } + foreach ($jobsToRun as $job) { $name = $job->getName(); $this->logger->info("cron: Running '$name'"); try { diff --git a/src/Cron/CronManager.php b/src/Cron/CronManager.php index 40ef666fd06514c0961f84f8d1a5447fcb85a55e..de6a24a1209a43645d1a583a73d5ba923f2c784f 100644 --- a/src/Cron/CronManager.php +++ b/src/Cron/CronManager.php @@ -85,6 +85,14 @@ final class CronManager implements LoggerAwareInterface return $previousRun; } + /** + * @return CronJobInterface[] + */ + public function getAllJobs(): array + { + return $this->jobs; + } + /** * @return CronJobInterface[] */