Skip to content

Commit d2cb7c5

Browse files
author
Paweł Kędzia
committed
Add _print_provider_status helper method to log Redis provider lock status for debugging.
1 parent aceb6ba commit d2cb7c5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

llm_router_api/base/lb/first_available.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ def get_provider(
181181
for p in providers:
182182
self.redis_client.hset(redis_key, self._provider_field(p), "false")
183183

184+
# self._print_provider_status(redis_key, providers)
185+
184186
is_random = options and options.get("random_choice", False)
185187

186188
while True:
@@ -431,3 +433,31 @@ def _clear_buffers(self) -> None:
431433
self._initialize_providers(
432434
model_name=model_name, providers=providers
433435
)
436+
437+
def _print_provider_status(self, redis_key: str, providers: List[Dict]) -> None:
438+
"""
439+
Print the lock status of each provider stored in the Redis hash
440+
``redis_key``. Uses emojis for a quick visual cue:
441+
442+
* 🟢 – provider is free (`'false'` or missing)
443+
* 🔴 – provider is currently taken (`'true'`)
444+
445+
The output is formatted in a table‑like layout for readability.
446+
"""
447+
try:
448+
# Retrieve the entire hash; missing fields default to None
449+
hash_data = self.redis_client.hgetall(redis_key)
450+
except Exception as exc:
451+
print(f"[⚠️] Could not read Redis key '{redis_key}': {exc}")
452+
return
453+
454+
print("\nProvider lock status:")
455+
print("-" * 40)
456+
for provider in providers:
457+
field = self._provider_field(provider)
458+
status = hash_data.get(field, "false")
459+
icon = "🔴" if status == "true" else "🟢"
460+
# Show a short identifier for the provider (fallback to field)
461+
provider_id = provider.get("id") or provider.get("name") or field
462+
print(f"{icon} {provider_id:<30} [{field}]")
463+
print("-" * 40)

0 commit comments

Comments
 (0)