Răsfoiți Sursa

refactor: enhance debug logging in quota synchronization process

Manuel 8 luni în urmă
părinte
comite
30d30b306e
1 a modificat fișierele cu 18 adăugiri și 6 ștergeri
  1. 18 6
      services/quota/quota_scheduler.py

+ 18 - 6
services/quota/quota_scheduler.py

@@ -90,7 +90,9 @@ def _sync_quota_squid_rules(enabled: bool):
         return
 
     blocked_path = "/etc/squid/usuarios_bloqueados.txt"
-    print(f"[DEBUG] _sync_quota_squid_rules: blocked_path={blocked_path}, enabled={enabled}")
+    print(
+        f"[DEBUG] _sync_quota_squid_rules: blocked_path={blocked_path}, enabled={enabled}"
+    )
     _ensure_blocked_file(blocked_path)
 
     def _normalize_line(line: str) -> str:
@@ -150,7 +152,9 @@ def _sync_quota_squid_rules(enabled: bool):
                 if enabled:
                     if not any(_matches_acl_entry(line) for line in acl_lines):
                         if use_src:
-                            print(f"[DEBUG] _apply_changes: modo src detectado, insertar include {acl_line}")
+                            print(
+                                f"[DEBUG] _apply_changes: modo src detectado, insertar include {acl_line}"
+                            )
                             # include va al principio del bloque
                             acl_lines.insert(0, acl_line)
                         else:
@@ -181,7 +185,9 @@ def _sync_quota_squid_rules(enabled: bool):
 
                 if enabled:
                     if not any(_is_http_line(line) for line in http_lines):
-                        print("[DEBUG] _apply_changes: insertando http_access deny usuarios_bloqueados")
+                        print(
+                            "[DEBUG] _apply_changes: insertando http_access deny usuarios_bloqueados"
+                        )
                         inserted = False
                         for i, line in enumerate(http_lines):
                             if line.strip().startswith("http_access "):
@@ -480,16 +486,22 @@ def register_quota_scheduler_tasks(scheduler):
                     new_blocked.append(user)
 
             if new_blocked:
-                print(f"[DEBUG] check_quota_users: {len(new_blocked)} nuevos bloqueos; use_src={use_src}")
+                print(
+                    f"[DEBUG] check_quota_users: {len(new_blocked)} nuevos bloqueos; use_src={use_src}"
+                )
                 with open(file_path, "a", encoding="utf-8") as f:
                     for user in new_blocked:
                         if use_src:
                             line = f"acl usuarios_bloqueados src {user.username}\n"
-                            print(f"[DEBUG] appending to blocked file (src): {line.strip()}")
+                            print(
+                                f"[DEBUG] appending to blocked file (src): {line.strip()}"
+                            )
                             f.write(line)
                         else:
                             line = f"{user.username}\n"
-                            print(f"[DEBUG] appending to blocked file (proxy_auth): {line.strip()}")
+                            print(
+                                f"[DEBUG] appending to blocked file (proxy_auth): {line.strip()}"
+                            )
                             f.write(line)
                 _sync_blocked_file_to_docker(file_path)