forked from AiRanthem/xmu-daily-report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
31 lines (23 loc) · 767 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
import os
import requests
from log import get_log_string, logger
MAIL_SERVER_URL = 'http://120.77.39.85:8080/mail/daily_report'
debug = os.getenv("ENV") == "debug"
def send_mail(msg: str, title: str, to: str):
msg += '\n\n【运行日志】\n' + get_log_string()
if not debug:
post = requests.post(MAIL_SERVER_URL, data=json.dumps(
{"title": title, "body": msg, "dest": to}))
return post
else:
logger.info(msg)
def fail(msg: str, title: str, email: str = "", e: Exception = None, shutdown=True, run_fail=False):
logger.error(msg)
if e is not None:
logger.error(e)
if run_fail:
raise RuntimeError(msg)
if shutdown:
send_mail(msg, title, email)
exit(0)