update
This commit is contained in:
parent
d1f335d6a2
commit
64beb48074
|
|
@ -17,6 +17,31 @@ def _mask_token(token: str) -> str:
|
|||
return f"{token[:6]}***{token[-4:]}"
|
||||
|
||||
|
||||
def _log_text_in_chunks(*, prefix: str, text: str, chunk_bytes: int = 8_000) -> None:
|
||||
"""
|
||||
将大文本尽可能写入 run_log:
|
||||
- 按 UTF-8 字节切分,避免单条日志过大导致整条无法写入(capture_logs 会在超过 max_bytes 时丢弃整条并标记截断)
|
||||
- 由上层 capture_logs(max_bytes=200_000) 负责总量截断
|
||||
"""
|
||||
try:
|
||||
if not text:
|
||||
logger.info("%s <empty>", prefix)
|
||||
return
|
||||
|
||||
if chunk_bytes <= 0:
|
||||
chunk_bytes = 8_000
|
||||
|
||||
raw_bytes = text.encode("utf-8", errors="replace")
|
||||
total = (len(raw_bytes) + chunk_bytes - 1) // chunk_bytes
|
||||
for i in range(total):
|
||||
b = raw_bytes[i * chunk_bytes : (i + 1) * chunk_bytes]
|
||||
chunk = b.decode("utf-8", errors="replace")
|
||||
logger.info("%s chunk %s/%s: %s", prefix, i + 1, total, chunk)
|
||||
except Exception:
|
||||
# run_log 捕获属于“尽力而为”,任何异常都不应影响任务执行
|
||||
return
|
||||
|
||||
|
||||
class SyncOAToDidiTokenJob(BaseJob):
|
||||
"""
|
||||
示例 Job:演示致远 OA 的 token 获取与日志记录
|
||||
|
|
@ -133,6 +158,7 @@ class SyncOAToDidiExportFormJob(BaseJob):
|
|||
content_type,
|
||||
base_url,
|
||||
)
|
||||
_log_text_in_chunks(prefix="Seeyon export_form_soap raw", text=raw_text, chunk_bytes=8_000)
|
||||
|
||||
return {
|
||||
"raw": raw_text,
|
||||
|
|
|
|||
Loading…
Reference in New Issue