Problem:
We've recently updated most of our email dispatch calls to use celery tasks (asynchronously)- #1341.
But, some of our dispatch email use cases require special handling upon email failure, which Celery does not surface (regardless of if we call asynchronously or synchronously through Celery).
Because Celery does not surface exceptions outside of a task, we currently don't use celery for these use cases, and instead call our dispatch logic directly. We'd like to be able to use Celery for all email dispatch calls.
Solution:
Celery offers an on_failure binding - https://docs.celeryq.dev/en/stable/userguide/tasks.html#on_failure, where we pass in a function to be executed upon failure / exception.
The specific use cases where we need to specify on_failure binding:
- request completion
- email connector and test email connector
- identity verification code