Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/adapter/bio_samples_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
43 changes: 28 additions & 15 deletions src/middleware/cache_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand Down
10 changes: 4 additions & 6 deletions src/orchestrator/execution_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)