WIP next tracks planing

This commit is contained in:
2026-03-06 14:52:10 -05:00
parent 3336959e02
commit 2c90020682
28 changed files with 482 additions and 540 deletions

View File

@@ -664,9 +664,25 @@ class AppController:
self._set_status(f"viewing prior session: {Path(path).name} ({len(entries)} entries)")
def cb_prune_logs(self) -> None:
"""Manually triggers the log pruning process."""
self._set_status("Pruning logs...")
self._prune_old_logs()
"""Manually triggers the log pruning process with aggressive thresholds."""
self._set_status("Manual prune started (Age > 0d, Size < 100KB)...")
def run_manual_prune() -> None:
try:
from src import log_registry
from src import log_pruner
registry = log_registry.LogRegistry("logs/sessions/log_registry.toml")
pruner = log_pruner.LogPruner(registry, "logs/sessions")
# Aggressive: Prune anything not whitelisted, even if just created, if under 100KB
# Note: max_age_days=0 means cutoff is NOW.
pruner.prune(max_age_days=0, min_size_kb=100)
self._set_status("Manual prune complete.")
except Exception as e:
self._set_status(f"Manual prune error: {e}")
print(f"Error during manual log pruning: {e}")
thread = threading.Thread(target=run_manual_prune, daemon=True)
thread.start()
def _load_active_project(self) -> None:
"""Loads the active project configuration, with fallbacks."""

View File

@@ -21,14 +21,14 @@ class LogPruner:
self.log_registry = log_registry
self.logs_dir = logs_dir
def prune(self, max_age_days: int = 1) -> None:
def prune(self, max_age_days: int = 1, min_size_kb: int = 2) -> None:
"""
Prunes old and small session directories from the logs directory.
Deletes session directories that meet the following criteria:
1. The session start time is older than max_age_days.
2. The session name is NOT in the whitelist provided by the LogRegistry.
3. The total size of all files within the session directory is less than 2KB (2048 bytes).
3. The total size of all files within the session directory is less than min_size_kb.
"""
now = datetime.now()
cutoff_time = now - timedelta(days=max_age_days)
@@ -37,7 +37,7 @@ class LogPruner:
return
# Get sessions that are old and not whitelisted from the registry
old_sessions_to_check = self.log_registry.get_old_non_whitelisted_sessions(cutoff_time)
# Prune sessions if their size is less than 2048 bytes
# Prune sessions if their size is less than threshold
for session_info in old_sessions_to_check:
session_id = session_info['session_id']
session_path = session_info['path']
@@ -51,8 +51,8 @@ class LogPruner:
total_size += entry.stat().st_size
except OSError:
continue
# Prune if the total size is less than 2KB (2048 bytes)
if total_size < 2048: # 2KB
# Prune if the total size is less than threshold
if total_size < (min_size_kb * 1024):
try:
shutil.rmtree(session_path)
# Also remove from registry to keep it in sync