retry on index fail/timeout

This commit is contained in:
Simon 2018-11-22 10:52:42 -05:00
parent 5782a45524
commit a33d4f2dca

View File

@ -179,13 +179,15 @@ class ElasticSearchEngine(SearchEngine):
self._index(docs)
def _index(self, docs):
while True:
try:
logger.debug("Indexing " + str(len(docs)) + " docs")
bulk_string = ElasticSearchEngine.create_bulk_index_string(docs)
result = self.es.bulk(body=bulk_string, index=self.index_name, doc_type="file", request_timeout=30)
if result["errors"]:
logger.error("Error in ES bulk index: \n" + result["errors"])
raise IndexingError
self.es.bulk(body=bulk_string, index=self.index_name, doc_type="file", request_timeout=30)
break
except Exception as e:
logger.error("Error in _index: " + str(e) + ", retrying")
time.sleep(10)
@staticmethod
def create_bulk_index_string(docs: list):