Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

mail_enterprise_task.py 1021B

123456789101112131415161718192021222324252627282930313233
  1. import logging
  2. import time
  3. import click
  4. from celery import shared_task # type: ignore
  5. from flask import render_template_string
  6. from extensions.ext_mail import mail
  7. @shared_task(queue="mail")
  8. def send_enterprise_email_task(to, subject, body, substitutions):
  9. if not mail.is_inited():
  10. return
  11. logging.info(click.style("Start enterprise mail to {} with subject {}".format(to, subject), fg="green"))
  12. start_at = time.perf_counter()
  13. try:
  14. html_content = render_template_string(body, **substitutions)
  15. if isinstance(to, list):
  16. for t in to:
  17. mail.send(to=t, subject=subject, html=html_content)
  18. else:
  19. mail.send(to=to, subject=subject, html=html_content)
  20. end_at = time.perf_counter()
  21. logging.info(
  22. click.style("Send enterprise mail to {} succeeded: latency: {}".format(to, end_at - start_at), fg="green")
  23. )
  24. except Exception:
  25. logging.exception("Send enterprise mail to {} failed".format(to))