提交 55fb4906 authored 作者: 刘擎阳's avatar 刘擎阳

1.优化

上级 c3fbce7a
......@@ -45,6 +45,24 @@ class CreateCartonPdf(object):
_logger.error(f"发生异常,将在 1秒 后重试。错误详情: {str(err)}")
time.sleep(1) # 出错后多睡一会儿,防止日志刷屏
def cancel_sns(self, order_id):
"""
启动守护进程循环
:param interval: 每次循环的休眠时间(秒)
"""
_logger.info(f">>>订单{order_id} 取消重新下单 <<<")
try:
# --- 执行业务逻辑 ---
result = odoo_conn.odoo_db.execute("temu.order", "cancel_sns", ["self"], order_id)
# 如果 Odoo 返回了处理的数量,可以打个日志
if result:
_logger.info(f"本次执行结果: {result}")
except Exception as err:
# --- 异常处理 ---
# 捕获所有异常,确保脚本不会崩掉退出
_logger.error(f"发生异常,将在 1秒 后重试。错误详情: {str(err)}")
time.sleep(1) # 出错后多睡一会儿,防止日志刷屏
try:
pool = redis.ConnectionPool(**config.redis_options)
......@@ -56,10 +74,13 @@ try:
result = r.brpop(['create_pdf_data'], 0)
data1 = result[1]
task_data = json.loads(data1)
if result:
data_type = task_data.get('type')
if data_type == 'cancel':
pdf_obj.cancel_sns(task_data.get('order_id'))
elif data_type == 'pdf':
pdf_obj.start_worker(task_data.get('order_no'), task_data.get('count'))
else:
logging.error('未找到数据类型')
logging.error('未识别到类型 %s' % data_type)
except Exception as e:
logging.error('error: %s' % str(e))
continue
......
......@@ -109,6 +109,8 @@ class TemuService(object):
return return_res
# === 场景 C: 更新模式 ===
else:
if state == 'cancel':
redis_obj.lpush('create_pdf_data', json.dumps({'order_id': order_id, 'type': 'cancel'}))
# 原生 SQL 更新主表
self._update_order(cr, order_id, kw)
# 清理旧数据 (全删全插模式)
......@@ -226,7 +228,7 @@ class TemuService(object):
'cartonInfo': final_cartons
}
# 记录日志
redis_obj.lpush('create_pdf_data', json.dumps({'order_no': order_no, 'count': len(final_cartons)}))
redis_obj.lpush('create_pdf_data', json.dumps({'order_no': order_no, 'count': len(final_cartons), 'type': 'pdf'}))
self._log_api(cr, kw_data, order_no, "")
except Exception as e:
......@@ -391,6 +393,12 @@ class TemuService(object):
# 【核心修改】开启一个新的事务来记录错误日志
try:
with db_handle.get_cursor() as log_cr:
log_sql = """
INSERT INTO temu_api_log (
big_bag_no, error_msg, push_time, data_text,
success_bl, request_id, source, create_date
) VALUES (%s, %s, %s, %s, %s, %s, '推入', (NOW() at time zone 'UTC'))
"""
log_params = (
f'Temu订单取消: {order_no}',
f"系统异常: {str(err)}", # 记录具体的报错信息
......@@ -500,6 +508,12 @@ class TemuService(object):
str(err))
try:
with db_handle.get_cursor() as log_cr:
log_sql = """
INSERT INTO temu_api_log (
big_bag_no, error_msg, push_time, data_text,
success_bl, request_id, source, create_date
) VALUES (%s, %s, (NOW() at time zone 'UTC'), %s, %s, %s, '推入', (NOW() at time zone 'UTC'))
"""
log_params = (
f'Temu订单查询箱贴: {order_no}',
f"系统异常: {str(err)}", # 记录详细错误
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论