From 204ebd4415fa95db8f84341fb97896b4051c0b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 12 Dec 2022 21:16:27 +0100 Subject: [PATCH] Feature: bootstrap dependency injection for CronJobManager and create a command --- .../Command/ExecuteCronJobCommand.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Command/ExecuteCronJobCommand.php diff --git a/src/Bundle/ChillMainBundle/Command/ExecuteCronJobCommand.php b/src/Bundle/ChillMainBundle/Command/ExecuteCronJobCommand.php new file mode 100644 index 000000000..9dca2996a --- /dev/null +++ b/src/Bundle/ChillMainBundle/Command/ExecuteCronJobCommand.php @@ -0,0 +1,56 @@ +cronManager = $cronManager; + } + + protected function configure() + { + $this + ->setDescription('Execute the cronjob(s) given as argument, or one cronjob scheduled by system.') + ->setHelp("If no job is specified, the next available cronjob will be executed by system.\nThis command should be execute every 15 minutes (more or less)") + ->addArgument('job', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'one or more job to force execute (by default, all jobs are executed)', []) + ->addUsage(''); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + if ([] === $input->getArgument('job')) { + $this->cronManager->run(); + + return 0; + } + + foreach ($input->getArgument('job') as $jobName) { + $this->cronManager->run($jobName); + } + + return 0; + } +}