异常回访增加错误信息抛出
This commit is contained in:
@@ -248,7 +248,7 @@ class NewExceptionTask:
|
||||
|
||||
# 对整个DataFrame的所有列应用替换函数
|
||||
data_yichang = data_yichang.apply(replace_values)
|
||||
|
||||
error_data= []
|
||||
for index_num, row in data_yichang.iterrows(): # 对过滤后的每一条进行派发
|
||||
try:
|
||||
# 每次循环前清空省市区变量
|
||||
@@ -471,8 +471,14 @@ class NewExceptionTask:
|
||||
res = api_instance.data_batch_create(routine_follow_up_payload)
|
||||
logger.info(f"创建结果:{res}")
|
||||
|
||||
except:
|
||||
except Exception as e:
|
||||
error_task_logger.exception(f"异常服务待办派发执行时发生异常: {e}")
|
||||
error_data.append(row)
|
||||
pass
|
||||
if error_data:
|
||||
error_df = pd.DataFrame(error_data)
|
||||
error_df.to_csv(os.path.join(output_dir, "异常派发错误数据.csv"))
|
||||
common_module.send_task_error(task_start_time = task_start_time,task_name= "异常服务待办派发",error_message="详情见失败文件", df = error_df)
|
||||
# ndf = pd.DataFrame(all_data)
|
||||
# ndf.to_csv(os.path.join(output_dir, "异常派发.csv"))
|
||||
common_module.send_task_status(task_start_time, "异常服务待办派发")
|
||||
|
||||
@@ -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}")
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
2025-11-17 09:27:24,426 - common_module.py - error_task_logger - ERROR - 获取异常明细时出错: can't execute an empty query
|
||||
2025-11-17 17:08:41,207 - Exception_Task.py - error_task_logger - ERROR - 异常服务待办派发执行时发生异常: [Errno 13] Permission denied: 'output\\异常派发.csv'
|
||||
2025-11-18 09:04:21,887 - update_BI_CRM_info.py - error_task_logger - ERROR - 任务简道云海外项目CRM客户档案迁移BI执行失败。
|
||||
2025-11-18 09:06:54,279 - update_BI_CRM_info.py - error_task_logger - ERROR - 任务简道云海外项目CRM客户档案迁移BI执行失败。
|
||||
2025-11-18 09:09:10,231 - update_BI_CRM_info.py - error_task_logger - ERROR - 任务简道云海外项目CRM客户档案迁移BI执行失败。
|
||||
2025-11-18 09:11:15,907 - update_BI_CRM_info.py - error_task_logger - ERROR - 导入数据时发生错误: Failed executing the operation; Python type dict cannot be converted
|
||||
2025-11-18 09:11:16,451 - update_BI_CRM_info.py - error_task_logger - ERROR - 任务简道云海外项目CRM客户档案迁移BI执行失败。
|
||||
2025-11-18 09:14:02,671 - update_BI_CRM_info.py - error_task_logger - ERROR - 任务简道云海外项目CRM客户档案迁移BI执行失败。
|
||||
2025-11-18 09:14:18,875 - update_BI_CRM_info.py - error_task_logger - ERROR - 导入数据时发生错误: 1054 (42S22): Unknown column 'nan' in 'field list'
|
||||
2025-11-18 09:14:19,185 - update_BI_CRM_info.py - error_task_logger - ERROR - 任务简道云海外项目CRM客户档案迁移BI执行失败。
|
||||
2025-11-18 09:15:37,826 - update_BI_CRM_info.py - error_task_logger - ERROR - 导入数据时发生错误: 1054 (42S22): Unknown column 'nan' in 'field list'
|
||||
2025-11-18 09:15:38,068 - update_BI_CRM_info.py - error_task_logger - ERROR - 任务简道云海外项目CRM客户档案迁移BI执行失败。
|
||||
2025-11-18 09:16:52,668 - update_BI_CRM_info.py - error_task_logger - ERROR - 任务简道云海外项目CRM客户档案迁移BI执行失败。
|
||||
2025-11-18 09:17:05,585 - update_BI_CRM_info.py - error_task_logger - ERROR - 导入数据时发生错误: 1054 (42S22): Unknown column 'nan' in 'field list'
|
||||
2025-11-18 09:17:05,912 - update_BI_CRM_info.py - error_task_logger - ERROR - 任务简道云海外项目CRM客户档案迁移BI执行失败。
|
||||
2025-11-27 09:08:41,105 - common_module.py - error_task_logger - ERROR - 获取借车宝NGV明细时出错: Length mismatch: Expected axis has 0 elements, new values have 16 elements
|
||||
2025-11-27 09:08:41,278 - JCB_efficient_car_pickup.py - error_task_logger - ERROR - 接车宝日常派发执行出错:获取接车宝数据失败,返回None
|
||||
2025-12-03 09:35:35,923 - update_molecule_reporting_adjustment_to_bi.py - error_task_logger - ERROR - 任务执行失败: unsupported operand type(s) for //: 'NoneType' and 'int'
|
||||
2025-12-03 09:37:19,719 - update_molecule_reporting_adjustment_to_bi.py - error_task_logger - ERROR - 任务执行失败: unsupported operand type(s) for //: 'NoneType' and 'int'
|
||||
2025-12-03 09:38:02,309 - update_molecule_reporting_adjustment_to_bi.py - error_task_logger - ERROR - 任务执行失败: unsupported operand type(s) for //: 'NoneType' and 'int'
|
||||
2025-12-03 09:39:56,925 - update_molecule_reporting_adjustment_to_bi.py - error_task_logger - ERROR - 任务执行失败: unsupported operand type(s) for //: 'NoneType' and 'int'
|
||||
2025-12-03 09:41:22,721 - update_molecule_reporting_adjustment_to_bi.py - error_task_logger - ERROR - 任务执行失败: unsupported operand type(s) for //: 'NoneType' and 'int'
|
||||
2025-12-03 09:42:57,097 - update_molecule_reporting_adjustment_to_bi.py - error_task_logger - ERROR - 任务执行失败: unsupported operand type(s) for //: 'NoneType' and 'int'
|
||||
2025-12-03 09:45:13,572 - update_molecule_reporting_adjustment_to_bi.py - error_task_logger - ERROR - 任务执行失败: unsupported operand type(s) for //: 'NoneType' and 'int'
|
||||
2025-12-03 09:50:07,647 - update_molecule_reporting_adjustment_to_bi.py - error_task_logger - ERROR - 任务执行失败: unsupported operand type(s) for //: 'NoneType' and 'int'
|
||||
2025-12-03 09:51:28,042 - update_molecule_reporting_adjustment_to_bi.py - error_task_logger - ERROR - 任务执行失败: unsupported operand type(s) for //: 'NoneType' and 'int'
|
||||
2025-12-03 09:55:47,222 - update_molecule_reporting_adjustment_to_bi.py - error_task_logger - ERROR - 任务执行失败: unsupported operand type(s) for //: 'NoneType' and 'int'
|
||||
|
||||
@@ -98,7 +98,7 @@ class DenominatorReportingAdjustment:
|
||||
if id_in_map == field_id:
|
||||
transformed_data[display_name] = value
|
||||
break
|
||||
# print(transformed_data.get("是否上传衡石"))
|
||||
# print(transformed_data.get("是否上传衡石"))# BI上已经实现
|
||||
# if transformed_data.get("是否上传衡石") == "否" or transformed_data.get("是否上传衡石") is None:
|
||||
# continue
|
||||
self.denominator_data_list.append(transformed_data)
|
||||
|
||||
@@ -88,6 +88,7 @@ class MoleculeReportingAdjustment:
|
||||
if id_in_map == field_id:
|
||||
transformed_data[display_name] = value
|
||||
break
|
||||
# BI上已经实现
|
||||
# if transformed_data.get("是否上传衡石") == "否" or transformed_data.get("是否上传衡石") is None:
|
||||
# continue
|
||||
self.molecule_data_list.append(transformed_data)
|
||||
@@ -190,6 +191,7 @@ class MoleculeReportingAdjustment:
|
||||
logger.info(f"获取宜搭数据成功")
|
||||
|
||||
df = pd.DataFrame(self.molecule_data_list)
|
||||
# df.to_csv('molecule_data.csv', index=False)
|
||||
if '归属月份' in df.columns:
|
||||
# 确保是整数类型
|
||||
df['归属月份'] = df['归属月份'].astype('Int64')
|
||||
|
||||
Reference in New Issue
Block a user