mirror of
https://git.datalinker.icu/ltdrdata/ComfyUI-Manager
synced 2025-12-15 09:04:52 +08:00
cleanup records older than 16 days
This commit is contained in:
parent
35d98dcea8
commit
a66f86d4af
@ -21,7 +21,7 @@ import traceback
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
import uuid
|
import uuid
|
||||||
import zipfile
|
import zipfile
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
import folder_paths
|
import folder_paths
|
||||||
@ -191,6 +191,7 @@ class TaskQueue:
|
|||||||
self.batch_start_time = None
|
self.batch_start_time = None
|
||||||
self.batch_state_before = None
|
self.batch_state_before = None
|
||||||
self._worker_task = None
|
self._worker_task = None
|
||||||
|
self._cleanup_performed = False
|
||||||
|
|
||||||
def is_processing(self) -> bool:
|
def is_processing(self) -> bool:
|
||||||
"""Check if the queue is currently processing tasks"""
|
"""Check if the queue is currently processing tasks"""
|
||||||
@ -546,6 +547,11 @@ class TaskQueue:
|
|||||||
self.batch_start_time = None
|
self.batch_start_time = None
|
||||||
self.batch_state_before = None
|
self.batch_state_before = None
|
||||||
|
|
||||||
|
# Cleanup old batch files once per session
|
||||||
|
if not self._cleanup_performed:
|
||||||
|
self._cleanup_old_batches()
|
||||||
|
self._cleanup_performed = True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"[ComfyUI-Manager] Failed to save batch history: {e}")
|
logging.error(f"[ComfyUI-Manager] Failed to save batch history: {e}")
|
||||||
|
|
||||||
@ -773,6 +779,39 @@ class TaskQueue:
|
|||||||
|
|
||||||
return operations
|
return operations
|
||||||
|
|
||||||
|
def _cleanup_old_batches(self) -> None:
|
||||||
|
"""Clean up batch history files older than 90 days.
|
||||||
|
|
||||||
|
This is a best-effort cleanup that silently ignores any errors
|
||||||
|
to avoid disrupting normal operations.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
cutoff = datetime.now() - timedelta(days=16)
|
||||||
|
cutoff_timestamp = cutoff.timestamp()
|
||||||
|
|
||||||
|
pattern = os.path.join(context.manager_batch_history_path, "batch_*.json")
|
||||||
|
removed_count = 0
|
||||||
|
|
||||||
|
import glob
|
||||||
|
|
||||||
|
for file_path in glob.glob(pattern):
|
||||||
|
try:
|
||||||
|
if os.path.getmtime(file_path) < cutoff_timestamp:
|
||||||
|
os.remove(file_path)
|
||||||
|
removed_count += 1
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if removed_count > 0:
|
||||||
|
logging.debug(
|
||||||
|
"[ComfyUI-Manager] Cleaned up %d old batch history files",
|
||||||
|
removed_count,
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
# Silently ignore all errors - this is non-critical functionality
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
task_queue = TaskQueue()
|
task_queue = TaskQueue()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user