/** * @return ImportResult */ public function run() { $import = $this->part->getImport(); // part is not finished, maybe it's already started/running if ($this->part->isStarted()) { $this->processor->checkProcessing($this->part); $this->logger->warning(sprintf('Part %d of import %d has already started, but the process (%s) is no longer running. ' . 'Resuming the part now.', $this->part->getPosition(), $import->getId(), $this->part->getProcess())); } // start import if necessary if (!$import->isStarted()) { $this->importer->dispatchEvent(ImportEvents::IMPORT_START, new ImportEvent($import)); $this->repository->startImport($import); } try { $this->start(); $this->importer->run($this->feed); } catch (\Exception $e) { // log the error $this->logger->error($e->getMessage()); $this->logger->debug($e->getTraceAsString()); // check if we have any retries left if ($this->part->getRetries() > 0) { // mark as unstarted and bail out $this->retry(); return null; } else { $this->fail($e->getMessage()); } } $this->repository->addResult($import, $this->importer->getResult()); $this->finish(); return $this->importer->getResult(); }
/** * @inheritdoc */ public function isRunning(ImportPart $part) { if (null === ($pid = $part->getProcess())) { return false; } if (intval($pid) < 1) { throw new \RuntimeException(sprintf('Import part does not have a valid pid: %s', json_encode($pid))); } // kill signal 0: check whether a process is running. // see http://www.php.net/manual/en/function.posix-kill.php#82560 return posix_kill($pid, 0); }