From 4bd150e32fb3d8728cea3c1de366cce8add5e343 Mon Sep 17 00:00:00 2001 From: wwwwwwwww <526125649@qq.com> Date: Wed, 17 Jun 2026 15:51:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9C=8D=E5=8A=A1=E9=A6=96?= =?UTF-8?q?=E9=A1=B5celery=E7=9B=B8=E5=85=B3=E7=9B=91=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- video-gen-api/app/main.py | 146 +++++++++++++++++++++++++++++++++++++- 1 file changed, 145 insertions(+), 1 deletion(-) diff --git a/video-gen-api/app/main.py b/video-gen-api/app/main.py index e77caf37..5c12c3a5 100644 --- a/video-gen-api/app/main.py +++ b/video-gen-api/app/main.py @@ -560,6 +560,150 @@ def create_app() -> FastAPI: async def health(): return {"status": "ok"} + @application.get("/internal/status", response_class=HTMLResponse) + async def status_page(): + from app.tasks.celery_app import celery_app + from app.config import settings + + celery_status = "unknown" + celery_error = "" + redis_status = "unknown" + redis_error = "" + + try: + if celery_app: + inspect = celery_app.control.inspect() + try: + workers = inspect.stats() + if workers: + celery_status = "running" + else: + celery_status = "no_workers" + except Exception as e: + celery_status = "error" + celery_error = str(e) + else: + celery_status = "disabled" + except Exception as e: + celery_status = "error" + celery_error = str(e) + + try: + if settings.REDIS_URL: + import redis + r = redis.from_url(settings.REDIS_URL) + r.ping() + redis_status = "connected" + else: + redis_status = "disabled" + except Exception as e: + redis_status = "disconnected" + redis_error = str(e) + + def get_celery_text(status): + if status == 'running': + return '运行中' + elif status == 'no_workers': + return '无可用 Worker' + elif status == 'disabled': + return '已禁用' + elif status == 'error': + return '连接失败' + else: + return '未知' + + def get_redis_text(status): + if status == 'connected': + return '已连接' + elif status == 'disabled': + return '已禁用' + elif status == 'disconnected': + return '未连接' + else: + return '未知' + + celery_text = get_celery_text(celery_status) + redis_text = get_redis_text(redis_status) + + celery_error_html = f'
错误: {celery_error}
' if celery_error else '' + redis_error_html = f'
错误: {redis_error}
' if redis_error else '' + + html_content = f""" + + + + 服务状态监控 + + + +

服务状态.

+

版本 v{settings.APP_VERSION}

+ +
+

Celery 任务队列

+
+
+ {celery_text} +
+ {celery_error_html} +
+ 说明: Celery 用于异步处理 AI 生成任务、轮询任务和下载任务。如果显示"无可用 Worker",请启动 Celery worker。 +
+
+ +
+

Redis 缓存

+
+
+ {redis_text} +
+ {redis_error_html} +
+ 说明: Redis 用于 Celery 消息队列、任务状态存储和缓存。 +
+
+ +
+

数据库连接

+
+
+ 已连接 +
+
+ 说明: PostgreSQL 数据库已连接。 +
+
+ + ← 返回首页 + +""" + return HTMLResponse(content=html_content) + @application.get("/internal/decrypt-data", response_class=HTMLResponse) async def decrypt_data_page(): html_content = """ @@ -701,7 +845,7 @@ a:hover{text-decoration:underline}

API 文档

Swagger UI 交互式文档

ReDoc

ReDoc 格式文档

-

健康检查

服务状态

+

服务状态

Celery/Redis 监控

解密数据

数据解密

"""