You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mail_change_mail_task.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import logging
  2. import time
  3. import click
  4. from celery import shared_task # type: ignore
  5. from extensions.ext_mail import mail
  6. from libs.email_i18n import get_email_i18n_service
  7. @shared_task(queue="mail")
  8. def send_change_mail_task(language: str, to: str, code: str, phase: str) -> None:
  9. """
  10. Send change email notification with internationalization support.
  11. Args:
  12. language: Language code for email localization
  13. to: Recipient email address
  14. code: Email verification code
  15. phase: Change email phase ('old_email' or 'new_email')
  16. """
  17. if not mail.is_inited():
  18. return
  19. logging.info(click.style("Start change email mail to {}".format(to), fg="green"))
  20. start_at = time.perf_counter()
  21. try:
  22. email_service = get_email_i18n_service()
  23. email_service.send_change_email(
  24. language_code=language,
  25. to=to,
  26. code=code,
  27. phase=phase,
  28. )
  29. end_at = time.perf_counter()
  30. logging.info(
  31. click.style("Send change email mail to {} succeeded: latency: {}".format(to, end_at - start_at), fg="green")
  32. )
  33. except Exception:
  34. logging.exception("Send change email mail to {} failed".format(to))