/**
  * {@inheritDoc}
  */
 public final function process(ScheduleIteratorInterface $iterator)
 {
     $numOfProcessed = 0;
     $exceptions = array();
     foreach ($iterator as $schedule) {
         $this->logger->debug('Process schedule {schedule}', array('schedule' => $schedule));
         try {
             /**
              * @var ScheduleInterface $schedule
              */
             if ($this->registry->get($schedule->getType())->process($schedule)) {
                 $schedule->setScheduledAt(new \DateTime());
                 $iterator->getManager()->save($schedule);
                 $this->dispatcher->dispatch(SchedulerEvents::SCHEDULE, new SchedulerEvent($schedule));
                 $numOfProcessed++;
             }
         } catch (\Exception $e) {
             $this->logger->error('Failed to process schedule {schedule} ({exception})', array('schedule' => $schedule, 'exception' => $e));
             $exceptions[] = new ScheduleException($schedule, $e);
         }
     }
     if (count($exceptions) > 0) {
         throw new SchedulerException($numOfProcessed, $exceptions);
     }
     return $numOfProcessed;
 }