Skip to content

Commit a66f86d

Browse files
cleanup records older than 16 days
1 parent 35d98dc commit a66f86d

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

comfyui_manager/glob/manager_server.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import urllib.request
2222
import uuid
2323
import zipfile
24-
from datetime import datetime
24+
from datetime import datetime, timedelta
2525
from typing import Any, Optional
2626

2727
import folder_paths
@@ -191,6 +191,7 @@ def __init__(self):
191191
self.batch_start_time = None
192192
self.batch_state_before = None
193193
self._worker_task = None
194+
self._cleanup_performed = False
194195

195196
def is_processing(self) -> bool:
196197
"""Check if the queue is currently processing tasks"""
@@ -546,6 +547,11 @@ def finalize(self) -> None:
546547
self.batch_start_time = None
547548
self.batch_state_before = None
548549

550+
# Cleanup old batch files once per session
551+
if not self._cleanup_performed:
552+
self._cleanup_old_batches()
553+
self._cleanup_performed = True
554+
549555
except Exception as e:
550556
logging.error(f"[ComfyUI-Manager] Failed to save batch history: {e}")
551557

@@ -587,20 +593,20 @@ def _get_frontend_version(self) -> Optional[str]:
587593
# Check if front-end-root is specified (overrides version)
588594
if hasattr(args, "front_end_root") and args.front_end_root:
589595
return f"custom-root: {args.front_end_root}"
590-
596+
591597
# Check if front-end-version is specified
592598
if hasattr(args, "front_end_version") and args.front_end_version:
593599
if "@" in args.front_end_version:
594600
return args.front_end_version.split("@")[1]
595601
else:
596602
return args.front_end_version
597-
603+
598604
# Otherwise, check for installed package
599605
pip_packages = self._get_pip_packages()
600606
for package_name in ["comfyui-frontend", "comfyui_frontend"]:
601607
if package_name in pip_packages:
602608
return pip_packages[package_name]
603-
609+
604610
return None
605611
except Exception:
606612
return None
@@ -741,7 +747,7 @@ def _extract_batch_operations(self) -> list[BatchOperation]:
741747
# Only include operations from the current batch
742748
if task.batch_id != self.batch_id:
743749
continue
744-
750+
745751
result_status = OperationResult.success
746752
if task.status:
747753
status_str = (
@@ -773,6 +779,39 @@ def _extract_batch_operations(self) -> list[BatchOperation]:
773779

774780
return operations
775781

782+
def _cleanup_old_batches(self) -> None:
783+
"""Clean up batch history files older than 90 days.
784+
785+
This is a best-effort cleanup that silently ignores any errors
786+
to avoid disrupting normal operations.
787+
"""
788+
try:
789+
cutoff = datetime.now() - timedelta(days=16)
790+
cutoff_timestamp = cutoff.timestamp()
791+
792+
pattern = os.path.join(context.manager_batch_history_path, "batch_*.json")
793+
removed_count = 0
794+
795+
import glob
796+
797+
for file_path in glob.glob(pattern):
798+
try:
799+
if os.path.getmtime(file_path) < cutoff_timestamp:
800+
os.remove(file_path)
801+
removed_count += 1
802+
except Exception:
803+
pass
804+
805+
if removed_count > 0:
806+
logging.debug(
807+
"[ComfyUI-Manager] Cleaned up %d old batch history files",
808+
removed_count,
809+
)
810+
811+
except Exception:
812+
# Silently ignore all errors - this is non-critical functionality
813+
pass
814+
776815

777816
task_queue = TaskQueue()
778817

0 commit comments

Comments
 (0)