christopher commited on
Commit ·
552befd
1
Parent(s): 64f44e3
logging fixed
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import logging
|
| 2 |
-
from fastapi import FastAPI, HTTPException, BackgroundTasks
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from typing import Dict, Optional, List, Any
|
| 6 |
import uuid
|
|
@@ -84,6 +85,46 @@ class JobStatus(BaseModel):
|
|
| 84 |
request: PostRequest
|
| 85 |
result: Optional[Dict[str, Any]] = None
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
@app.post("/index", response_model=JobStatus)
|
| 88 |
async def create_job(request: PostRequest, background_tasks: BackgroundTasks):
|
| 89 |
job_id = str(uuid.uuid4())
|
|
|
|
| 1 |
import logging
|
| 2 |
+
from fastapi import FastAPI, HTTPException, BackgroundTasks, Request
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
from fastapi.responses import JSONResponse
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from typing import Dict, Optional, List, Any
|
| 7 |
import uuid
|
|
|
|
| 85 |
request: PostRequest
|
| 86 |
result: Optional[Dict[str, Any]] = None
|
| 87 |
|
| 88 |
+
@app.get("/")
|
| 89 |
+
async def root(request: Request):
|
| 90 |
+
"""Root endpoint with API information"""
|
| 91 |
+
logger.info(f"Root access from {request.client.host}")
|
| 92 |
+
return {
|
| 93 |
+
"message": "Kairos News API is running",
|
| 94 |
+
"endpoints": {
|
| 95 |
+
"create_job": {"method": "POST", "path": "/index"},
|
| 96 |
+
"check_status": {"method": "GET", "path": "/loading"},
|
| 97 |
+
"get_logs": {"method": "GET", "path": "/logs"}
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
@app.get("/logs")
|
| 102 |
+
async def get_logs(log_type: str = None):
|
| 103 |
+
"""Endpoint for log retrieval"""
|
| 104 |
+
if log_type == "container":
|
| 105 |
+
return {"message": "Container logs endpoint", "status": "Not implemented"}
|
| 106 |
+
return {
|
| 107 |
+
"message": "Available log types: container",
|
| 108 |
+
"usage": "/logs?log_type=container"
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
@app.exception_handler(404)
|
| 112 |
+
async def not_found_exception_handler(request: Request, exc: HTTPException):
|
| 113 |
+
"""Custom 404 handler"""
|
| 114 |
+
logger.warning(f"404 Not Found: {request.url}")
|
| 115 |
+
return JSONResponse(
|
| 116 |
+
status_code=404,
|
| 117 |
+
content={
|
| 118 |
+
"message": "Endpoint not found",
|
| 119 |
+
"available_endpoints": [
|
| 120 |
+
{"path": "/", "method": "GET"},
|
| 121 |
+
{"path": "/index", "method": "POST"},
|
| 122 |
+
{"path": "/loading", "method": "GET"},
|
| 123 |
+
{"path": "/logs", "method": "GET"}
|
| 124 |
+
]
|
| 125 |
+
},
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
@app.post("/index", response_model=JobStatus)
|
| 129 |
async def create_job(request: PostRequest, background_tasks: BackgroundTasks):
|
| 130 |
job_id = str(uuid.uuid4())
|