Ejemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $jobId = $input->getArgument('jobId');
     $this->init($jobId);
     // Ensure that job status is 'terminating'
     if ($this->job->getStatus() != Job::STATUS_TERMINATING) {
         $this->job->setStatus(Job::STATUS_TERMINATING);
         $this->jobMapper->update($this->job);
     }
     /** @var ExecutorInterface $jobExecutor */
     $jobExecutor = $this->getContainer()->get('syrup.job_executor_factory')->create();
     // run cleanup
     $jobExecutor->cleanup($this->job);
     // Update job
     $endTime = time();
     $duration = $endTime - strtotime($this->job->getStartTime());
     $this->job->setStatus(Job::STATUS_TERMINATED);
     $this->job->setResult(['message' => 'Job has been terminated']);
     $this->job->setEndTime(date('c', $endTime));
     $this->job->setDurationSeconds($duration);
     $this->jobMapper->update($this->job);
     // run post-cleanup
     $jobExecutor->postCleanup($this->job);
     // DB unlock
     $this->lock->unlock();
 }
Ejemplo n.º 2
0
 public function build(\Keboola\Syrup\Job\Metadata\Job $job)
 {
     $params = $job->getRawParams();
     $process = $job->getProcess();
     $token = $job->getToken();
     $project = $job->getProject();
     $this->setId($job->getId());
     if (!empty($params['config'])) {
         $this->setConfig($params['config']);
     }
     $this->setProjectId($project['id']);
     $this->setOrchestrationId($params['orchestration']['id']);
     $this->setToken($token['token']);
     $this->setTokenId($token['id']);
     $this->setTokenDesc($token['description']);
     $this->setTokenOwnerName($project['name']);
     $this->setStatus($job->getStatus());
     $this->setStartTime($job->getStartTime());
     $this->setEndTime($job->getEndTime());
     $this->setResults($job->getResult());
     if (!empty($params['tasks'])) {
         $this->setTaks($params['tasks']);
     }
     $this->setCreatedTime($job->getCreatedTime());
     $this->setOrchestrationName($params['orchestration']['name']);
     $this->setInitializedBy($params['initializedBy']);
     $this->setInitiatorTokenId($params['initiator']['id']);
     $this->setInitiatorTokenDesc($params['initiator']['description']);
     $this->setInitiatorUserAgent($params['initiator']['userAgent']);
     $this->setNotificationsEmails($params['notificationsEmails']);
     $this->setRunId($job->getRunId());
     $this->setPid($process['pid']);
     $this->setWorkerAddress($process['host']);
 }