From 3991629acf80af0f3bf2695a82dea18500cba155 Mon Sep 17 00:00:00 2001 From: sarikaya Date: Wed, 8 May 2024 21:33:52 +0300 Subject: [PATCH] Implement retry mechansim on redis queue --- cvat/apps/engine/task.py | 3 ++- cvat/apps/engine/views.py | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cvat/apps/engine/task.py b/cvat/apps/engine/task.py index 2003d541c559..8a70f8827117 100644 --- a/cvat/apps/engine/task.py +++ b/cvat/apps/engine/task.py @@ -35,7 +35,8 @@ def create(tid, data): """Schedule the task""" q = django_rq.get_queue('default') q.enqueue_call(func=_create_thread, args=(tid, data), - job_id="/api/v1/tasks/{}".format(tid)) + job_id="/api/v1/tasks/{}".format(tid), + retry=django_rq.Retry(max=3, interval=[10, 60, 180])) @transaction.atomic def rq_handler(job, exc_type, exc_value, traceback): diff --git a/cvat/apps/engine/views.py b/cvat/apps/engine/views.py index dd13b1ffffb4..f5afbae3aab6 100644 --- a/cvat/apps/engine/views.py +++ b/cvat/apps/engine/views.py @@ -488,6 +488,7 @@ def create(self, request): 'tmp_file': filename, 'tmp_file_descriptor': fd, }, + retry=django_rq.Retry(max=3, interval=[10, 60, 180]) ) else: @@ -565,7 +566,8 @@ def retrieve(self, request, pk=None): args=(pk, 'task_dump.zip'), job_id=rq_id, meta={'request_time': timezone.localtime()}, - result_ttl=ttl, failure_ttl=ttl) + result_ttl=ttl, failure_ttl=ttl, + retry=django_rq.Retry(max=3, interval=[10, 60, 180])) return Response(status=status.HTTP_202_ACCEPTED) else: @@ -1592,7 +1594,8 @@ def _import_annotations(request, rq_id, rq_func, pk, format_name): rq_job = queue.enqueue_call( func=rq_func, args=(pk, filename, format_name), - job_id=rq_id + job_id=rq_id, + retry=django_rq.Retry(max=3, interval=[10, 60, 180]) ) rq_job.meta['tmp_file'] = filename rq_job.meta['tmp_file_descriptor'] = fd @@ -1686,7 +1689,8 @@ def _export_annotations(db_instance, rq_id, request, format_name, action, callba queue.enqueue_call(func=callback, args=(db_instance.id, format_name, server_address), job_id=rq_id, meta={'request_time': timezone.localtime()}, - result_ttl=ttl, failure_ttl=ttl) + result_ttl=ttl, failure_ttl=ttl, + retry=django_rq.Retry(max=3, interval=[10, 60, 180])) return Response(status=status.HTTP_202_ACCEPTED)