diff --git a/djcelery_email/tasks.py b/djcelery_email/tasks.py index 6e219b9..93fbd50 100644 --- a/djcelery_email/tasks.py +++ b/djcelery_email/tasks.py @@ -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: @@ -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