修复 prefect中psql报错
This commit is contained in:
@@ -28,7 +28,19 @@ from prefect import flow, get_run_logger, task
|
||||
|
||||
from inventory_analytics.logging_utils import exception_fields
|
||||
from inventory_analytics.channel_inventory_sync.entrypoint import main as channel_inventory_sync_main
|
||||
from inventory_analytics.channel_inventory_sync.entrypoint import LOG_FILE as CHANNEL_INVENTORY_SYNC_LOG_FILE
|
||||
from inventory_analytics.batch_inventory_report.cli import main as batch_inventory_report_main
|
||||
from inventory_analytics.batch_inventory_report.service import LOG_FILE as BATCH_INVENTORY_REPORT_LOG_FILE
|
||||
|
||||
|
||||
def read_log_tail(log_file: Path, line_count: int = 80) -> str:
|
||||
try:
|
||||
lines = log_file.read_text(encoding="utf-8", errors="replace").splitlines()
|
||||
except FileNotFoundError:
|
||||
return f"日志文件不存在: {log_file.name}"
|
||||
except Exception as exc: # noqa: BLE001
|
||||
return f"读取日志文件失败: {exc.__class__.__name__}: {exc}"
|
||||
return "\n".join(lines[-line_count:]) if lines else f"日志文件为空: {log_file.name}"
|
||||
|
||||
|
||||
@task(name="run-channel-inventory-sync")
|
||||
@@ -58,6 +70,7 @@ def run_channel_inventory_sync_task() -> None:
|
||||
root_logger.setLevel(original_level)
|
||||
if exit_code != 0:
|
||||
logger.error("渠道库存统计失败,退出码=%s", exit_code)
|
||||
logger.error("渠道库存统计日志尾部:\n%s", read_log_tail(CHANNEL_INVENTORY_SYNC_LOG_FILE))
|
||||
raise RuntimeError(f"渠道库存统计执行失败,退出码: {exit_code}")
|
||||
logger.info("渠道库存统计完成,耗时毫秒=%s", int((time.monotonic() - started_at) * 1000))
|
||||
|
||||
@@ -107,6 +120,7 @@ def run_batch_inventory_report_task(
|
||||
root_logger.setLevel(original_level)
|
||||
if exit_code != 0:
|
||||
logger.error("批次库存统计失败,退出码=%s", exit_code)
|
||||
logger.error("批次库存统计日志尾部:\n%s", read_log_tail(BATCH_INVENTORY_REPORT_LOG_FILE))
|
||||
raise RuntimeError(f"批次库存统计报表执行失败,退出码: {exit_code}")
|
||||
logger.info("批次库存统计完成,耗时毫秒=%s", int((time.monotonic() - started_at) * 1000))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user