Prepare btcprice for Kubernetes deployment

This commit is contained in:
2026-09-15 17:12:25 +02:00
parent dda00da77a
commit 573eba2d86
8 changed files with 619 additions and 11 deletions
+23 -1
View File
@@ -12,7 +12,9 @@ from fastapi.staticfiles import StaticFiles
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("btcprice")
BTCDATA_URL = os.environ.get("BTCDATA_URL", "http://localhost:4100")
BTCDATA_URL = os.environ.get("BTCDATA_URL", "http://localhost:4100").rstrip("/")
APP_VERSION = os.environ.get("APP_VERSION", "development")
READINESS_TIMEOUT_SECONDS = 3.0
app = FastAPI()
@@ -133,6 +135,26 @@ async def health():
return {"status": "up"}
@app.get("/api/ready")
async def ready():
"""Report readiness only while the btcdata dependency is healthy."""
url = f"{BTCDATA_URL}/api/health"
try:
async with httpx.AsyncClient() as client:
response = await client.get(url, timeout=READINESS_TIMEOUT_SECONDS)
response.raise_for_status()
except httpx.HTTPError:
logger.warning("btcdata readiness check failed for %s", url)
return JSONResponse(content={"status": "not ready"}, status_code=503)
return {"status": "ready"}
@app.get("/api/version")
async def version():
return {"version": APP_VERSION}
async def _proxy_btcdata_json(path: str) -> JSONResponse:
url = f"{BTCDATA_URL}{path}"
try: