WIP: PAIN
This commit is contained in:
@@ -21,17 +21,17 @@ class LogPruner:
|
||||
self.log_registry = log_registry
|
||||
self.logs_dir = logs_dir
|
||||
|
||||
def prune(self) -> None:
|
||||
def prune(self, max_age_days: int = 1) -> 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 24 hours (based on data from LogRegistry).
|
||||
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).
|
||||
"""
|
||||
now = datetime.now()
|
||||
cutoff_time = now - timedelta(hours=24)
|
||||
cutoff_time = now - timedelta(days=max_age_days)
|
||||
# Ensure the base logs directory exists.
|
||||
if not os.path.isdir(self.logs_dir):
|
||||
return
|
||||
@@ -39,7 +39,7 @@ class LogPruner:
|
||||
old_sessions_to_check = self.log_registry.get_old_non_whitelisted_sessions(cutoff_time)
|
||||
# Prune sessions if their size is less than 2048 bytes
|
||||
for session_info in old_sessions_to_check:
|
||||
session_info['session_id']
|
||||
session_id = session_info['session_id']
|
||||
session_path = session_info['path']
|
||||
if not session_path or not os.path.isdir(session_path):
|
||||
continue
|
||||
@@ -55,6 +55,9 @@ class LogPruner:
|
||||
if total_size < 2048: # 2KB
|
||||
try:
|
||||
shutil.rmtree(session_path)
|
||||
# print(f"Pruned session '{session_id}' (Size: {total_size} bytes)")
|
||||
# Also remove from registry to keep it in sync
|
||||
if session_id in self.log_registry.data:
|
||||
del self.log_registry.data[session_id]
|
||||
except OSError:
|
||||
pass
|
||||
self.log_registry.save_registry()
|
||||
|
||||
Reference in New Issue
Block a user