init: web_hgdjc_server
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package srv_aicomment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/models/aicommentrecord"
|
||||
"videoweb/pub/models/playletmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
// RetryFailedPlaylets retries a bounded batch, oldest failure first.
|
||||
func RetryFailedPlaylets(ctx context.Context) {
|
||||
if !GetAiCommentService().Configured() {
|
||||
return
|
||||
}
|
||||
records, serr := aicommentrecord.FindFailedForRetry(ctx, 100)
|
||||
if serr != nil || len(records) == 0 {
|
||||
return
|
||||
}
|
||||
ids := make([]int64, 0, len(records))
|
||||
for _, record := range records {
|
||||
id, err := strconv.ParseInt(record.Vid, 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
_ = aicommentrecord.SetStatusByKey(ctx, record.Key, aicommentrecord.StatusAbandoned, "短剧ID无效")
|
||||
continue
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return
|
||||
}
|
||||
playlets, serr := playletmod.FindManyPlaylet(ctx, bson.M{
|
||||
playletmod.FN.Playlet.Id: bson.M{"$in": ids},
|
||||
playletmod.FN.Playlet.Status: playletmod.StatusUp,
|
||||
})
|
||||
if serr != nil {
|
||||
log.Warn("查询待重试短剧失败", log.E(serr))
|
||||
return
|
||||
}
|
||||
active := make(map[int64]struct{}, len(playlets))
|
||||
for _, playlet := range playlets {
|
||||
active[playlet.Id] = struct{}{}
|
||||
}
|
||||
for _, record := range records {
|
||||
id, err := strconv.ParseInt(record.Vid, 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
continue
|
||||
}
|
||||
if _, ok := active[id]; !ok {
|
||||
_ = aicommentrecord.SetStatusByKey(ctx, record.Key, aicommentrecord.StatusAbandoned, "短剧已下架或不存在")
|
||||
}
|
||||
}
|
||||
if len(active) == 0 {
|
||||
return
|
||||
}
|
||||
activeIDs := make([]int64, 0, len(active))
|
||||
for id := range active {
|
||||
activeIDs = append(activeIDs, id)
|
||||
}
|
||||
if err := AutoProcessUnsubmittedPlaylets(ctx, activeIDs); err != nil {
|
||||
log.Warn("重试短剧自动评论失败", log.E(err), log.Any("count", len(activeIDs)))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user