-
Notifications
You must be signed in to change notification settings - Fork 0
Background task db logging #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lpi-tn
wants to merge
18
commits into
main
Choose a base branch
from
background-task-db-logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7426844
feat(search): add lru_cache to qdrant client and get_model
sandragjacinto 6f5044c
feat: customize uvicorn command
Nastaliss a41032b
thread and cache
sandragjacinto 32cc49d
wip
sandragjacinto 331c38d
add async
sandragjacinto 57fbc9b
wip
sandragjacinto c86df69
make sure model is downloade once
sandragjacinto 243c82c
make sure model is downloade once
sandragjacinto 0054baa
Merge remote-tracking branch 'origin/cache_model' into cache_model
lpi-tn 2db7e47
feat(search): add lru_cache to qdrant client and get_model
sandragjacinto d9bab09
feat: customize uvicorn command
Nastaliss 269f162
thread and cache
sandragjacinto d9733c2
wip
sandragjacinto 4ed5856
add async
sandragjacinto 3b38fc0
wip
sandragjacinto 26b064c
make sure model is downloade once
sandragjacinto bb65607
feat: implement background logging for endpoint registration
lpi-tn 88ea88e
Merge branch 'cache_model' into background-task-db-logging
lpi-tn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,20 @@ | ||
| # src/app/core/lifespan.py | ||
|
|
||
| from contextlib import asynccontextmanager | ||
|
|
||
| from fastapi import FastAPI | ||
| from qdrant_client import AsyncQdrantClient | ||
|
|
||
| from src.app.services.search import close_qdrant, init_qdrant | ||
| from src.app.api.dependencies import get_settings | ||
|
|
||
|
|
||
| @asynccontextmanager | ||
| async def lifespan(app: FastAPI): | ||
| await init_qdrant() | ||
| settings = get_settings() | ||
| app.state.qdrant = AsyncQdrantClient( | ||
| url=settings.QDRANT_HOST, | ||
| port=settings.QDRANT_PORT, | ||
| timeout=100, | ||
| ) | ||
| yield | ||
| await close_qdrant() | ||
| await app.state.qdrant.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| from fastapi import Request | ||
| from fastapi.concurrency import run_in_threadpool | ||
| from starlette.background import BackgroundTask | ||
| from starlette.middleware.base import BaseHTTPMiddleware | ||
|
|
||
| from src.app.services.sql_service import register_endpoint | ||
|
|
@@ -11,18 +12,16 @@ | |
| class MonitorRequestsMiddleware(BaseHTTPMiddleware): | ||
| async def dispatch(self, request: Request, call_next): | ||
| session_id = request.headers.get("X-Session-ID") | ||
| response = await call_next(request) | ||
|
|
||
| if session_id and request.url.path.startswith("/api/v1/"): | ||
| try: | ||
| await run_in_threadpool( | ||
| register_endpoint, | ||
| endpoint=request.url.path, | ||
| session_id=session_id, | ||
| http_code=200, | ||
| response.background = BackgroundTask( | ||
| register_endpoint, request.url.path, session_id, 200 | ||
| ) | ||
| except Exception as e: | ||
| logger.error(f"Failed to register endpoint {request.url.path}: {e}") | ||
|
Comment on lines
22
to
23
|
||
| else: | ||
| logger.warning(f"No X-Session-ID header provided for {request.url.path}") | ||
|
|
||
| response = await call_next(request) | ||
| return response | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HTTP status code is hardcoded to 200, but
response.status_codeshould be used instead to accurately log the actual response status (e.g., 404, 500). Replace200withresponse.status_code.