mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Feature: bootstrap dependency injection for CronJobManager and create a command
This commit is contained in:
parent
b789250b8d
commit
204ebd4415
56
src/Bundle/ChillMainBundle/Command/ExecuteCronJobCommand.php
Normal file
56
src/Bundle/ChillMainBundle/Command/ExecuteCronJobCommand.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Command;
|
||||
|
||||
use Chill\MainBundle\Cron\CronManagerInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ExecuteCronJobCommand extends Command
|
||||
{
|
||||
private CronManagerInterface $cronManager;
|
||||
|
||||
public function __construct(
|
||||
?string $name,
|
||||
CronManagerInterface $cronManager
|
||||
) {
|
||||
parent::__construct('chill:cron-job:execute');
|
||||
|
||||
$this->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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user