fix: clean Redis URL by removing query parameters in cache client and update flush mode logging in benchmark runner

This commit is contained in:
Benjamin McCormick 2026-01-23 17:57:58 -05:00
parent 258fd3736b
commit 6c3f671636
2 changed files with 11 additions and 6 deletions

8
src/cache/client.py vendored
View File

@ -3,7 +3,9 @@ from __future__ import annotations
import asyncio
import logging
from typing import cast
from urllib.parse import urlparse, urlunparse
import redis.asyncio as aioredis
import sentry_sdk
from cashews import cache
from cashews.picklers import PicklerType
@ -126,9 +128,11 @@ async def is_deriver_flush_enabled() -> bool:
if not is_cache_enabled():
return False
try:
import redis.asyncio as aioredis
# Strip query parameters - redis-py doesn't support custom params like ?suppress=true
parsed = urlparse(settings.CACHE.URL)
clean_url = urlunparse(parsed._replace(query=""))
redis_client = aioredis.from_url(settings.CACHE.URL) # pyright: ignore[reportUnknownMemberType]
redis_client = aioredis.from_url(clean_url) # pyright: ignore[reportUnknownMemberType]
try:
result = await redis_client.get(DERIVER_FLUSH_KEY)
return result == b"1"

View File

@ -623,13 +623,14 @@ class BaseRunner(ABC, Generic[ResultT]):
async def _flush_deriver_queue(self) -> None:
"""Enable deriver flush mode to bypass batch token threshold."""
if self.config.base_url:
print("Skipping flush mode (remote instance)")
default_redis_url = "redis://localhost:6379/0"
if self.config.base_url and self.config.redis_url == default_redis_url:
print("Skipping flush mode (remote instance, no --redis-url provided)")
return
redis_client: Redis = aioredis.from_url(self.config.redis_url) # pyright: ignore[reportUnknownMemberType]
try:
await redis_client.set("honcho:deriver:flush_mode", "1", ex=60)
print("Enabled deriver flush mode")
await redis_client.set("honcho:deriver:flush_mode", "1", ex=3600)
print(f"Enabled deriver flush mode via {self.config.redis_url}")
finally:
await redis_client.aclose()