Browse Source

消息通知修改

master
dongchangxi 2 years ago
parent
commit
f8ed0cec6c
  1. 19
      timer/check_task.py

19
timer/check_task.py

@ -20,6 +20,8 @@ else:
import config import config
notifyUserIds = ["DongZhangX"]
#公共连接库 #公共连接库
def pymysqlAlias(): def pymysqlAlias():
return pymysql.connect( return pymysql.connect(
@ -30,15 +32,12 @@ def pymysqlAlias():
db=config.mysql_local['db'], db=config.mysql_local['db'],
charset=config.mysql_local['charset'],) charset=config.mysql_local['charset'],)
def notify(user_agent_id,content): def notify(content):
if user_agent_id == "":
return "user_agent_id 不能为空"
if content == "": if content == "":
return "content 不能为空" return "content 不能为空"
#获取token for user_agent_id in notifyUserIds:
data = { data = {
'userId': user_agent_id, 'userId': user_agent_id,
'message': content, 'message': content,
@ -75,26 +74,26 @@ def check_task_distributed_detail():
taskData = get_task_distributed_by_id(row["task_distributed_id"]) taskData = get_task_distributed_by_id(row["task_distributed_id"])
if taskData == "error": if taskData == "error":
notify("DongZhangXi",f'task_distributed_id{row["task_distributed_id"]}的数据异常') notify(f'task_distributed_id{row["task_distributed_id"]}的数据异常')
continue continue
if row["step"] == "step1": if row["step"] == "step1":
#判断是否超过了30=分钟 #判断是否超过了30=分钟
if (time.time() - time.mktime(row["started_at"].timetuple())) > 180: 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": if row["step"] == "step2":
#判断是否超过了10分钟 #判断是否超过了10分钟
if (time.time() - time.mktime(row["started_at"].timetuple())) > 60*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": if row["step"] == "step3":
#判断是否超过了10分钟 #判断是否超过了10分钟
if (time.time() - time.mktime(row["started_at"].timetuple())) > 60*8: 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" return "no"
except Exception as e: except Exception as e:
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行check_task_distributed_detail异常: {str(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=分钟 #判断是否超过了30=分钟
if (time.time() - time.mktime(row["created_at"].timetuple())) > 60*25: 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" return "no"
except Exception as e: except Exception as e:
print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行check_task_distributed_detail异常: {str(e)}") print(f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 执行check_task_distributed_detail异常: {str(e)}")

Loading…
Cancel
Save