fix(meituan-etl): 常驻可观测性——压制美团 logger traceback + stdout 行缓冲
本地灰度(20 城 / 每 10min 一轮)暴露两个只在常驻/cron 下出现的问题: - 美团调用偶发 SSL EOF(本机走代理高并发)/ code=5 被 meituan._call 的 logger.exception 打完整 traceback,单轮刷数十 KB 日志;ETL 已用 _STATS 统计放弃页数,故把 shagua.meituan logger 压到 CRITICAL(线上直连少见,统计仍可见放弃数); - stdout 块缓冲导致 cron/后台 log 攒到 ~4KB 才落盘,常驻几乎看不到进度; reconfigure(line_buffering=True) 每行即时 flush。
This commit is contained in:
@@ -34,6 +34,7 @@ from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
@@ -43,9 +44,11 @@ import time
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
# Windows 控制台按 UTF-8 输出中文/¥
|
||||
# Windows 控制台按 UTF-8 输出中文/¥;line_buffering=True 让 print 每行即时 flush——
|
||||
# 否则 stdout 重定向到 cron/后台日志文件时是块缓冲,要攒到 ~4KB 或进程退出才落盘,
|
||||
# 常驻(--loop)时几乎看不到每轮进度。
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding="utf-8") # type: ignore[attr-defined]
|
||||
sys.stdout.reconfigure(encoding="utf-8", line_buffering=True) # type: ignore[attr-defined]
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
|
||||
@@ -61,6 +64,11 @@ from app.models.meituan_coupon import MeituanCoupon # noqa: E402
|
||||
# ETL 不需要 SQL 日志,显式关掉(入库不受影响;线上 prod 本就 echo=False)。
|
||||
engine.echo = False
|
||||
|
||||
# 美团调用偶发错误(本机走代理高并发时的 SSL EOF / 上游 code=5 等)会被 meituan._call 的
|
||||
# logger.exception 打完整 traceback,并发抓取下单轮可刷数十 KB 日志。ETL 自己用 _STATS 统计
|
||||
# 「放弃页数」,无需逐条 traceback,故把美团 logger 压到 CRITICAL(线上直连少见此类错误)。
|
||||
logging.getLogger("shagua.meituan").setLevel(logging.CRITICAL)
|
||||
|
||||
QUERY_PATH = "/cps_open/common/api/v1/query_coupon"
|
||||
PAGE_SIZE = 20
|
||||
MAX_PAGES = 80 # 单路安全上限(搜索 ~52 页、供给 ~70 页)
|
||||
|
||||
Reference in New Issue
Block a user