/**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @throws LockException
  * @throws \Exception
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($this->lockHandler->isLocked()) {
         throw new LockException('Command is locked by another process');
     }
     $this->lockHandler->lock();
     try {
         while (true) {
             if (!($event = $this->eventRepository->findFirstTodoEvent())) {
                 break;
             }
             $event->setDelayed(false);
             $this->eventProcessor->process($event);
         }
     } catch (\Exception $e) {
         $this->lockHandler->release();
         throw $e;
     }
     $this->lockHandler->release();
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $channels = $input->getOption('channel');
     foreach ($channels as $channel) {
         if (!isset($this->channels[$channel])) {
             $output->writeln(sprintf('<error>Channel <info>%s</info> is not configured.</error>', $channel));
             continue;
         }
         if ($this->lockHandler->isLocked($channel)) {
             $output->writeln(sprintf('Command is locked by another process for channel <info>%s</info>.', $channel));
             continue;
         }
         $output->writeln(sprintf('Process events for channel <info>%s</info>', $channel));
         $this->lockHandler->lock($channel);
         $processedEventsCount = 0;
         $commandStartTime = time();
         $event = null;
         try {
             while (!$this->isLimitReached($commandStartTime, $processedEventsCount, $this->channels[$channel]['duration_limit_per_run'], $this->channels[$channel]['events_limit_per_run'])) {
                 if (!$this->lockHandler->isLocked($channel)) {
                     $output->writeln(sprintf('<error>Lock for channel <info>%s</info> has been released outside of the process.</error>', $channel));
                     break;
                 }
                 $event = $this->eventRepository->findFirstTodoEvent(false, $this->channels[$channel]['include'], $this->channels[$channel]['exclude']);
                 if (!$event instanceof Event) {
                     break;
                 }
                 $event->setDelayed(false);
                 $this->eventProcessor->process($event);
                 $processedEventsCount++;
             }
         } catch (\Exception $e) {
             if ($event instanceof Event) {
                 $output->writeln(sprintf('<info>[%s]</info> <error> An error occurred while processing event "%s".</error>', $channel, $event->getOriginalName()));
             }
             $output->writeln(sprintf('<info>[%s]</info> <error>%s</error>', $channel, $e->getMessage()));
             $output->writeln($e->getTraceAsString());
         }
         $this->lockHandler->release($channel);
     }
 }