Skip to content

Conversation

@stefanotroncaro
Copy link
Contributor

@stefanotroncaro stefanotroncaro commented Oct 24, 2025

  • Added a CeleryTaskEmailClient, which schedules an email sending task instead of sending the email outright.
  • Configured app container to use the CeleryTaskEmailClient as default client
  • Configured celery worker container to use other email client implementations (that synchronously send emails)
  • Added configurable email sending retry logic by specific methods on the EmailService, through env variables.

@stefanotroncaro stefanotroncaro marked this pull request as ready for review October 27, 2025 21:07
@stefanotroncaro stefanotroncaro requested review from DanTcheche and jsarrolt and removed request for jsarrolt October 27, 2025 21:14
@stefanotroncaro stefanotroncaro changed the title feat: celery task email client default on api container Add email client to send emails via celery tasks Oct 27, 2025
raise

multiplicator = BACKOFF_EXPONENTIAL_GROWTH_BASE**self.request.retries
countdown_in_seconds = email.context.backoff_in_seconds * multiplicator
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird for me that the email has the information about the backoff. We are tying email data with celery data. Same for max retries.
This should probably be a parameter of this function independent from email.

Copy link
Contributor Author

@stefanotroncaro stefanotroncaro Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get what you mean.

The intention behind the context field is to represent metadata related to the email, which can be used by the different clients to customize behavior. This can range from the error message that needs to be generated upon failed delivery, to, in this case, the backoff value. Perhaps simply metadata would have been a better name for the field.

We could create an email metadata class by itself and pass the email and metadata objects as different arguments, but then the metadata would lose its association with the correct email object, which feels off to me.

Alternatively, we can set the backoff and growth base as env variables and have them apply to all emails. Perhaps we don't need to be able to customize those values individually for each particular email? The previous implementation suggested that such versatility was intended, as it attempted to configure independent env variables for each kind of email.

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants