MCPcopy Index your code
hub / github.com/vastsa/FileCodeBox / clean_incomplete_uploads

Function clean_incomplete_uploads

core/tasks.py:50–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48
49
50async def clean_incomplete_uploads():
51 while True:
52 try:
53 await refresh_settings()
54 file_storage: FileStorageInterface = storages[settings.file_storage]()
55 expire_hours = getattr(settings, "chunk_expire_hours", 24)
56 now = await get_now()
57 expire_time = now - datetime.timedelta(hours=expire_hours)
58 expired_sessions = await UploadChunk.filter(
59 chunk_index=-1, created_at__lt=expire_time
60 ).all()
61
62 for session in expired_sessions:
63 try:
64 save_path = session.save_path
65 if not save_path:
66 _, _, _, _, save_path = await get_chunk_file_path_name(
67 session.file_name, session.upload_id
68 )
69 await file_storage.clean_chunks(session.upload_id, save_path)
70 except Exception as e:
71 logging.error(
72 f"清理分片文件失败 upload_id={session.upload_id}: {e}"
73 )
74
75 try:
76 await UploadChunk.filter(upload_id=session.upload_id).delete()
77 logging.info(f"已清理过期上传会话 upload_id={session.upload_id}")
78 except Exception as e:
79 logging.error(
80 f"删除分片记录失败 upload_id={session.upload_id}: {e}"
81 )
82
83 except Exception as e:
84 logging.error(f"清理未完成上传任务异常: {e}")
85 finally:
86 await asyncio.sleep(3600)

Callers 1

lifespanFunction · 0.90

Calls 6

refresh_settingsFunction · 0.90
get_nowFunction · 0.90
get_chunk_file_path_nameFunction · 0.90
deleteMethod · 0.80
filterMethod · 0.45
clean_chunksMethod · 0.45

Tested by

no test coverage detected