diff --git a/src/adapter/bio_samples_adapter.py b/src/adapter/bio_samples_adapter.py index dc0917d..3c0d70a 100644 --- a/src/adapter/bio_samples_adapter.py +++ b/src/adapter/bio_samples_adapter.py @@ -160,7 +160,7 @@ async def get_sample( async def submit_sample( self, submission: dict[str, Any], - auth_token:Any, + auth_token: str | None, ) -> dict[str, Any]: if not auth_token: diff --git a/src/middleware/cache_middleware.py b/src/middleware/cache_middleware.py index acbfa51..60e301e 100644 --- a/src/middleware/cache_middleware.py +++ b/src/middleware/cache_middleware.py @@ -48,24 +48,32 @@ async def process( try: cached = await self.redis.get(cache_key) - except Exception: + except Exception as error: + logger.warning( + "Redis cache read failed. Proceeding without cache.", + extra={ + "extra_fields": { + "event": "cache_read_failed", + "tool": context.tool_name, + "requestId": context.request_id, + "error": str(error), + } + }, + ) cached = None if cached: logger.info( "Cache hit", extra={ - "extra_fields": { + "extra_fields": { "event": "cache_hit", "tool": context.tool_name, - "requestId": context.request_id, + "requestId": context.request_id, } }, ) return json.loads(cached) - - cached_response = json.loads(cached) - return cached_response response = await next_handler(context) @@ -88,15 +96,20 @@ async def process( }, ) - logger.info({ - "event": "cache_miss", - "tool": context.tool_name, - "cache": { - "hit": False, - "type": "redis", - "ttlSeconds": self.ttl_seconds, - }, - }) + logger.info( + "Cache miss", + extra={ + "extra_fields": { + "event": "cache_miss", + "tool": context.tool_name, + "cache": { + "hit": False, + "type": "redis", + "ttlSeconds": self.ttl_seconds, + }, + } + }, + ) return response def _cache_key(self, context: RequestContext) -> str: diff --git a/src/orchestrator/execution_pipeline.py b/src/orchestrator/execution_pipeline.py index 70774e1..2b3fd58 100644 --- a/src/orchestrator/execution_pipeline.py +++ b/src/orchestrator/execution_pipeline.py @@ -11,17 +11,15 @@ async def execute( self, context ): - async def call_next(index): + async def call_next(index, ctx=context): if index == len(self.middlewares): - return await self.executor.execute( - context - ) + return await self.executor.execute(ctx) middleware = self.middlewares[index] return await middleware.process( - context, - lambda ctx: call_next(index + 1) + ctx, + lambda next_ctx: call_next(index + 1, next_ctx) ) return await call_next(0) \ No newline at end of file