Пример #1
0
 public function execute(SyrupJob $job)
 {
     parent::build($job);
     $jobLogger = new JobLogger($this->job, $this->storageApi);
     try {
         $jobLogger->start($this->stopwatch->getEvent(self::STOPWATCH_ORCHESTRATION_EVENT));
         if ($this->job->getTasks()) {
             /** @var StorageApi\OrchestrationTask[] $rows */
             $orchestrationTasks = array_map(function ($line) {
                 $task = new StorageApi\OrchestrationTask();
                 $task->fromArray(json_decode(json_encode($line), true));
                 return $task;
             }, $this->job->getTasks());
         } else {
             $orchestrationTasks = $this->loadTasks($this->job, $this->token);
             if (!$this->job->getTasks() && $orchestrationTasks) {
                 $this->logger->info('orchestration.job.emptyTasks', array('jobId' => $this->job->getId(), 'orchestrationId' => $this->job->getOrchestrationId(), 'orchestrationName' => $this->job->getOrchestrationName(), 'projectId' => $this->job->getProjectId()));
             }
         }
         // fill result
         foreach ($orchestrationTasks as $task) {
             $this->jobResult->addTaskResult(new TaskResult($task));
         }
         $this->saveJobResult($this->jobResult);
         foreach ($orchestrationTasks as $task) {
             // skip inactive taks
             if (!$task->getActive()) {
                 continue;
             }
             try {
                 $taskResult = (new TaskResult($task))->setProcessingStatus();
                 $this->jobResult->addTaskResult($taskResult);
                 $this->saveJobResult($this->jobResult);
                 $result = $this->executeJobTask($this->job, $taskResult, $this->storageApi);
                 $this->jobResult->addTaskResult($result);
                 $this->saveJobResult($this->jobResult);
                 if (!$task->getContinueOnFailure() && $result->getError()) {
                     break;
                 }
                 if ($task->getContinueOnFailure() && $result->getError()) {
                     continue;
                 }
             } catch (\Exception $taskE) {
                 //@FIXME better handling = not log to sapi
                 throw Exception\JobRuntimeException::factory($taskE);
             }
         }
         $jobLogger->end($this->jobResult);
         $status = StatusConverter::orchestratorToSyrup($this->jobResult->getEventType());
         $result = array('tasks' => $this->jobResult->toArray());
         if ($status === SyrupJob::STATUS_SUCCESS) {
             return $result;
         }
         if ($status === SyrupJob::STATUS_WARNING) {
             $eData = array('jobId' => $this->job->getId(), 'orchestrationId' => $this->orchestration->getId(), 'projectId' => $this->orchestration->getProjectId());
             $e = new JobException(500, sprintf('Some of tasks failed'), null, $eData);
             $e->setStatus($status)->setResult($result);
             throw $e;
         }
         if ($status === SyrupJob::STATUS_ERROR) {
             $eData = array('jobId' => $this->job->getId(), 'orchestrationId' => $this->orchestration->getId(), 'projectId' => $this->orchestration->getProjectId());
             $e = new JobException(500, sprintf('Job failed', $job->getId()), null, $eData);
             $e->setStatus($status)->setResult($result);
             throw $e;
         }
     } catch (Exception\JobInvalidStateException $e) {
         $jobLogger->stateError($e);
         // any change of job status, job is probably processing
     } catch (Exception\JobRuntimeException $e) {
         throw $e->getPrevious();
     }
     return array();
 }
Пример #2
0
 public function execute(SyrupJob $job)
 {
     parent::build($job);
     //@FIXME remove debug logging from info channel
     $jobLogger = new JobLogger($this->job, $this->storageApi);
     try {
         $jobLogger->start($this->stopwatch->getEvent(self::STOPWATCH_ORCHESTRATION_EVENT));
         $phases = $this->createPhases($this->job);
         $this->saveJobResult($this->jobResult);
         $httpClient = new Client(array(), $this->logger);
         foreach ($phases as $phase) {
             $phaseLogger = new PhaseLogger($phase, $this->storageApi);
             $startTime = time();
             $jobResponses = $this->startPhase($phase, $phaseLogger, $httpClient);
             if ($jobResponses === false) {
                 break;
             }
             $pollResponses = $this->pollPhase($phase, $phaseLogger, $httpClient, $jobResponses);
             if ($pollResponses === false) {
                 break;
             }
         }
         $endEvent = $jobLogger->end($this->jobResult);
         $status = StatusConverter::orchestratorToSyrup($this->jobResult->getEventType());
         $result = array('tasks' => $this->jobResult->toArray());
         if ($status === SyrupJob::STATUS_SUCCESS) {
             return $result;
         }
         if ($status === SyrupJob::STATUS_WARNING) {
             $eData = array('jobId' => $this->job->getId(), 'orchestrationId' => $this->orchestration->getId(), 'projectId' => $this->orchestration->getProjectId());
             $e = new JobException(500, sprintf('Some of tasks failed'), null, $eData);
             $e->setStatus($status)->setResult($result);
             throw $e;
         }
         if ($status === SyrupJob::STATUS_ERROR) {
             $eData = array('jobId' => $this->job->getId(), 'orchestrationId' => $this->orchestration->getId(), 'projectId' => $this->orchestration->getProjectId());
             $e = new JobException(500, sprintf('Job failed', $job->getId()), null, $eData);
             $e->setStatus($status)->setResult($result);
             throw $e;
         }
     } catch (Exception\JobInvalidStateException $e) {
         $endEvent = $jobLogger->stateError($e);
         // any change of job status, job is probably processing
     } catch (Exception\JobRuntimeException $e) {
         throw $e->getPrevious();
     }
     return array();
 }