Files
xiaoxia-saas/apps/worker/worker_app/celery_app.py
T
xiaoxia 54916aff86
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Successful in 5s
CI/CD Pipeline / Check push changed paths (push) Successful in 8s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 29s
CI/CD Pipeline / Build Staging API Image (push) Successful in 31s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 37s
CI/CD Pipeline / Validate - Python (mypy + alembic) (push) Successful in 2m1s
CI/CD Pipeline / Integration Tests (push) Successful in 2m22s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m11s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m16s
CI/CD Pipeline / Validate - Style (push) Successful in 2m58s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m41s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 1m30s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 1m36s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 5m47s
CI/CD Pipeline / Validate - Security (push) Successful in 6m2s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 3m33s
AI Code Review / AI Code Review (pull_request) Successful in 6m27s
CI/CD Pipeline / Unit Tests (push) Successful in 8m30s
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 31s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 32s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 38s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 241h24m45s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 241h24m46s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 241h24m56s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 241h25m4s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 241h25m7s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 241h25m17s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 241h25m19s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 241h25m57s
CI/CD Pipeline / Canary Release to Production (push) Failing after 241h34m12s
CI/CD Pipeline / CI Gate (push) Failing after 241h34m16s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 241h34m16s
CI/CD Pipeline / Build Production API Image (push) Failing after 241h34m16s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Failing after 241h38m54s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 0s
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Failing after 241h41m44s
CI/CD Pipeline / Retag skipped Staging API Image (push) Failing after 241h41m46s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 0s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 0s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 241h25m51s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 241h25m52s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 241h25m52s
CI/CD Pipeline / Validate - Security (pull_request) Failing after 241h25m56s
CI/CD Pipeline / Validate - Style (pull_request) Failing after 241h25m56s
CI/CD Pipeline / Frontend Lint (push) Failing after 241h42m46s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 241h42m51s
CI/CD Pipeline / PR Build API Image (push) Failing after 241h42m52s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 241h42m57s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 241h59m22s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 241h59m42s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 241h59m53s
CI/CD Pipeline / Deploy Production (push) Failing after 242h8m49s
CI/CD Pipeline / Build Production Web Image (push) Failing after 242h8m52s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 0s
CI/CD Pipeline / Retag skipped Staging Web Image (push) Failing after 242h16m21s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 0s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 242h0m28s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Failing after 242h0m28s
CI/CD Pipeline / PR Build Web Image (push) Failing after 242h17m27s
fix(#1714): 同名兜底去重误杀新视频 + ingest 链路孤儿清理/启动恢复 (#1734)
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com>
Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
2026-09-06 13:41:26 +08:00

65 lines
3.0 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from celery import Celery
from worker_app.core.config import get_settings
settings = get_settings()
celery_app = Celery(settings.worker_name)
celery_app.conf.broker_url = settings.broker_url
celery_app.conf.result_backend = settings.result_backend
celery_app.conf.broker_connection_retry_on_startup = True
# #1714 队列隔离:generation(高优,独占 worker)/ transcode(素材转码)/ celery(默认)
from packages.shared.celery_queues import ( # noqa: E402
GENERATION_WORKER_PREFETCH_MULTIPLIER,
apply_queue_settings,
)
apply_queue_settings(celery_app)
# 长渲染任务预取 1,避免任务被预取占住导致调度不均
celery_app.conf.worker_prefetch_multiplier = GENERATION_WORKER_PREFETCH_MULTIPLIER
celery_app.conf.task_acks_late = True # worker 崩溃时未完成任务重回队列,由执行前守卫丢弃作废消息
# worker 进程被 OOM/容器硬杀时拒绝 ack,消息留在队列由其他 worker 接手
celery_app.conf.task_reject_on_worker_lost = True
# Redis broker 消息可见性超时(#1714):acks_late 下,消息被预取后 visibility_timeout
# 内未 ack 才会重投。长任务(ingest HEVC 转码 20-30 分钟、生成硬超时 11 分钟)
# 必须远大于最长执行时间,否则正常任务会在执行中被误重投;4 小时覆盖最长转码 + 余量。
celery_app.conf.broker_transport_options = {"visibility_timeout": 4 * 60 * 60}
celery_app.conf.imports = (
"worker_app.tasks.health",
"worker_app.tasks.ingest",
"worker_app.tasks.classification",
"worker_app.tasks.generation",
"worker_app.tasks.voice_extraction",
"worker_app.tasks.voice_clone",
"worker_app.tasks.tts_synthesis",
"worker_app.tasks.batch_download",
"worker_app.tasks.duplication_check",
"worker_app.tasks._startup",
"apps.worker.video_processing.dedup",
"worker_app.tasks.cleanup",
)
# Celery Beat 定时任务调度
# 注:worker 单实例内嵌 beat(entrypoint-worker.sh -B),定时任务不会重复执行
celery_app.conf.beat_schedule = {
# pending 任务超时清理:worker 停止消费后,卡 pending 的任务 15 分钟内释放限流名额
"cleanup-stale-pending-tasks": {
"task": "worker.cleanup_stale_pending_tasks",
"schedule": 300.0, # 每 5 分钟(秒)
"options": {"expires": 240}, # 4 分钟过期,避免堆积
},
# running 孤儿任务巡检:容器重启/进程被杀后卡 running 的任务,20 分钟无更新则判失败
"cleanup-stale-running-tasks": {
"task": "worker.cleanup_stale_running_tasks",
"schedule": 300.0, # 每 5 分钟(秒)
"options": {"expires": 240},
},
# 上传/转码链路孤儿巡检:worker 重启丢 prefetch 消息后,卡 pending/processing
# 的 ingest_job + asset 占位超时标终态(#1714)。转码任务较长,10 分钟一轮
"cleanup-stale-ingest-jobs": {
"task": "worker.cleanup_stale_ingest_jobs",
"schedule": 600.0, # 每 10 分钟(秒)
"options": {"expires": 540},
},
}