消息通知修改

This commit is contained in:
dongchangxi committed 2023-10-10 15:16:32 +08:00
1 parent 56b0a5f6d5
commit f8ed0cec6c
1 file changed
+9 -10
+9 -10
View File
@@ -20,6 +20,8 @@ else:
import config
notifyUserIds = ["DongZhangX"]
#公共连接库
def pymysqlAlias():
return pymysql.connect(
@@ -30,15 +32,12 @@ def pymysqlAlias():
db=config.mysql_local['db'],
charset=config.mysql_local['charset'],)
def notify(user_agent_id,content):
if user_agent_id == "":
return "user_agent_id 不能为空"
def notify(content):
if content == "":
return "content 不能为空"
#获取token
for user_agent_id in notifyUserIds:
data = {
'userId': user_agent_id,
'message': content,
@@ -75,26 +74,26 @@ def check_task_distributed_detail():
taskData = get_task_distributed_by_id(row["task_distributed_id"])
if taskData == "error":
notify("DongZhangXi",f'task_distributed_id{row["task_distributed_id"]}的数据异常')
notify(f'task_distributed_id{row["task_distributed_id"]}的数据异常')
continue
if row["step"] == "step1":
#判断是否超过了30=分钟
if (time.time() - time.mktime(row["started_at"].timetuple())) > 180:
#发送消息通知
notify("DongZhangXi",f'任务{taskData["task_key"]}的{row["step"]}步骤已经超运行太久了,当前还有{waitNums}个任务未完成')
notify(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}-任务{taskData["task_key"]}的{row["step"]}步骤已经超运行太久了,当前还有{waitNums}个任务未完成')
if row["step"] == "step2":
#判断是否超过了10分钟
if (time.time() - time.mktime(row["started_at"].timetuple())) > 60*10:
#发送消息通知
notify("DongZhangXi",f'任务{taskData["task_key"]}的{row["step"]}步骤已经超运行太久了,当前还有{waitNums}个任务未完成')
notify(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}-任务{taskData["task_key"]}的{row["step"]}步骤已经超运行太久了,当前还有{waitNums}个任务未完成')
if row["step"] == "step3":
#判断是否超过了10分钟
if (time.time() - time.mktime(row["started_at"].timetuple())) > 60*8:
#发送消息通知
notify("DongZhangXi",f'任务{taskData["task_key"]}的{row["step"]}步骤已经超运行太久了,当前还有{waitNums}个任务未完成')
notify(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}-任务{taskData["task_key"]}的{row["step"]}步骤已经超运行太久了,当前还有{waitNums}个任务未完成')
return "no"
except Exception as e:
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行check_task_distributed_detail异常: {str(e)}")
@@ -126,7 +125,7 @@ def check_task():
#判断是否超过了30=分钟
if (time.time() - time.mktime(row["created_at"].timetuple())) > 60*25:
#发送消息通知
notify("DongZhangXi",f'任务{row["task_key"]}已经超运行超过25分钟了,当前还有{waitNums}个任务未完成')
notify(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}-任务{row["task_key"]}已经超运行超过25分钟了,当前还有{waitNums}个任务未完成')
return "no"
except Exception as e:
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行check_task_distributed_detail异常: {str(e)}")