添加创建请求和读取进度接口
This commit is contained in:
@@ -3,14 +3,12 @@ import shutil
|
||||
import threading
|
||||
import time
|
||||
import logging
|
||||
from shared_utils import file_registry, file_lock, task_registry, task_lock
|
||||
|
||||
UPLOAD_FOLDER = 'temp_files'
|
||||
CLEANUP_INTERVAL = 3600 # 清理临时文件的间隔(秒)
|
||||
FILE_EXPIRY = 7200 # 文件过期时间(秒)
|
||||
|
||||
file_registry = {}
|
||||
file_lock = threading.Lock()
|
||||
|
||||
def cleanup_temp_files():
|
||||
current_time = time.time()
|
||||
expired_folders = []
|
||||
@@ -38,6 +36,17 @@ def cleanup_temp_files():
|
||||
logging.error(f"删除文件夹 {folder_path} 失败: {e}")
|
||||
|
||||
logging.info(f"清理完成,共删除 {len(expired_folders)} 个过期文件夹")
|
||||
|
||||
# 同时清理过期的任务记录(超过2小时)
|
||||
with task_lock:
|
||||
expired_tasks = []
|
||||
for task_id, task_info in list(task_registry.items()):
|
||||
if current_time - task_info['create_time'] > FILE_EXPIRY:
|
||||
expired_tasks.append(task_id)
|
||||
|
||||
for task_id in expired_tasks:
|
||||
del task_registry[task_id]
|
||||
logging.info(f"已清理过期任务记录: {task_id}")
|
||||
|
||||
def start_cleanup_thread():
|
||||
def cleanup_loop():
|
||||
|
||||
Reference in New Issue
Block a user