/**
  * @param OutputInterface $output
  * @param ImportPart      $part
  */
 protected function runImportPart(OutputInterface $output, ImportPart $part)
 {
     $output->writeln(sprintf('Importing part <comment>%d</comment> of import <comment>%d</comment>', $part->getPosition(), $part->getImport()->getId()));
     $job = $this->importFactory->createImportJob($part);
     $job->setLogger($this->logger);
     $job->run();
 }
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @param Feed[]          $feeds
  * @param int             $minutes
  * @param bool            $force
  *
  * @return int
  */
 protected function scheduleImports(InputInterface $input, OutputInterface $output, array $feeds, $minutes, $force = false)
 {
     if (empty($feeds)) {
         $output->writeln('No feeds to schedule');
         return 0;
     }
     $num = 0;
     $factor = $minutes / sizeof($feeds);
     foreach ($feeds as $feedId => $priority) {
         $offset = round($factor * $num++);
         $date = new \DateTime(sprintf('+%d minutes', $offset));
         /** @var Feed $feed */
         $feed = $this->importScheduler->findFeed($feedId);
         if ($input->isInteractive()) {
             $this->checkForUnfinishedImports($feed, $input, $output);
         }
         $output->writeln(sprintf('Scheduling import for <info>%s</info> feed <info>%d</info> to run at <info>%s</info>', $feed->getOrigin()->getName(), $feed->getId(), $date->format('Y-m-d H:i:s')));
         try {
             $import = $this->importFactory->createImport($feed, $date, $force);
             $output->writeln(sprintf('Created import <info>%d</info>', $import->getId()));
             $output->writeln('Scheduling parts');
             foreach ($import->getParts() as $part) {
                 $this->importScheduler->schedulePart($part);
             }
         } catch (\Exception $e) {
             // we could get an exception when a new import cannot be created, for example when an existing import
             // for this feed is still running.
             $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
             continue;
         }
     }
     return 0;
 }
 /**
  * @param OutputInterface $output
  * @param Feed            $feed
  * @param bool            $force
  */
 protected function runImport(OutputInterface $output, Feed $feed, $force = false)
 {
     $output->writeln(sprintf('Starting a new import for <info>%s</info> feed <info>%d</info>', $feed->getOrigin()->getName(), $feed->getId()));
     $import = $this->importFactory->createImport($feed, new \DateTime(), $force);
     $output->writeln(sprintf('Created import <info>%d</info>', $import->getId()));
     foreach ($import->getParts() as $part) {
         $output->writeln(sprintf('Importing part <comment>%d</comment>', $part->getPosition()));
         $job = $this->importFactory->createImportJob($part);
         $job->setLogger($this->logger);
         $job->run();
     }
 }
 /**
  * @inheritdoc
  */
 public function execute(array $payload)
 {
     /** @var Feed $feed */
     /** @var bool $force */
     list($feed, $force) = $payload;
     try {
         $import = $this->importFactory->createImport($feed, new \DateTime(), $force);
         $this->logger->info(sprintf('Created import %d', $import->getId()));
         $this->logger->debug('Scheduling parts');
         foreach ($import->getParts() as $part) {
             $this->scheduler->schedulePart($part);
         }
         return true;
     } catch (\Exception $e) {
         // we could get an exception when a new import cannot be created, for example when an existing import
         // for this feed is still running.
         $this->logger->error(sprintf('<error>%s</error>', $e->getMessage()));
         return false;
     }
 }
 /**
  * @inheritdoc
  */
 public function execute(array $payload)
 {
     /** @var ImportPart $part */
     list($part) = $payload;
     $import = $part->getImport();
     $feed = $import->getFeed();
     $this->logger->info(sprintf('Importing part <comment>%d</comment> of %s-feed for import "%d" for origin "%s"', $part->getPosition(), $feed->getType(), $import->getId(), $feed->getOrigin()->getTitle()));
     if ($import->isFinished()) {
         $this->logger->info(sprintf('Import %d has already finished', $import->getId()));
         return false;
     }
     if ($part->isFinished()) {
         $this->logger->info(sprintf('Part %d has already finished', $part->getId()));
         return false;
     }
     if (!$this->validate($part)) {
         return false;
     }
     $job = $this->importFactory->createImportJob($part);
     $job->setLogger($this->logger);
     $job->run();
     return true;
 }