Skip to content

Commit

Permalink
enhancement: Move celery retry values as env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
renceInbox committed May 24, 2023
1 parent 8b0dd82 commit e06eb20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions card_generator/tasks/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class OPENSPPCeleryTask(Task):
max_retries = 3
max_retries = settings.CELERY_MAX_RETRIES

def on_failure(self, exc, task_id, args, kwargs, einfo):
batch_id = args[1]["batch_id"]
Expand Down Expand Up @@ -142,7 +142,7 @@ def merge_cards(self, batch_id: int) -> None:
)
except Exception as e: # noqa Lets catch all errors error for debugging and retry
logger.info(f"Error raised on client. {str(e)}")
raise self.retry(exc=e, countdown=30)
raise self.retry(exc=e, countdown=settings.CELERY_RETRY_COUNTDOWN)
try:
perform_merging(client, batch_id)
except (
Expand All @@ -151,5 +151,5 @@ def merge_cards(self, batch_id: int) -> None:
Exception,
) as e: # noqa Lets catch all errors error for debugging and retry
logger.info(f"Error raised while performing merge. {str(e)}")
raise self.retry(countdown=30)
raise self.retry(countdown=settings.CELERY_RETRY_COUNTDOWN)
logger.info(f"Batch #{batch_id} have been updated with merged cards.")
4 changes: 4 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,7 @@
OPENSPP_CUSTOM_TLS = env.bool("OPENSPP_USE_TLS", default=False)
if OPENSPP_CUSTOM_TLS:
OPENSPP_CUSTOM_CERT_PATH = env.str("OPENSPP_CUSTOM_CERT_PATH")

# Celery
CELERY_MAX_RETRIES = env.int("CELERY_MAX_RETRIES", default=3)
CELERY_RETRY_COUNTDOWN = env.int("CELERY_RETRY_COUNTDOWN", default=30)

0 comments on commit e06eb20

Please sign in to comment.