nex_animation/backend/app/jobs/tasks.py

78 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""Celery 任务包装:只负责把消息转交给 handlers,编排逻辑仍在数据库里。
任务名与 services/execution.CELERY_TASK_NAMES 一一对应,队列划分见 worker.QUEUES。
"""
from __future__ import annotations
from sqlalchemy.orm import Session
from app.worker import celery_app
@celery_app.task(name="app.jobs.generate_shot", bind=True, acks_late=True)
def generate_shot(self, task_id: int) -> dict:
from app.jobs import handlers
return handlers.run("generate_shot", task_id)
@celery_app.task(name="app.jobs.voiceover", bind=True, acks_late=True)
def voiceover(self, task_id: int) -> dict:
from app.jobs import handlers
return handlers.run("voiceover", task_id)
@celery_app.task(name="app.jobs.qc_shot", bind=True, acks_late=True)
def qc_shot(self, task_id: int) -> dict:
from app.jobs import handlers
return handlers.run("qc_shot", task_id)
@celery_app.task(name="app.jobs.compose", bind=True, acks_late=True)
def compose(self, task_id: int) -> dict:
from app.jobs import handlers
return handlers.run("compose", task_id)
@celery_app.task(name="app.jobs.import_package", bind=True, acks_late=True)
def import_package(self, task_id: int) -> dict:
from app.jobs import handlers
return handlers.run("import", task_id)
@celery_app.task(name="app.jobs.asset", bind=True, acks_late=True)
def asset(self, task_id: int) -> dict:
from app.jobs import handlers
return handlers.run("asset", task_id)
@celery_app.task(name="app.jobs.dispatch_due")
def dispatch_due() -> dict:
"""周期调度器:扫描到期任务并按模型限流额度派发。"""
from app.db import SessionLocal
from app.services import dispatch
db: Session = SessionLocal()
try:
return dispatch.dispatch_due(db)
finally:
db.close()
@celery_app.task(name="app.jobs.resume_interrupted")
def resume_interrupted() -> dict:
"""周期断点续跑:回收中断任务,跳过已存在产物。"""
from app.db import SessionLocal
from app.services import dispatch
db: Session = SessionLocal()
try:
return dispatch.resume_interrupted(db)
finally:
db.close()