Skip to content

Commit

Permalink
Use celery autoretry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomilov committed Mar 5, 2025
1 parent d9d1a3a commit 76b2519
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions h/tasks/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@
__all__ = ("send",)


@celery.task(bind=True, max_retries=3, acks_late=True)
@celery.task(
bind=True,
acks_late=True,
autoretry_for=(smtplib.socket.error,),
retry_backoff=180,
max_retries=3,
retry_jitter=False,
)
def send( # noqa: PLR0913
self,
self, # noqa: ARG001
recipients: list[str],
subject: str,
body: str,
Expand All @@ -34,11 +41,4 @@ def send( # noqa: PLR0913
:type body: unicode
"""
service = celery.request.find_service(EmailService)
try:
service.send(
recipients=recipients, subject=subject, body=body, html=html, tag=tag
)
except smtplib.socket.error as exc:
# Exponential backoff in case the SMTP service is having problems.
countdown = self.default_retry_delay * 2**self.request.retries
self.retry(exc=exc, countdown=countdown)
service.send(recipients=recipients, subject=subject, body=body, html=html, tag=tag)

0 comments on commit 76b2519

Please sign in to comment.