eventDispatcher = $eventDispatcher; } /** * @required */ public function setSentryLogger(SentryLogger $sentryLogger): void { $this->sentryLogger = $sentryLogger; } protected function configure() { $this ->addArgument('type', InputArgument::OPTIONAL, 'Type of cron to run. One of [FREQUENT, NORMAL, EXPENSIVE]', 'NORMAL') ->addOption('method', 'm', InputOption::VALUE_OPTIONAL, 'Call specific cron method - write just method, f.e.: "-m activatePoints"', false); } protected function execute(InputInterface $input, OutputInterface $output) { try { $event = new CronEvent($input->getArgument('type')); $eventName = constant('KupShop\KupShopBundle\Event\CronEvent::RUN_'.$input->getArgument('type')); if ($input->hasOption('method')) { $method = $input->getOption('method'); if ($method === null) { // List all available handlers and exit $table = new Table($output); $table ->setHeaders(['Handler']); foreach ($this->eventDispatcher->getListeners($eventName) as $listener) { $table->addRow([sprintf('%s::%s', get_class($listener[0]), $listener[1])]); } $table->render(); return 0; } $this->eventDispatcher->setSpecificMethod($input->getOption('method')); } $this->eventDispatcher->dispatch( $event, $eventName, ); } catch (\Throwable $e) { $this->sentryLogger->setChannel(SentryLogger::CHANNEL_CRON)->captureException($e); throw $e; } return 0; } }