-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(BSR)[API] feat: use celery for sending mails
- Loading branch information
1 parent
bd3ac3c
commit c4144f0
Showing
11 changed files
with
236 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from celery import Celery, Task | ||
from flask import Flask | ||
|
||
def celery_init_app(app: Flask) -> Celery: | ||
class FlaskTask(Task): | ||
def __call__(self, *args: object, **kwargs: object) -> object: | ||
with app.app_context(): | ||
return self.run(*args, **kwargs) | ||
|
||
celery_app = Celery(app.name, task_cls=FlaskTask) | ||
celery_app.config_from_object(app.config["CELERY"]) | ||
celery_app.set_default() | ||
app.extensions["celery"] = celery_app | ||
return celery_app | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from pcapi.flask_app import app as flask_app | ||
|
||
|
||
celery_app = flask_app.extensions["celery"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from celery import shared_task | ||
|
||
from pcapi.core.external import sendinblue | ||
from pcapi.core.mails.transactional.send_transactional_email import send_transactional_email | ||
from pcapi.tasks.serialization.sendinblue_tasks import SendTransactionalEmailRequest | ||
from pcapi.tasks.serialization.sendinblue_tasks import UpdateSendinblueContactRequest | ||
|
||
|
||
@shared_task(name="mails.tasks.update_contact_attributes", acks_late=True) | ||
def update_contact_attributes_task(payload: UpdateSendinblueContactRequest) -> None: | ||
sendinblue.make_update_request(payload) | ||
|
||
|
||
@shared_task(name="mails.tasks.send_transactional_email_primary", acks_late=True) | ||
def send_transactional_email_primary_task(payload: SendTransactionalEmailRequest) -> None: | ||
send_transactional_email(payload) | ||
|
||
|
||
@shared_task(name="mails.tasks.send_transactional_email_secondary", acks_late=True) | ||
def send_transactional_email_secondary_task(payload: SendTransactionalEmailRequest) -> None: | ||
send_transactional_email(payload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters