-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathElasticSearchIndexInit.php
More file actions
64 lines (47 loc) · 1.93 KB
/
ElasticSearchIndexInit.php
File metadata and controls
64 lines (47 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace App\Jobs\CirrusSearch;
use Illuminate\Support\Facades\Log;
class ElasticSearchIndexInit extends CirrusSearchJob {
private $cluster;
public function __construct(int $wikiId, string $cluster = 'all') {
$this->cluster = $cluster;
parent::__construct($wikiId);
}
public function cluster(): string {
return $this->cluster;
}
public function apiModule(): string {
return 'wbstackElasticSearchInit';
}
private function logFailure(): void {
Log::error(__METHOD__ . ': Failed initializing elasticsearch.');
}
public function handleResponse(string $rawResponse, $error): void {
$response = json_decode($rawResponse, true);
if (!$this->validateOrFailRequest($response, $rawResponse, $error)) {
$this->logFailure();
return;
}
if (!$this->validateSuccess($response, $rawResponse, $error)) {
$this->logFailure();
return;
}
$output = $response[$this->apiModule()]['output'];
// if newly created index failed, script ran and update was unsuccessful, then log error.
if (!(
in_array("\tCreating index...ok", $output) ||
in_array("\t\tValidating {$this->wikiDB->name}_general alias...ok", $output)
)) {
Log::error(__METHOD__ . ": Job finished but didn't create or update, something is weird");
$this->logFailure();
$this->fail(new \RuntimeException($this->apiModule() . ' call for ' . $this->wikiId . ' was not successful:' . $rawResponse));
}
}
protected function getRequestTimeout(): int {
return getenv('CURLOPT_TIMEOUT_ELASTICSEARCH_INIT') !== false
? intval(getenv('CURLOPT_TIMEOUT_ELASTICSEARCH_INIT')) : parent::getRequestTimeout();
}
protected function getQueryParams() {
return parent::getQueryParams() . '&cluster=' . $this->cluster;
}
}