Ejemplo n.º 1
2
 public function __invoke(Job $job)
 {
     $job = $this->elasticsearch->getJob($job->getId());
     // find and kill child jobs
     $childJobs = $this->elasticsearch->getJobs(['query' => 'runId:' . $job->getRunId() . '.*', 'project.id' => $job->getProject()['id']]);
     $this->logger->debug("Child jobs found", ['jobs' => $childJobs]);
     $snsClient = new SnsClient(['credentials' => ['key' => $this->snsConfig['key'], 'secret' => $this->snsConfig['secret']], 'region' => isset($this->snsConfig['region']) ? $this->snsConfig['region'] : 'us-east-1', 'version' => '2010-03-31']);
     // kill them all
     if (!empty($childJobs)) {
         foreach ($childJobs as $childJob) {
             $snsClient->publish(['TopicArn' => $this->snsConfig['topic_arn'], 'Message' => json_encode(['jobId' => $childJob['id']])]);
         }
     }
     $callback = $this->cleanupCallback;
     $callback($job);
     $endTime = time();
     $duration = $endTime - strtotime($job->getStartTime());
     $job->setStatus(Job::STATUS_TERMINATED);
     $job->setResult(['message' => 'Job has been terminated']);
     $job->setEndTime(date('c', $endTime));
     $job->setDurationSeconds($duration);
     $this->jobMapper->update($job);
 }
Ejemplo n.º 2
0
 public function testGetJobs()
 {
     $job = $this->createJob();
     self::$jobMapper->create($job);
     $job2 = $this->createJob();
     self::$jobMapper->create($job2);
     $retries = 0;
     $res = [];
     while ($retries < 7) {
         $delaySecs = 2 * pow(2, $retries);
         sleep($delaySecs);
         $retries++;
         $projectId = $job->getProject()['id'];
         $res = self::$search->getJobs(['projectId' => $projectId, 'component' => SYRUP_APP_NAME, 'since' => '-1 day', 'until' => 'now']);
         if (count($res) >= 2) {
             break;
         }
     }
     $job1Asserted = false;
     $job2Asserted = false;
     foreach ($res as $r) {
         if ($r['id'] == $job->getId()) {
             $this->assertJob($job, $r);
             $job1Asserted = true;
         }
         if ($r['id'] == $job2->getId()) {
             $this->assertJob($job2, $r);
             $job2Asserted = true;
         }
     }
     $this->assertTrue($job1Asserted);
     $this->assertTrue($job2Asserted);
 }
 /**
  * Fetches job details for specified id
  * @param $runId
  * @return array|null
  */
 private function fetchStatsForJob($runId)
 {
     // a bit of hack, since there's no method for getting job by runId
     $jobs = $this->elasticsearch->getJobs(['runId' => $runId]);
     if (!empty($jobs)) {
         $job = reset($jobs);
         return $job;
     } else {
         return null;
     }
 }
Ejemplo n.º 4
0
 /**
  * @param array $criteria
  * @return Job[]
  * @throws \Keboola\StorageApi\Exception
  */
 public function findJobs(array $criteria, $offset = 0, $limit = JobManager::PAGING)
 {
     $exportOptions = $this->buildExportOptions($criteria);
     $data = $this->syrupJobSearch->getJobs(array('projectId' => $this->token->getProjectId(), 'component' => KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME, 'offset' => $offset, 'limit' => $limit, 'query' => $exportOptions));
     $manager = $this;
     return array_map(function ($line) use($manager) {
         $esJob = new Elasticsearch\Job($this->objectEncryptor, $line, $line['_index'], $line['_type']);
         $job = new Job();
         $job->build($esJob);
         $job->setUrl($manager->generateJobUri($job));
         $job->setToken($this->decryptToken($job->getToken()));
         return $job;
     }, $data);
 }