Update app/control/account/runtime.py
Browse files- app/control/account/runtime.py +26 -13
app/control/account/runtime.py
CHANGED
|
@@ -5,8 +5,12 @@ callers import ``app.main``. Admin handlers use them to reconcile strategy and
|
|
| 5 |
scheduler state after hot config updates.
|
| 6 |
"""
|
| 7 |
|
|
|
|
|
|
|
| 8 |
from typing import TYPE_CHECKING, Literal
|
| 9 |
|
|
|
|
|
|
|
| 10 |
if TYPE_CHECKING:
|
| 11 |
from .refresh import AccountRefreshService
|
| 12 |
from .scheduler import AccountRefreshScheduler
|
|
@@ -91,18 +95,9 @@ def reconcile_refresh_runtime(
|
|
| 91 |
return target_strategy
|
| 92 |
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
"get_refresh_scheduler",
|
| 98 |
-
"set_refresh_scheduler",
|
| 99 |
-
"is_refresh_scheduler_leader",
|
| 100 |
-
"set_refresh_scheduler_leader",
|
| 101 |
-
"reconcile_refresh_runtime",
|
| 102 |
-
]
|
| 103 |
-
import threading
|
| 104 |
-
from collections import deque
|
| 105 |
-
from app.control.account.models import AuditLogRecord, QuotaDistributionSummary
|
| 106 |
|
| 107 |
class InMemoryAuditor:
|
| 108 |
def __init__(self, max_logs: int = 2000):
|
|
@@ -150,5 +145,23 @@ class InMemoryAuditor:
|
|
| 150 |
top_user_agents=top_uas
|
| 151 |
)
|
| 152 |
|
|
|
|
| 153 |
# 全局单例,供路由层和数据面公用
|
| 154 |
-
global_auditor = InMemoryAuditor(max_logs=2000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
scheduler state after hot config updates.
|
| 6 |
"""
|
| 7 |
|
| 8 |
+
import threading
|
| 9 |
+
from collections import deque
|
| 10 |
from typing import TYPE_CHECKING, Literal
|
| 11 |
|
| 12 |
+
from app.control.account.models import AuditLogRecord, QuotaDistributionSummary
|
| 13 |
+
|
| 14 |
if TYPE_CHECKING:
|
| 15 |
from .refresh import AccountRefreshService
|
| 16 |
from .scheduler import AccountRefreshScheduler
|
|
|
|
| 95 |
return target_strategy
|
| 96 |
|
| 97 |
|
| 98 |
+
# ---------------------------------------------------------------------------
|
| 99 |
+
# In-Memory Auditor (Rolling queue to protect TiDB Serverless free quota)
|
| 100 |
+
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
class InMemoryAuditor:
|
| 103 |
def __init__(self, max_logs: int = 2000):
|
|
|
|
| 145 |
top_user_agents=top_uas
|
| 146 |
)
|
| 147 |
|
| 148 |
+
|
| 149 |
# 全局单例,供路由层和数据面公用
|
| 150 |
+
global_auditor = InMemoryAuditor(max_logs=2000)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
# ---------------------------------------------------------------------------
|
| 154 |
+
# Module Exports (Placed at the bottom)
|
| 155 |
+
# ---------------------------------------------------------------------------
|
| 156 |
+
|
| 157 |
+
__all__ = [
|
| 158 |
+
"get_refresh_service",
|
| 159 |
+
"set_refresh_service",
|
| 160 |
+
"get_refresh_scheduler",
|
| 161 |
+
"set_refresh_scheduler",
|
| 162 |
+
"is_refresh_scheduler_leader",
|
| 163 |
+
"set_refresh_scheduler_leader",
|
| 164 |
+
"reconcile_refresh_runtime",
|
| 165 |
+
"InMemoryAuditor",
|
| 166 |
+
"global_auditor",
|
| 167 |
+
]
|