示例#1
0
 /**
  * @param $values
  * @return Job
  * @throws ConnectorException
  */
 public function create($values)
 {
     $job = new Job();
     $values['status'] = array_get($values, 'status', 'new');
     $job->fill($values);
     if ($job->save()) {
         return $job;
     }
     throw new ConnectorException("Cannot create Job.");
 }
示例#2
0
 /**
  * @param JobModel $job
  * @return array
  * @throws ConnectorException
  */
 protected function prepareStageData(JobModel $job)
 {
     $fromStageNumber = 1;
     $preloadedData = null;
     if ($job->getPreviousStatus() === JobModel::STATUS_NEW || $job->getPreviousStatus() === JobModel::STATUS_QUEUED) {
         // Defaults are OK
     } elseif ($job->getPreviousStatus() === JobModel::STATUS_RETRY) {
         $lastStage = $this->stageRepo->findLastByJobIdAndStatus($job->id, 'processed');
         if ($lastStage !== null) {
             $fromStageNumber = array_get($this->stageMapping, $lastStage->stage) + 1;
             $preloadedData = $lastStage->getParsedData();
             $this->deleteFailedStages($lastStage);
         }
     } elseif ($job->getPreviousStatus() === JobModel::STATUS_RESTART) {
         $this->stageRepo->deleteByJobId($job->id);
         // Defaults are OK
     } else {
         throw new HandlerException("Unexpected Job status (status: {$job->getPreviousStatus()}), cannot prepare Stages.");
     }
     return [$fromStageNumber, $preloadedData];
 }