選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

mail_change_mail_task.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import logging
  2. import time
  3. import click
  4. from celery import shared_task
  5. from extensions.ext_mail import mail
  6. from libs.email_i18n import EmailType, 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(f"Start change email mail to {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(click.style(f"Send change email mail to {to} succeeded: latency: {end_at - start_at}", fg="green"))
  31. except Exception:
  32. logging.exception("Send change email mail to %s failed", to)
  33. @shared_task(queue="mail")
  34. def send_change_mail_completed_notification_task(language: str, to: str) -> None:
  35. """
  36. Send change email completed notification with internationalization support.
  37. Args:
  38. language: Language code for email localization
  39. to: Recipient email address
  40. """
  41. if not mail.is_inited():
  42. return
  43. logging.info(click.style(f"Start change email completed notify mail to {to}", fg="green"))
  44. start_at = time.perf_counter()
  45. try:
  46. email_service = get_email_i18n_service()
  47. email_service.send_email(
  48. email_type=EmailType.CHANGE_EMAIL_COMPLETED,
  49. language_code=language,
  50. to=to,
  51. template_context={
  52. "to": to,
  53. "email": to,
  54. },
  55. )
  56. end_at = time.perf_counter()
  57. logging.info(
  58. click.style(
  59. f"Send change email completed mail to {to} succeeded: latency: {end_at - start_at}",
  60. fg="green",
  61. )
  62. )
  63. except Exception:
  64. logging.exception("Send change email completed mail to %s failed", to)