style: add units to variable names, name busy_timeout constant
- core.py: rename RATE_LIMIT_WINDOW → RATE_LIMIT_WINDOW_SECONDS (env var name RATE_LIMIT_WINDOW is unchanged — only the Python attribute) - core.py: extract _BUSY_TIMEOUT_MS = 5000 local constant so the PRAGMA value is no longer a bare magic number - worker.py: rename poll_interval → poll_interval_seconds Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -77,7 +77,7 @@ class Config:
|
||||
WAITLIST_MODE: bool = os.getenv("WAITLIST_MODE", "false").lower() == "true"
|
||||
|
||||
RATE_LIMIT_REQUESTS: int = int(os.getenv("RATE_LIMIT_REQUESTS", "100"))
|
||||
RATE_LIMIT_WINDOW: int = int(os.getenv("RATE_LIMIT_WINDOW", "60"))
|
||||
RATE_LIMIT_WINDOW_SECONDS: int = int(os.getenv("RATE_LIMIT_WINDOW", "60"))
|
||||
|
||||
PLAN_FEATURES: dict = {
|
||||
"free": ["basic"],
|
||||
@@ -149,7 +149,8 @@ async def init_db(path: str = None) -> None:
|
||||
|
||||
await _db.execute("PRAGMA journal_mode=WAL")
|
||||
await _db.execute("PRAGMA foreign_keys=ON")
|
||||
await _db.execute("PRAGMA busy_timeout=5000")
|
||||
_BUSY_TIMEOUT_MS = 5000
|
||||
await _db.execute(f"PRAGMA busy_timeout={_BUSY_TIMEOUT_MS}")
|
||||
await _db.execute("PRAGMA synchronous=NORMAL")
|
||||
await _db.execute("PRAGMA cache_size=-64000")
|
||||
await _db.execute("PRAGMA temp_store=MEMORY")
|
||||
@@ -573,7 +574,7 @@ async def check_rate_limit(key: str, limit: int = None, window: int = None) -> t
|
||||
Uses SQLite for storage - no Redis needed.
|
||||
"""
|
||||
limit = limit or config.RATE_LIMIT_REQUESTS
|
||||
window = window or config.RATE_LIMIT_WINDOW
|
||||
window = window or config.RATE_LIMIT_WINDOW_SECONDS
|
||||
now = utcnow()
|
||||
window_start = now - timedelta(seconds=window)
|
||||
|
||||
|
||||
@@ -786,7 +786,7 @@ async def process_task(task: dict) -> None:
|
||||
logger.error("Failed: %s (id=%s): %s", task_name, task_id, e)
|
||||
|
||||
|
||||
async def run_worker(poll_interval: float = 1.0) -> None:
|
||||
async def run_worker(poll_interval_seconds: float = 1.0) -> None:
|
||||
"""Main worker loop."""
|
||||
setup_logging()
|
||||
logger.info("Starting...")
|
||||
@@ -803,11 +803,11 @@ async def run_worker(poll_interval: float = 1.0) -> None:
|
||||
await process_task(task)
|
||||
|
||||
if not tasks:
|
||||
await asyncio.sleep(poll_interval)
|
||||
await asyncio.sleep(poll_interval_seconds)
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Error: %s", e)
|
||||
await asyncio.sleep(poll_interval * 5)
|
||||
await asyncio.sleep(poll_interval_seconds * 5)
|
||||
|
||||
|
||||
async def run_scheduler() -> None:
|
||||
|
||||
Reference in New Issue
Block a user