retry if deleting docs fail

This commit is contained in:
Simon 2018-07-14 21:34:25 -04:00
parent f452d0f8b2
commit 2f1b0c96f1

View File

@ -95,22 +95,25 @@ class ElasticSearchEngine(SearchEngine):
def delete_docs(self, website_id): def delete_docs(self, website_id):
try: while True:
print("Deleting docs of " + str(website_id)) try:
self.es.delete_by_query(body={ print("Deleting docs of " + str(website_id))
"query": { self.es.delete_by_query(body={
"constant_score": { "query": {
"filter": { "constant_score": {
"term": {"website_id": website_id} "filter": {
"term": {"website_id": website_id}
}
} }
} }
} }, index=self.index_name, request_timeout=200)
}, index=self.index_name, request_timeout=200) break
except elasticsearch.exceptions.ConflictError: except elasticsearch.exceptions.ConflictError:
print("Error: multiple delete tasks at the same time") print("Error: multiple delete tasks at the same time, retrying")
except Exception: time.sleep(10)
print("Timeout during delete!") except Exception:
time.sleep(30) print("Timeout during delete! Retrying")
time.sleep(10)
def import_json(self, in_lines, website_id: int): def import_json(self, in_lines, website_id: int):