Skip to content

Commit

Permalink
NOJIRA Fix ElasticSearch event logging
Browse files Browse the repository at this point in the history
They removed the hardcoded ok: true in their responses a while ago:
elastic/elasticsearch#4310

We now use HTTP status codes to determine if everything went ok. We
also catch all exceptions now. Before the whole application would just
barf if ElasticSearch went away.
  • Loading branch information
stefan committed Oct 8, 2014
1 parent 4901eba commit fbeb675
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions app/lib/core/Plugins/SearchEngine/ElasticSearch.php
Expand Up @@ -684,16 +684,15 @@ public function flushContentBuffer() {
$va_key[0]."/".$va_key[2]
);

$vo_http_client->setRawData(json_encode($va_post_json))->setEncType('text/json')->request('POST');
try {
$vo_http_client->setRawData(json_encode($va_post_json))->setEncType('text/json')->request('POST');
$vo_http_response = $vo_http_client->request();
$va_response = json_decode($vo_http_response->getBody(),true);

if(!isset($va_response["ok"]) || $va_response["ok"]!=1){
caLogEvent('ERR', _t('Indexing commit failed for %1; response was %2', $vs_key, $vo_http_response->getBody()), 'ElasticSearch->flushContentBuffer()');

if($vo_http_response->getStatus() != 200) {
caLogEvent('ERR', _t('Indexing commit failed for %1; response was %2; request was %3', $vs_key, $vo_http_response->getBody(), json_encode($va_post_json)), 'ElasticSearch->flushContentBuffer()');
}
} catch (Exception $e){
caLogEvent('ERR', _t('Indexing commit failed for %1: %2; response was %3', $vs_key, $e->getMessage(), $vo_http_response->getBody()), 'ElasticSearch->flushContentBuffer()');
caLogEvent('ERR', _t('Indexing commit failed for %1 with Exception: %2', $vs_key, $e->getMessage()), 'ElasticSearch->flushContentBuffer()');
}
}

Expand Down

0 comments on commit fbeb675

Please sign in to comment.