异常回访增加错误信息抛出

This commit is contained in:
z66
2025-12-04 17:44:21 +08:00
parent 931c0929b7
commit 8c34b781e0
10 changed files with 860 additions and 119 deletions
+29 -9
View File
@@ -6,7 +6,7 @@ import pandas as pd
import pymysql
from api import API
from log_config import configure_task_logger, configure_error_task_logger
import time
api_instance = API()
# 获取已经配置好的常规日志记录器
@@ -168,7 +168,6 @@ class CommonModule:
cursor.close()
conn.close()
return data_yichang
except Exception as e:
@@ -200,7 +199,7 @@ class CommonModule:
# 执行语句并获取结果集
cursor.execute(sql)
rows = cursor.fetchall()
all_fields = cursor.description # 获取所有字段名
all_fields = cursor.description # 获取所有字段名
# 执行结果转化为dataframe
col = [i[0] for i in all_fields]
@@ -215,7 +214,6 @@ class CommonModule:
error_task_logger.error(f"获取续约待办数据时出错: {e}")
return None
def get_jcb_details(self, ):
"""
从固定的数据库中获取前几天的借车宝。
@@ -510,7 +508,6 @@ class CommonModule:
error_task_logger.error(f"获取履约表数据时出错: {e}")
return None
def get_GroupNotification_details(self, ):
"""
从f6operation_data_relay数据库中获取短信数据支撑数据。
@@ -612,9 +609,11 @@ class CommonModule:
task_start_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
CommonModule.send_task_error(task_start_time, "发送任务状态", e)
def send_task_error(self, task_start_time: str, task_name: str, error_message: str) -> None:
def send_task_error(self, task_start_time: str, task_name: str, error_message: str,
df: pd.DataFrame = None) -> None:
"""
将任务失败情况发送到简道云(影响业务数据时调用)
:param df: 失败文件
:param task_start_time: 任务开始时间(字符串格式:"%Y-%m-%d %H:%M:%S",表示北京时间 UTC+8
:param task_name: 任务名称
:param error_message: 失败详情
@@ -639,7 +638,26 @@ class CommonModule:
task_end_iso = end_time_utc.strftime("%Y-%m-%dT%H:%M:%SZ")
task_start_iso = task_start_utc.strftime("%Y-%m-%dT%H:%M:%SZ")
# 6. 构造请求数据(所有时间以 UTC 格式发送)
# 6.上传附件
UUid = time.strftime("%Y%m%d%H%M%S", time.localtime())
if df is not None:
df.to_excel("upload_file.xlsx", index=False)
file_path = "upload_file.xlsx"
up_data = api_instance.get_upload_token(
{"api_key": "6694d3c4fcb69ca9a111a6c4", "entry_id": "689ae65da00c17578e27cd74",
"transaction_id": UUid})
upload_url = up_data.get("upload_url")
upload_token = up_data.get("upload_token")
upload_result = api_instance.upload_file(
{"upload_url": upload_url, "upload_token": upload_token, "file_path": file_path})
upload_key = upload_result.get("key")
else:
upload_key = ""
# 7. 构造请求数据(所有时间以 UTC 格式发送)
payload = {
"api_key": Config.SCHEDULED_TASKS_APP_ID,
"entry_id": Config.JDY_TASKS_ERROR_ENTRY_ID,
@@ -650,10 +668,12 @@ class CommonModule:
"_widget_1744873387502": {"value": task_end_iso}, # UTC 结束时间
"_widget_1744873387504": {"value": run_time_sec},
"_widget_1754981992215": {"value": error_message}, # 错误信息
}
"_widget_1764830825356": {"value": [upload_key]}
},
"transaction_id": UUid
}
# 7. 发送请求
# 8. 发送请求
response = api_instance.data_batch_create(payload)
logger.info(f"任务错误发生成功: {response}")