Skip to content

Commit

Permalink
Retry on connection open failures
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbuddy committed Jun 11, 2019
1 parent 02ed314 commit ec8592d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions djcelery_email/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
TASK_CONFIG['base'] = import_string(TASK_CONFIG['base'])


@shared_task(**TASK_CONFIG)
def send_emails(messages, backend_kwargs=None, **kwargs):
@shared_task(**TASK_CONFIG, bind=True)
def send_emails(self, messages, backend_kwargs=None, **kwargs):
# backward compat: handle **kwargs and missing backend_kwargs
combined_kwargs = {}
if backend_kwargs is not None:
Expand All @@ -39,8 +39,9 @@ def send_emails(messages, backend_kwargs=None, **kwargs):
conn = get_connection(backend=settings.CELERY_EMAIL_BACKEND, **combined_kwargs)
try:
conn.open()
except Exception:
logger.exception("Cannot reach CELERY_EMAIL_BACKEND %s", settings.CELERY_EMAIL_BACKEND)
except Exception as e:
logger.warning("Cannot reach CELERY_EMAIL_BACKEND %s", settings.CELERY_EMAIL_BACKEND)
self.retry(exc=e, countdown=2 ** self.request.retries)

messages_sent = 0

Expand Down

0 comments on commit ec8592d

Please sign in to comment.