添加创建请求和读取进度接口

This commit is contained in:
HKXluo
2025-11-20 20:54:15 +08:00
parent eede77a848
commit 0e3f229260
7 changed files with 404 additions and 55 deletions

22
shared_utils.py Normal file
View File

@@ -0,0 +1,22 @@
# 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:]