WIP next tracks planing
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user