fixed injection watcher

This commit is contained in:
2026-06-11 07:18:19 +03:00
parent 827f9016cd
commit 06e09cd728
7 changed files with 93 additions and 84 deletions
+22 -1
View File
@@ -4,6 +4,8 @@ import random
from datetime import datetime
from zoneinfo import ZoneInfo
import httpx
from app.config import get_settings
from app.db.base import SessionLocal
from app.homelab.comfyui import ComfyUIClient
@@ -76,6 +78,15 @@ async def _tick_netdata() -> None:
db.close()
async def _comfyui_reachable(base_url: str) -> bool:
try:
async with httpx.AsyncClient(timeout=httpx.Timeout(3.0, connect=2.0)) as client:
response = await client.get(f"{base_url.rstrip('/')}/system_stats")
return response.status_code < 500
except (httpx.TimeoutException, httpx.ConnectError, httpx.NetworkError):
return False
async def _tick_rofl() -> None:
settings = get_settings()
if not settings.comfyui_enabled or not settings.comfyui_rofl_enabled:
@@ -114,8 +125,18 @@ async def _tick_rofl() -> None:
return
client = ComfyUIClient()
if not await _comfyui_reachable(client.base_url):
return
prompt = client.random_rofl_prompt()
result = await client.generate_image(prompt)
try:
result = await asyncio.wait_for(
client.generate_image(prompt),
timeout=settings.comfyui_timeout_sec + 15,
)
except (asyncio.TimeoutError, httpx.TimeoutException, httpx.ConnectError) as exc:
logger.warning("Rofl image skipped (ComfyUI): %s", exc)
return
if not result.get("ok"):
logger.warning("Rofl image failed: %s", result.get("error"))
return