Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry delete run on db failure #420

Merged
merged 7 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions backend/entityservice/views/run/description.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import psycopg2
from flask import request
from structlog import get_logger
from tenacity import retry, wait_random_exponential, retry_if_exception_type

from entityservice import database as db
from entityservice.database import delete_run_data, get_similarity_file_for_run
Expand All @@ -23,21 +25,29 @@ def get(project_id, run_id):
return RunDescription().dump(run_object)


@retry(wait=wait_random_exponential(multiplier=1, max=60), retry=retry_if_exception_type(psycopg2.IntegrityError))
hardbyte marked this conversation as resolved.
Show resolved Hide resolved
def _delete_run(run_id, log):
# Retry if a db integrity error occurs (e.g. when a worker is writing to the same row)
# Randomly wait up to 2^x * 1 seconds between each retry until the range reaches 60 seconds, then randomly up to 60 seconds afterwards
with db.DBConn() as conn:
log.debug("Retrieving run details from database")
similarity_file = get_similarity_file_for_run(conn, run_id)
delete_run_data(conn, run_id)
return similarity_file


def delete(project_id, run_id):
log = logger.bind(pid=project_id, rid=run_id)
log.debug("request to delete run")
authorize_run_detail(project_id, run_id)
log.debug("approved request to delete run")

with db.DBConn() as conn:
log.debug("Retrieving run details from database")
similarity_file = get_similarity_file_for_run(conn, run_id)
if similarity_file:
log.debug("Queuing task to remove similarities file from object store")
delete_minio_objects.delay([similarity_file], project_id)
delete_run_data(conn, run_id)
similarity_file = _delete_run(run_id, log)
log.debug("Deleted run from database")

log.debug("Deleted run")
if similarity_file:
log.debug("Queuing task to remove similarities file from object store")
delete_minio_objects.delay([similarity_file], project_id)
return '', 204


Expand Down
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ redis==3.2.1
requests==2.21.0
setproctitle==1.1.10 # used by celery to change process name
structlog==18.2.0
tenacity==5.1.1
tornado==4.5.3