Esempio n. 1
0
 public function getJob($jobId)
 {
     $indices = $this->getIndices();
     $docs = [];
     foreach ($indices as $index) {
         $docs[] = ['_index' => $index, '_type' => 'jobs', '_id' => $jobId];
     }
     $i = 0;
     while ($i < 5) {
         try {
             $result = $this->client->mget(['body' => ['docs' => $docs]]);
             foreach ($result['docs'] as $doc) {
                 if (isset($doc['found']) && $doc['found'] === true) {
                     return new Job($this->configEncryptor, $doc['_source'], $doc['_index'], $doc['_type'], $doc['_version']);
                 }
             }
             return null;
         } catch (ServerErrorResponseException $e) {
             // ES server error, try again
             $this->log('error', 'Elastic server error response', ['attemptNo' => $i, 'jobId' => $jobId, 'exception' => $e]);
         }
         sleep(1 + intval(pow(2, $i) / 2));
         $i++;
     }
     return null;
 }