2023-07-14 11:19:26 +08:00
|
|
|
import logging
|
|
|
|
import time
|
|
|
|
|
|
|
|
import click
|
|
|
|
from celery import shared_task
|
|
|
|
from flask import current_app
|
|
|
|
|
|
|
|
from extensions.ext_mail import mail
|
|
|
|
|
|
|
|
|
2023-07-31 13:13:08 +08:00
|
|
|
@shared_task(queue='mail')
|
2023-09-14 12:07:34 +08:00
|
|
|
def send_invite_member_mail_task(to: str, token: str, inviter_name: str, workspace_name: str):
|
2023-07-14 11:19:26 +08:00
|
|
|
"""
|
|
|
|
Async Send invite member mail
|
|
|
|
:param to
|
|
|
|
:param token
|
|
|
|
:param inviter_name
|
|
|
|
:param workspace_name
|
|
|
|
|
2023-09-14 12:07:34 +08:00
|
|
|
Usage: send_invite_member_mail_task.delay(to, token, inviter_name, workspace_name)
|
2023-07-14 11:19:26 +08:00
|
|
|
"""
|
|
|
|
if not mail.is_inited():
|
|
|
|
return
|
|
|
|
|
|
|
|
logging.info(click.style('Start send invite member mail to {} in workspace {}'.format(to, workspace_name),
|
|
|
|
fg='green'))
|
|
|
|
start_at = time.perf_counter()
|
|
|
|
|
|
|
|
try:
|
|
|
|
mail.send(
|
|
|
|
to=to,
|
|
|
|
subject="{} invited you to join {}".format(inviter_name, workspace_name),
|
|
|
|
html="""<p>Hi there,</p>
|
|
|
|
<p>{inviter_name} invited you to join {workspace_name}.</p>
|
|
|
|
<p>Click <a href="{url}">here</a> to join.</p>
|
|
|
|
<p>Thanks,</p>
|
|
|
|
<p>Dify Team</p>""".format(inviter_name=inviter_name, workspace_name=workspace_name,
|
2023-09-14 12:07:34 +08:00
|
|
|
url=f'{current_app.config.get("CONSOLE_WEB_URL")}/activate?token={token}')
|
2023-07-14 11:19:26 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
end_at = time.perf_counter()
|
|
|
|
logging.info(
|
|
|
|
click.style('Send invite member mail to {} succeeded: latency: {}'.format(to, end_at - start_at),
|
|
|
|
fg='green'))
|
|
|
|
except Exception:
|
|
|
|
logging.exception("Send invite member mail to {} failed".format(to))
|