perf: 系统级异步邮件 — 消除SMTP阻塞导致的10-15秒UI冻结
## email_service.py - 新增 send_email_async(): threading.Thread(daemon=True) 包装 send_email() 无需 Flask app_context (send_email仅用os.getenv+smtplib) - 6处 send_email→send_email_async 替换 ## inventory_task.py - 库存预警 send_email→send_email_async (2处)
This commit is contained in:
@ -129,7 +129,7 @@ class InventoryWarningService:
|
||||
"timestamp": "..."
|
||||
}
|
||||
"""
|
||||
from app.utils.email_service import send_email
|
||||
from app.utils.email_service import send_email_async
|
||||
|
||||
beijing_tz = timezone(timedelta(hours=8))
|
||||
now = datetime.now(beijing_tz)
|
||||
@ -248,7 +248,7 @@ class InventoryWarningService:
|
||||
"详情请登录仓库管理系统查看。\n\n"
|
||||
"此邮件由系统自动发送,请勿回复。"
|
||||
)
|
||||
send_email(email, subject, content)
|
||||
send_email_async(email, subject, content)
|
||||
sent_red = True
|
||||
|
||||
# ★ 按邮箱聚合,批量发送黄色预警邮件 ★
|
||||
@ -262,7 +262,7 @@ class InventoryWarningService:
|
||||
"详情请登录仓库管理系统查看。\n\n"
|
||||
"此邮件由系统自动发送,请勿回复。"
|
||||
)
|
||||
send_email(email, subject, content)
|
||||
send_email_async(email, subject, content)
|
||||
sent_yellow = True
|
||||
|
||||
# ★ 批量更新 last_notified_at ★
|
||||
|
||||
Reference in New Issue
Block a user