mirror of
https://github.com/xpltdco/media-rip.git
synced 2026-04-03 02:53:58 -06:00
Version: - New app/__version__.py with 'dev' fallback for local dev - Dockerfile injects APP_VERSION build arg from CI tag - Health endpoint and footer now show actual release version - Test updated to accept 'dev' in non-Docker environments File size: - Capture filesize/filesize_approx from yt-dlp extract_info - Write to DB via update_job_progress and broadcast via SSE - New 'Size' column in download table (hidden on mobile) - formatSize helper: bytes → human-readable (KB/MB/GB) - Frontend store picks up filesize from SSE events
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
"""Health endpoint for monitoring tools and Docker healthchecks."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from datetime import datetime, timezone
|
|
|
|
from fastapi import APIRouter, Request
|
|
|
|
from app.core.database import get_queue_depth
|
|
|
|
logger = logging.getLogger("mediarip.health")
|
|
|
|
router = APIRouter(tags=["health"])
|
|
|
|
# yt-dlp version — resolved once at import time.
|
|
# Wrapped in try/except so tests that don't install yt-dlp still work.
|
|
try:
|
|
from yt_dlp.version import __version__ as _yt_dlp_version
|
|
except ImportError: # pragma: no cover
|
|
_yt_dlp_version = "unknown"
|
|
|
|
try:
|
|
from app.__version__ import __version__ as _APP_VERSION
|
|
except ImportError: # pragma: no cover
|
|
_APP_VERSION = "dev"
|
|
|
|
|
|
@router.get("/health")
|
|
async def health(request: Request) -> dict:
|
|
"""Return service health status, versions, uptime, and queue depth.
|
|
|
|
Intended consumers: Uptime Kuma, Docker HEALTHCHECK, load balancer probes.
|
|
"""
|
|
db = request.app.state.db
|
|
start_time: datetime = request.app.state.start_time
|
|
now = datetime.now(timezone.utc)
|
|
uptime = (now - start_time).total_seconds()
|
|
depth = await get_queue_depth(db)
|
|
|
|
return {
|
|
"status": "ok",
|
|
"version": _APP_VERSION,
|
|
"yt_dlp_version": _yt_dlp_version,
|
|
"uptime": uptime,
|
|
"queue_depth": depth,
|
|
}
|