Add scheduled cleanup for rate limiter (#32)
Implement periodic cleanup of expired rate-limiter entries to prevent unbounded memory growth during long runtimes. Changes: - Create rate_limiter_cleanup task that calls cleanup_expired() every 30 minutes - Register the task in the startup DAG alongside other background jobs - Update rate_limiter module documentation with operational notes about the cleanup lifecycle and memory management strategy The cleanup is conservative and only removes IPs with no recent attempts (all timestamps outside the rate-limit window), so active IPs are preserved. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -41,6 +41,7 @@ from app.tasks import (
|
||||
geo_re_resolve,
|
||||
health_check,
|
||||
history_sync,
|
||||
rate_limiter_cleanup,
|
||||
session_cleanup,
|
||||
)
|
||||
from app.utils.async_utils import run_blocking
|
||||
@@ -395,6 +396,7 @@ async def _stage_register_tasks(app: FastAPI, scheduler: AsyncIOScheduler) -> No
|
||||
- geo_re_resolve: Periodic re-resolution of stale records
|
||||
- history_sync: Periodic synchronization of ban history
|
||||
- session_cleanup: Periodic cleanup of expired sessions
|
||||
- rate_limiter_cleanup: Periodic cleanup of expired rate-limiter entries
|
||||
|
||||
Args:
|
||||
app: The FastAPI application instance.
|
||||
@@ -407,5 +409,6 @@ async def _stage_register_tasks(app: FastAPI, scheduler: AsyncIOScheduler) -> No
|
||||
geo_re_resolve.register(app)
|
||||
history_sync.register(app)
|
||||
session_cleanup.register(app)
|
||||
rate_limiter_cleanup.register(app)
|
||||
|
||||
log.info("startup_tasks_registered", count=7)
|
||||
log.info("startup_tasks_registered", count=8)
|
||||
|
||||
Reference in New Issue
Block a user