Beispiel #1
0
 /**
  * @param JobModel $job
  * @param IStageProcessor $stage
  * @param null $preloadedData is used when status is STATUS_RETRY
  * @throws HandlerException
  * @return bool
  */
 protected function handleStage(JobModel $job, IStageProcessor $stage, $preloadedData = null)
 {
     $number = $this->getStageNumber($stage);
     $this->stageData = null;
     // reset stage data result
     try {
         if ($number === 1) {
             // pass the parsed job data when this is the first stage.
             $continue = $stage->process($preloadedData ?: $job->getParsedData());
         } else {
             if ($preloadedData) {
                 $processData = $preloadedData;
             } else {
                 $lastStageNumber = $number - 1;
                 $lastStage = $this->stageRepo->findByJobIdAndStage($job->id, $this->getStageName($lastStageNumber));
                 if (is_null($lastStage)) {
                     throw new ConnectorException("Last Stage output is NULL, array expected.");
                 }
                 $processData = $lastStage->getParsedData();
             }
             // pass the last processed stage's parsed data
             $continue = $stage->process($processData);
         }
         $stageModel = $this->stageRepo->createStub(['stage' => $stage->getName(), 'data' => $this->stageData ?: [], 'status' => StageModel::STATUS_PROCESSED]);
         if ($this->jobRepo->attachStage($job->id, $stageModel) === false) {
             throw new HandlerException("Could not attach StageModel to JobModel (database/foreign key issue?).");
         }
         return $continue;
     } catch (ConnectorException $e) {
         throw new HandlerException($e->getMessage());
     } catch (\Exception $e) {
         throw new HandlerException("Unexpected exception while processing stage (job_id: {$job->id}).");
     }
 }