mirror of
https://github.com/Hommy-master/capcut-mate.git
synced 2026-08-30 17:48:47 +08:00
新增加查询云渲染任务数的接口,方便调度。
This commit is contained in:
@@ -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:
|
||||
"""
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
"""云渲染进行中数量查询"""
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class GenVideoActiveCountResponse(BaseModel):
|
||||
"""当前排队与渲染中的云渲染草稿数量"""
|
||||
count: int = Field(..., description="排队中(pending)与渲染中(processing)的草稿数量,不含已完成/失败")
|
||||
@@ -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"]
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user