package playletwatermark import ( "context" "time" "videoweb/pub/common/log" "videoweb/pub/common/srvdef" "videoweb/pub/models/playletchaptermod" "go.mongodb.org/mongo-driver/bson" ) const watermarkStuckTimeout = 48 * time.Hour // MarkStuckChaptersFailed 兜底:已登记/处理中超过 2 天仍未完成的剧集标记为处理失败。 // media 原片已 CompletedFail 时由 submit 立即回写,不必等这 2 天。 func MarkStuckChaptersFailed() { ctx := context.Background() now := time.Now() cutoff := now.Add(-watermarkStuckTimeout) err := playletchaptermod.UpdateManyPlayletChapter(ctx, bson.M{ playletchaptermod.FN.PlayletChapter.WatermarkStatus: bson.M{ "$in": []playletchaptermod.WatermarkStatus{ playletchaptermod.WatermarkStatusRegistered, playletchaptermod.WatermarkStatusProcessing, }, }, playletchaptermod.FN.PlayletChapter.UpdatedAt: bson.M{"$lt": cutoff}, }, bson.M{"$set": bson.M{ playletchaptermod.FN.PlayletChapter.WatermarkStatus: playletchaptermod.WatermarkStatusFailed, playletchaptermod.FN.PlayletChapter.UpdatedAt: now, }}) if err != nil && err.Code != srvdef.ErrNoData { log.Error("playletwatermark:MarkStuckChaptersFailed 更新失败", log.E(err)) return } log.Info("playletwatermark:MarkStuckChaptersFailed end", log.Any("cutoff", cutoff)) }