protected function tick(BackendInterface $backend, array $options = [])
 {
     $this->configure($options);
     $iterator = $backend->getIterator();
     foreach ($iterator as $message) {
         if ($this->controller->doPause()) {
             return true;
         }
         if ($this->controller->doStop()) {
             return false;
         }
         if (microtime(true) > $this->options['max-runtime']) {
             return false;
         }
         $backend->handle($message, $this->notificationDispatcher);
         $this->eventDispatcher->dispatch(IterateEvent::EVENT_NAME, new IterateEvent($iterator, $backend, $message));
         if (null !== $this->options['max-messages'] && !(bool) --$this->options['max-messages']) {
             return false;
         }
     }
     return !$this->options['stop-when-empty'];
 }
 /**
  * @param InputInterface   $input
  * @param OutputInterface  $output
  * @param BackendInterface $backend
  * @param                  $showDetails
  * @param                  $startMemoryUsage
  */
 protected function iterate(InputInterface $input, OutputInterface $output, BackendInterface $backend, $showDetails, $startMemoryUsage)
 {
     $iterator = $backend->getIterator();
     foreach ($iterator as $message) {
         if (!$message instanceof MessageInterface) {
             throw new \RuntimeException('The iterator must return a MessageInterface instance');
         }
         if (!$message->getType()) {
             $output->write("<error>Skipping : no type defined </error>");
             continue;
         }
         $date = new \DateTime();
         $output->write(sprintf("[%s] <info>%s</info>", $date->format('r'), $message->getType()));
         $memoryUsage = memory_get_usage(true);
         try {
             $start = microtime(true);
             $returnInfos = $backend->handle($message, $this->getNotificationDispatcher());
             $currentMemory = memory_get_usage(true);
             $output->writeln(sprintf("<comment>OK! </comment> - %0.04fs, %ss, %s, %s - %s = %s, %0.02f%%", microtime(true) - $start, $date->format('U') - $message->getCreatedAt()->format('U'), $this->formatMemory($currentMemory - $memoryUsage), $this->formatMemory($currentMemory), $this->formatMemory($startMemoryUsage), $this->formatMemory($currentMemory - $startMemoryUsage), ($currentMemory - $startMemoryUsage) / $startMemoryUsage * 100));
             if ($showDetails && null !== $returnInfos) {
                 $output->writeln($returnInfos->getReturnMessage());
             }
         } catch (HandlingException $e) {
             $output->writeln(sprintf("<error>KO! - %s</error>", $e->getPrevious()->getMessage()));
         } catch (\Exception $e) {
             $output->writeln(sprintf("<error>KO! - %s</error>", $e->getMessage()));
         }
         $this->getEventDispatcher()->dispatch(IterateEvent::EVENT_NAME, new IterateEvent($iterator, $backend, $message));
     }
 }