fix(lipsync, P0): TTS异步任务改用@shared_task,解决Worker不注册任务导致卡tts_processing #1851
Reference in New Issue
Block a user
Delete Branch "fix/lipsync-shared-task"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
P0 Bug 描述
对口型TTS异步化上线后,任务一直卡在 tts_processing 不执行。
根本原因:
lipsync_tts.py从app.core.celery_app导入 celery_app 并用@celery_app.task装饰,task 被注册到 API 侧 celery_app 实例,但 Worker 进程运行的是 Worker 侧 celery_app(xiaoxia-saas-worker)。Worker imports 里虽然写了apps.api.app.tasks.lipsync_tts,但装饰器把 task 注册到了 API 的 celery_app 上,Worker 的 celery_app 不知道这个 task 的存在,消息被消费后路由不到处理函数。修复
@shared_task:使用from celery import shared_task+@shared_task(name="lipsync_tts.synthesize_and_submit", ...),任务会自动注册到当前活跃的 celery_app(Worker 启动时正确注册),API 侧tts_synthesize_and_submit.apply_async(...)调用方式不变。get_shared_storage_service懒导入,改为在 OSS 上传段按需懒导入,保持 task 注册阶段无副作用。_sign_media_url保持模块内独立函数(不反射调用 LipsyncService,避免跨容器问题)。apps/web/src/pages/ai-avatar/api/aiAvatar.ts的getLipsyncJob接口加上{ timeout: 60000 },跟其他接口保持一致,避免轮询时 10s 默认超时导致前端状态刷新失败。不影响
apps.api.app.tasks.lipsync_tts)测试
🚀 预览环境已部署
e85626dc69todf0416c80aP0: lipsync_tts.py 原从 app.core.celery_app 导入 celery_app 并 @celery_app.task 装饰, task 被注册到 API 侧 celery_app 实例上,但 Worker 进程使用的是 Worker 侧 celery_app, 导致 Worker 消费消息后找不到处理函数,对口型任务永远卡在 tts_processing 状态。 修复: 1. 改为 @shared_task(name="lipsync_tts.synthesize_and_submit") 装饰器, 任务自动注册到当前活跃的 celery_app(Worker 启动时会正确注册), API 侧 apply_async 调用方式不变。 2. _sign_media_url 保持为模块内独立函数(不依赖 LipsyncService 反射), 删除函数体开头冗余的 get_shared_storage_service 重复 import, 仅在 OSS 上传段按需懒导入,保持 task 注册阶段无副作用。 3. 前端 aiAvatar.ts 的 getLipsyncJob 接口加 { timeout: 60000 }, 避免轮询时 10s 默认超时导致前端状态刷新失败。 测试:56 passed,lipsync_tts.py 覆盖率 79%。df0416c80ato11ee0b3a03🗑️ 预览环境已清理
PR #1851 已关闭或合并,对应的预览环境已被清理。