From cbd46adaa678b51bd098a70031f8a7959084e951 Mon Sep 17 00:00:00 2001 From: Tomas Kracmar Date: Wed, 22 Apr 2026 10:08:32 +0200 Subject: [PATCH] style: ruff format --- backend/jobs.py | 6 +++++- backend/routes/ask.py | 14 +++++++++++--- backend/tests/conftest.py | 1 + backend/tests/test_api.py | 1 + backend/tests/test_ask.py | 11 ++++++++++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/backend/jobs.py b/backend/jobs.py index 19c2ee6..b84d9c0 100644 --- a/backend/jobs.py +++ b/backend/jobs.py @@ -56,7 +56,10 @@ async def set_cached_explain(redis, event_id: str, result: dict): # arq job functions # --------------------------------------------------------------------------- -async def process_ask_question(ctx, question: str, filters: dict, events: list, total: int, excluded_services: list | None): + +async def process_ask_question( + ctx, question: str, filters: dict, events: list, total: int, excluded_services: list | None +): """Background job: call LLM for /api/ask and cache result.""" from routes.ask import _call_llm @@ -92,6 +95,7 @@ async def process_explain_event(ctx, event_id: str, event: dict, related: list): # arq worker configuration # --------------------------------------------------------------------------- + async def startup(ctx): from redis.asyncio import Redis diff --git a/backend/routes/ask.py b/backend/routes/ask.py index 591ef20..7ef3bc9 100644 --- a/backend/routes/ask.py +++ b/backend/routes/ask.py @@ -813,9 +813,17 @@ async def ask_question(body: AskRequest, user: dict = Depends(require_auth)): try: answer = await _call_llm(question, events, total=total, excluded_services=excluded_services) llm_used = True - await set_cached_ask(redis, question, filters_snapshot, events, { - "answer": answer, "llm_used": True, "llm_error": None, - }) + await set_cached_ask( + redis, + question, + filters_snapshot, + events, + { + "answer": answer, + "llm_used": True, + "llm_error": None, + }, + ) except Exception as exc: llm_error = f"LLM call failed: {exc}" logger.warning("LLM call failed, falling back to structured summary", error=str(exc)) diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index 8711fe8..c726436 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -53,6 +53,7 @@ def client(mock_events_collection, mock_watermarks_collection, monkeypatch): class FakeRedis: async def get(self, key): return None + async def setex(self, key, ttl, value): pass diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index 02d4e44..92b368e 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -92,6 +92,7 @@ def test_explain_event_with_llm_mock(client, mock_events_collection, monkeypatch class FakeRedis: async def get(self, key): return None + async def setex(self, key, ttl, value): pass diff --git a/backend/tests/test_ask.py b/backend/tests/test_ask.py index 6b0191d..b246ba8 100644 --- a/backend/tests/test_ask.py +++ b/backend/tests/test_ask.py @@ -405,7 +405,15 @@ class TestAskCaching: "include_tags": None, "exclude_tags": None, } - asyncio.run(set_cached_ask(redis, "What happened to USER-001?", filters_snapshot, [{"id": "evt-cache"}], {"answer": "Cached answer!", "llm_used": True, "llm_error": None})) + asyncio.run( + set_cached_ask( + redis, + "What happened to USER-001?", + filters_snapshot, + [{"id": "evt-cache"}], + {"answer": "Cached answer!", "llm_used": True, "llm_error": None}, + ) + ) async def fake_get_arq_pool(): return redis @@ -451,6 +459,7 @@ class TestAskCaching: async def enqueue_job(self, func, *args, **kwargs): from unittest.mock import MagicMock + job = MagicMock() job.job_id = "job-12345" self.enqueued.append((func, args, kwargs))