From a278635dd2193a73ca1359cbfeb44cb469e05249 Mon Sep 17 00:00:00 2001 From: Hommy <16620803786@163.com> Date: Sun, 5 Apr 2026 18:22:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=BA=91=E6=B8=B2=E6=9F=93=E4=BB=BB=E5=8A=A1=E6=95=B0=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=96=B9=E4=BE=BF=E8=B0=83=E5=BA=A6?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/v1.py | 10 ++++++++++ src/schemas/gen_video_active_count.py | 7 +++++++ src/service/__init__.py | 4 ++-- src/service/gen_video.py | 5 +++++ src/utils/video_task_manager.py | 10 +++++++++- 5 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 src/schemas/gen_video_active_count.py diff --git a/src/router/v1.py b/src/router/v1.py index 415d2e0..af92d96 100644 --- a/src/router/v1.py +++ b/src/router/v1.py @@ -34,6 +34,7 @@ from src.schemas.easy_create_material import EasyCreateMaterialRequest, EasyCrea from src.schemas.save_draft import SaveDraftRequest, SaveDraftResponse from src.schemas.gen_video import GenVideoRequest, GenVideoResponse from src.schemas.gen_video_status import GenVideoStatusRequest, GenVideoStatusResponse +from src.schemas.gen_video_active_count import GenVideoActiveCountResponse from src.schemas.get_draft import GetDraftRequest, GetDraftResponse from src.schemas.get_audio_duration import GetAudioDurationRequest, GetAudioDurationResponse from src.schemas.timelines import TimelinesRequest, TimelinesResponse @@ -489,6 +490,15 @@ def gen_video_status(gvsr: GenVideoStatusRequest) -> GenVideoStatusResponse: return GenVideoStatusResponse(**status_info) +@router.get(path="/gen_video_active_count", response_model=GenVideoActiveCountResponse) +def gen_video_active_count() -> GenVideoActiveCountResponse: + """ + 查询当前进行中的云渲染草稿数量(排队中 + 渲染中,不含已完成/失败)。 + """ + count = service.get_gen_video_active_count() + return GenVideoActiveCountResponse(count=count) + + @router.post(path="/get_audio_duration", response_model=GetAudioDurationResponse) def get_audio_duration(gadr: GetAudioDurationRequest) -> GetAudioDurationResponse: """ diff --git a/src/schemas/gen_video_active_count.py b/src/schemas/gen_video_active_count.py new file mode 100644 index 0000000..d48efd3 --- /dev/null +++ b/src/schemas/gen_video_active_count.py @@ -0,0 +1,7 @@ +"""云渲染进行中数量查询""" +from pydantic import BaseModel, Field + + +class GenVideoActiveCountResponse(BaseModel): + """当前排队与渲染中的云渲染草稿数量""" + count: int = Field(..., description="排队中(pending)与渲染中(processing)的草稿数量,不含已完成/失败") diff --git a/src/service/__init__.py b/src/service/__init__.py index 026b812..b295fc2 100644 --- a/src/service/__init__.py +++ b/src/service/__init__.py @@ -15,7 +15,7 @@ from .get_filters import get_filters from .get_effects import get_effects from .easy_create_material import easy_create_material, easy_create_material_async from .save_draft import save_draft, save_draft_async -from .gen_video import gen_video, gen_video_status +from .gen_video import gen_video, gen_video_status, get_gen_video_active_count from .get_draft import get_draft from .get_audio_duration import get_audio_duration from .timelines import timelines @@ -33,4 +33,4 @@ from .str_list_to_objs import str_list_to_objs from .str_to_list import str_to_list from .objs_to_str_list import objs_to_str_list -__all__ = ["create_draft", "add_videos", "add_audios", "add_images", "add_sticker", "add_keyframes", "add_captions", "add_effects", "add_filters", "add_masks", "add_text_style", "get_text_animations", "get_image_animations", "get_filters", "get_effects", "easy_create_material", "save_draft", "gen_video", "gen_video_status", "get_draft", "get_audio_duration", "timelines", "audio_timelines", "audio_infos", "imgs_infos", "caption_infos", "effect_infos", "filter_infos", "keyframes_infos", "video_infos", "search_sticker", "get_url", "str_list_to_objs", "str_to_list", "objs_to_str_list", "add_videos_async", "add_audios_async", "add_images_async", "add_sticker_async", "add_keyframes_async", "add_captions_async", "add_effects_async", "add_filters_async", "add_masks_async", "easy_create_material_async", "save_draft_async"] +__all__ = ["create_draft", "add_videos", "add_audios", "add_images", "add_sticker", "add_keyframes", "add_captions", "add_effects", "add_filters", "add_masks", "add_text_style", "get_text_animations", "get_image_animations", "get_filters", "get_effects", "easy_create_material", "save_draft", "gen_video", "gen_video_status", "get_gen_video_active_count", "get_draft", "get_audio_duration", "timelines", "audio_timelines", "audio_infos", "imgs_infos", "caption_infos", "effect_infos", "filter_infos", "keyframes_infos", "video_infos", "search_sticker", "get_url", "str_list_to_objs", "str_to_list", "objs_to_str_list", "add_videos_async", "add_audios_async", "add_images_async", "add_sticker_async", "add_keyframes_async", "add_captions_async", "add_effects_async", "add_filters_async", "add_masks_async", "easy_create_material_async", "save_draft_async"] diff --git a/src/service/gen_video.py b/src/service/gen_video.py index a381627..a82cdc9 100644 --- a/src/service/gen_video.py +++ b/src/service/gen_video.py @@ -132,3 +132,8 @@ def get_task_status_info(draft_url: str) -> dict: raise CustomException(CustomError.VIDEO_TASK_NOT_FOUND) return status_info + + +def get_gen_video_active_count() -> int: + """返回当前排队中 + 渲染中的云渲染草稿数量(不含已完成/失败)。""" + return task_manager.get_active_render_count() diff --git a/src/utils/video_task_manager.py b/src/utils/video_task_manager.py index 3dd2182..cdea6c4 100644 --- a/src/utils/video_task_manager.py +++ b/src/utils/video_task_manager.py @@ -196,7 +196,15 @@ class VideoGenTaskManager: "started_at": task.started_at.isoformat() if task.started_at else None, "completed_at": task.completed_at.isoformat() if task.completed_at else None } - + + def get_active_render_count(self) -> int: + """ + 当前进行中的云渲染草稿数量:排队(pending) + 渲染中(processing)。 + 不含已完成(completed)、失败(failed)。 + """ + active = (TaskStatus.PENDING, TaskStatus.PROCESSING) + return sum(1 for t in self.tasks.values() if t.status in active) + def _ensure_worker_running(self): """确保工作线程正在运行""" if self.worker_thread is None or not self.worker_thread.is_alive():