for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Zenstruck\ScheduleBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Zenstruck\ScheduleBundle\EventListener\ConsoleOutputScheduleSubscriber;
use Zenstruck\ScheduleBundle\Schedule\ScheduleRunner;
/**
* @author Kevin Bond <[email protected]>
*/
final class ScheduleRunCommand extends Command
{
protected static $defaultName = 'schedule:run';
private $scheduleRunner;
private $dispatcher;
public function __construct(ScheduleRunner $scheduleRunner, EventDispatcherInterface $dispatcher)
$this->scheduleRunner = $scheduleRunner;
$this->dispatcher = $dispatcher;
parent::__construct();
}
protected function configure(): void
$this
->setDescription('Runs scheduled tasks that are due')
->setHelp(<<<EOF
Exit code 0: no tasks ran, schedule skipped or all tasks run were successful.
Exit code 1: some of the tasks ran failed.
EOF
)
;
protected function execute(InputInterface $input, OutputInterface $output): int
$io = new SymfonyStyle($input, $output);
$this->dispatcher->addSubscriber(new ConsoleOutputScheduleSubscriber($io));
return ($this->scheduleRunner)()->isSuccessful() ? 0 : 1;