# shared_utils.py import time import logging from threading import Lock # 全局变量 task_registry = {} file_registry = {} file_lock = Lock() task_lock = Lock() def add_task_log(task_id, message, task_registry, task_lock): """添加任务日志""" with task_lock: if task_id in task_registry: timestamp = time.strftime("%Y-%m-%d %H:%M:%S") log_entry = f"[{timestamp}] {message}" task_registry[task_id]['logs'].append(log_entry) # 保持日志数量不超过1000条 if len(task_registry[task_id]['logs']) > 1000: task_registry[task_id]['logs'] = task_registry[task_id]['logs'][-1000:]