修复线上视频导出卡死(OOM)+ 导出健壮性加固

根因:后端容器内存 limit 仅 768Mi,ffmpeg 编码 1080P 竖屏时内存峰值超限被
K8s OOMKill,导出后台线程随 Pod 重启而死,任务永远停在 35%(本地无 limit 29s 出片)。

- k8s/core/api-deployment.yaml: 后端内存 limit 768Mi→2Gi、requests 256→512Mi,
  给 ffmpeg 足够编码空间(根治)
- export.py: ffmpeg subprocess 加 900s 超时(卡死不再永久 RUNNING)+ -threads 2 降内存峰值
- views.py: submit-export 清理超 5 分钟未结束的僵尸任务,前端不再无限转圈

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
zyc
2026-06-15 13:58:18 +08:00
co-authored by Claude Opus 4.8
parent 5e2bc0fc5a
commit a8852345db
3 changed files with 24 additions and 6 deletions
+9
View File
@@ -371,6 +371,15 @@ class ProjectViewSet(TeamScopedViewSetMixin, ModelViewSet):
duration_ms=segment.target_duration_seconds * 1000,
)
start_ms += segment.target_duration_seconds * 1000
# 清理僵尸任务:后台线程跑导出时若 Pod 被重启/OOM 杀掉,旧任务会永远停在 RUNNING、
# 前端无限轮询。新建前把本时间线超过 5 分钟仍未结束的旧任务标失败,避免界面一直转圈。
from django.utils import timezone
from datetime import timedelta
ExportJob.objects.filter(
timeline=timeline,
status__in=[ExportJob.Status.QUEUED, ExportJob.Status.RUNNING],
updated_at__lt=timezone.now() - timedelta(minutes=5),
).update(status=ExportJob.Status.FAILED, error_message="任务中断(服务重启或超时),已自动失败,请重新导出")
export_job = create_export_job(timeline=timeline, user=request.user)
stage, _ = ProjectStage.objects.get_or_create(project=project, stage=ProjectStage.Stage.EXPORT)
stage.status = ProjectStage.Status.RUNNING