Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

mail_account_deletion_task.py 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. logger = logging.getLogger(__name__)
  8. @shared_task(queue="mail")
  9. def send_deletion_success_task(to: str, language: str = "en-US") -> None:
  10. """
  11. Send account deletion success email with internationalization support.
  12. Args:
  13. to: Recipient email address
  14. language: Language code for email localization
  15. """
  16. if not mail.is_inited():
  17. return
  18. logger.info(click.style(f"Start send account deletion success email to {to}", fg="green"))
  19. start_at = time.perf_counter()
  20. try:
  21. email_service = get_email_i18n_service()
  22. email_service.send_email(
  23. email_type=EmailType.ACCOUNT_DELETION_SUCCESS,
  24. language_code=language,
  25. to=to,
  26. template_context={
  27. "to": to,
  28. "email": to,
  29. },
  30. )
  31. end_at = time.perf_counter()
  32. logger.info(
  33. click.style(f"Send account deletion success email to {to}: latency: {end_at - start_at}", fg="green")
  34. )
  35. except Exception:
  36. logger.exception("Send account deletion success email to %s failed", to)
  37. @shared_task(queue="mail")
  38. def send_account_deletion_verification_code(to: str, code: str, language: str = "en-US") -> None:
  39. """
  40. Send account deletion verification code email with internationalization support.
  41. Args:
  42. to: Recipient email address
  43. code: Verification code
  44. language: Language code for email localization
  45. """
  46. if not mail.is_inited():
  47. return
  48. logger.info(click.style(f"Start send account deletion verification code email to {to}", fg="green"))
  49. start_at = time.perf_counter()
  50. try:
  51. email_service = get_email_i18n_service()
  52. email_service.send_email(
  53. email_type=EmailType.ACCOUNT_DELETION_VERIFICATION,
  54. language_code=language,
  55. to=to,
  56. template_context={
  57. "to": to,
  58. "code": code,
  59. },
  60. )
  61. end_at = time.perf_counter()
  62. logger.info(
  63. click.style(
  64. "Send account deletion verification code email to {} succeeded: latency: {}".format(
  65. to, end_at - start_at
  66. ),
  67. fg="green",
  68. )
  69. )
  70. except Exception:
  71. logger.exception("Send account deletion verification code email to %s failed", to)