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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 EmailType, get_email_i18n_service
  7. @shared_task(queue="mail")
  8. def send_owner_transfer_confirm_task(language: str, to: str, code: str, workspace: str) -> None:
  9. """
  10. Send owner transfer confirmation email with internationalization support.
  11. Args:
  12. language: Language code for email localization
  13. to: Recipient email address
  14. code: Verification code
  15. workspace: Workspace name
  16. """
  17. if not mail.is_inited():
  18. return
  19. logging.info(click.style("Start owner transfer confirm 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_email(
  24. email_type=EmailType.OWNER_TRANSFER_CONFIRM,
  25. language_code=language,
  26. to=to,
  27. template_context={
  28. "to": to,
  29. "code": code,
  30. "WorkspaceName": workspace,
  31. },
  32. )
  33. end_at = time.perf_counter()
  34. logging.info(
  35. click.style(
  36. "Send owner transfer confirm mail to {} succeeded: latency: {}".format(to, end_at - start_at),
  37. fg="green",
  38. )
  39. )
  40. except Exception:
  41. logging.exception("owner transfer confirm email mail to {} failed".format(to))
  42. @shared_task(queue="mail")
  43. def send_old_owner_transfer_notify_email_task(language: str, to: str, workspace: str, new_owner_email: str) -> None:
  44. """
  45. Send old owner transfer notification email with internationalization support.
  46. Args:
  47. language: Language code for email localization
  48. to: Recipient email address
  49. workspace: Workspace name
  50. new_owner_email: New owner email address
  51. """
  52. if not mail.is_inited():
  53. return
  54. logging.info(click.style("Start old owner transfer notify mail to {}".format(to), fg="green"))
  55. start_at = time.perf_counter()
  56. try:
  57. email_service = get_email_i18n_service()
  58. email_service.send_email(
  59. email_type=EmailType.OWNER_TRANSFER_OLD_NOTIFY,
  60. language_code=language,
  61. to=to,
  62. template_context={
  63. "to": to,
  64. "WorkspaceName": workspace,
  65. "NewOwnerEmail": new_owner_email,
  66. },
  67. )
  68. end_at = time.perf_counter()
  69. logging.info(
  70. click.style(
  71. "Send old owner transfer notify mail to {} succeeded: latency: {}".format(to, end_at - start_at),
  72. fg="green",
  73. )
  74. )
  75. except Exception:
  76. logging.exception("old owner transfer notify email mail to {} failed".format(to))
  77. @shared_task(queue="mail")
  78. def send_new_owner_transfer_notify_email_task(language: str, to: str, workspace: str) -> None:
  79. """
  80. Send new owner transfer notification email with internationalization support.
  81. Args:
  82. language: Language code for email localization
  83. to: Recipient email address
  84. workspace: Workspace name
  85. """
  86. if not mail.is_inited():
  87. return
  88. logging.info(click.style("Start new owner transfer notify mail to {}".format(to), fg="green"))
  89. start_at = time.perf_counter()
  90. try:
  91. email_service = get_email_i18n_service()
  92. email_service.send_email(
  93. email_type=EmailType.OWNER_TRANSFER_NEW_NOTIFY,
  94. language_code=language,
  95. to=to,
  96. template_context={
  97. "to": to,
  98. "WorkspaceName": workspace,
  99. },
  100. )
  101. end_at = time.perf_counter()
  102. logging.info(
  103. click.style(
  104. "Send new owner transfer notify mail to {} succeeded: latency: {}".format(to, end_at - start_at),
  105. fg="green",
  106. )
  107. )
  108. except Exception:
  109. logging.exception("new owner transfer notify email mail to {} failed".format(to))