From f8ed0cec6c009b01652313325b4284ea69a6deae Mon Sep 17 00:00:00 2001 From: dongchangxi <458593490@qq.com> Date: Tue, 10 Oct 2023 15:16:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- timer/check_task.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/timer/check_task.py b/timer/check_task.py index 8a14b50..742976b 100644 --- a/timer/check_task.py +++ b/timer/check_task.py @@ -20,6 +20,8 @@ else: import config +notifyUserIds = ["DongZhangX"] + #公共连接库 def pymysqlAlias(): return pymysql.connect( @@ -30,22 +32,19 @@ 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 - - data = { - 'userId': user_agent_id, - 'message': content, - } - headers = {'Content-Type': 'application/json'} - message_send_url = "https://mp.api.suwa3d.com/api/qyNotify/sendMessage?userId="+user_agent_id+"&message="+content - response = requests.post(message_send_url, data=json.dumps(data), headers=headers) + for user_agent_id in notifyUserIds: + data = { + 'userId': user_agent_id, + 'message': content, + } + headers = {'Content-Type': 'application/json'} + message_send_url = "https://mp.api.suwa3d.com/api/qyNotify/sendMessage?userId="+user_agent_id+"&message="+content + response = requests.post(message_send_url, data=json.dumps(data), headers=headers) @@ -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)}")