feat(file-check): 增加文件检核 Excel 下载链接解析与展示功能
This commit is contained in:
1 parent
5e7e5a8717
commit
f21216f81e
21 files changed
+885
-125
No files matched your search
@@ -39,7 +39,7 @@ import tempfile
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, TextIO
|
||||
|
||||
@@ -126,26 +126,55 @@ def _env(name: str, default: str = "") -> str:
|
||||
return value
|
||||
|
||||
|
||||
def _log_line_timestamp() -> str:
|
||||
"""
|
||||
生成 worker 日志行首时间戳(本地时区)。
|
||||
|
||||
核心逻辑:RPA 批量导出常跨 1+ 小时,行级时间便于对照 DSV 页面卡顿与超时点。
|
||||
|
||||
Returns:
|
||||
str: `YYYY-MM-DD HH:MM:SS` 格式字符串。
|
||||
"""
|
||||
return datetime.now(UTC).astimezone().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
class _TeeStream:
|
||||
"""
|
||||
同时写入控制台与日志文件的轻量 stream。
|
||||
|
||||
核心逻辑:保留原 stdout/stderr,避免计划任务改为日志模式后本地调试看不到输出;
|
||||
文件 flush 采用行级同步,RPA 异常退出时尽量保留最后几行排障信息。
|
||||
每行完整输出前自动前缀本地时间戳;文件 flush 采用行级同步,RPA 异常退出时尽量
|
||||
保留最后几行排障信息。
|
||||
"""
|
||||
|
||||
def __init__(self, console: TextIO, log_file: TextIO) -> None:
|
||||
self._console = console
|
||||
self._log_file = log_file
|
||||
self._pending = ""
|
||||
self.encoding = getattr(console, "encoding", "utf-8")
|
||||
|
||||
def _emit_line(self, line: str, *, newline: bool) -> None:
|
||||
"""将单行(可含时间戳前缀)写入控制台与日志文件。"""
|
||||
if line:
|
||||
stamped = f"{_log_line_timestamp()} {line}"
|
||||
self._console.write(stamped)
|
||||
self._log_file.write(stamped)
|
||||
if newline:
|
||||
self._console.write("\n")
|
||||
self._log_file.write("\n")
|
||||
|
||||
def write(self, text: str) -> int:
|
||||
self._console.write(text)
|
||||
written = self._log_file.write(text)
|
||||
self._pending += text
|
||||
while "\n" in self._pending:
|
||||
line, self._pending = self._pending.split("\n", 1)
|
||||
self._emit_line(line, newline=True)
|
||||
self.flush()
|
||||
return written
|
||||
return len(text)
|
||||
|
||||
def flush(self) -> None:
|
||||
if self._pending:
|
||||
self._emit_line(self._pending, newline=False)
|
||||
self._pending = ""
|
||||
self._console.flush()
|
||||
self._log_file.flush()
|
||||
|
||||
@@ -158,7 +187,8 @@ def _configure_file_logging() -> Path | None:
|
||||
按 FREIGHT_RPA_LOG_FILE 启用 worker 文件日志。
|
||||
|
||||
【AI 触发时机】:Windows 任务计划程序后台运行 RPA worker 时配置本变量,
|
||||
让所有 print/stdout/stderr 同时落盘,便于排查登录、下载、回调失败。
|
||||
让所有 print/stdout/stderr 同时落盘,并在每行前自动加本地时间戳,便于排查
|
||||
登录、下载、回调失败与长批次耗时。
|
||||
|
||||
Returns:
|
||||
Path | None: 已启用的日志路径;未配置时返回 None。
|
||||
|
||||
Reference in new issue
Block a user