refresh for PendingInteract delete to avoid race condition, #217

This commit is contained in:
simon 2022-05-02 18:20:56 +07:00
parent 34a1fe9e8e
commit ca5b00a373
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 5 additions and 3 deletions

View File

@ -103,7 +103,7 @@ class PendingInteract:
def delete_item(self):
"""delete single item from pending"""
path = f"ta_download/_doc/{self.video_id}"
_, _ = ElasticWrap(path).delete()
_, _ = ElasticWrap(path).delete(refresh=True)
def delete_by_status(self):
"""delete all matching item by status"""

View File

@ -75,8 +75,10 @@ class ElasticWrap:
return response.json(), response.status_code
def delete(self, data=False):
def delete(self, data=False, refresh=False):
"""delete document from es"""
if refresh:
self.url = f"{self.url}/?refresh=true"
if data:
response = requests.delete(self.url, json=data, auth=self.auth)
else:

View File

@ -86,7 +86,7 @@ class YouTubeItem:
def del_in_es(self):
"""delete item from elastic search"""
print(f"{self.youtube_id}: delete from es")
_, _ = ElasticWrap(self.es_path).delete()
_, _ = ElasticWrap(self.es_path).delete(refresh=True)
class Pagination: