service/library/contentaudit/video_moderation/control_block.go

69 lines
3.1 KiB
Go
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.

package videomoderation
import (
"fmt"
"service/api/consts"
"service/dbstruct"
"service/library/logger"
"github.com/gin-gonic/gin"
)
// 批次视频审核任务控制块
type VideoModerationTaskBatchControlBlock struct {
BatchId string // 批次号
TaskCtrlBlockMap map[string]*VideoModerationTaskControlBlock // 视频审核任务表id->任务控制块map
VidmodId2taskMap map[string]*VideoModerationTaskControlBlock // 视频审核表id->任务控制块map
ActionMap map[string]*VideoModerationAction // 动作Id号-action的map
Ct int64 // 创建时间戳
TaskNum int64 // 任务数量
FinishedTaskNum int64 // 已完成任务数量
}
func (ctrlBlock *VideoModerationTaskBatchControlBlock) RecordAction(taskCtrlBlock *VideoModerationTaskControlBlock) {
ctx := &gin.Context{}
// 写map记录
if ctrlBlock.ActionMap[taskCtrlBlock.ActionId] == nil { // 写入ctrlBlock.ActionMap
ctrlBlock.ActionMap[taskCtrlBlock.ActionId] = NewVideoModerationAction()
// 将此前批次对该元素未成功,待处理的审核全部置为已失效
failStatuses := []int64{consts.VideoModeration_Rollbacked, consts.VideoModeration_ServiceFailed}
if err := _DefaultVideoModerationTask.OpHandleOverdue(ctx, taskCtrlBlock.VideoModerationTask, taskCtrlBlock.VideoModerationTask.GetBatchId(), failStatuses); err != nil {
logger.Error("_DefaultVideoModerationTask OpHandleOverdue fail :%v", err)
}
}
ctrlBlock.ActionMap[taskCtrlBlock.ActionId].Record(taskCtrlBlock)
}
func (ctrlBlock *VideoModerationTaskBatchControlBlock) IsBatchFinished() bool {
return ctrlBlock.TaskNum <= ctrlBlock.FinishedTaskNum
}
func (ctrlBlock *VideoModerationTaskBatchControlBlock) FinishATask() {
ctrlBlock.FinishedTaskNum++
}
// 视频审核任务控制块
// ActionId设计初衷由于视频审核是定时任务触发的批量作业如果在一次作业间隔有针对同一个视频媒体的多次更新则会提交关于它的多次审核需要保证数据一致性
type VideoModerationTaskControlBlock struct {
// 静态元素
ActionId string // 审核动作id号由视频审核实体数据库四要素拼接而成用于指示对数据库-表-单条数据-视频字段的审核动作
VideoModerationTask *dbstruct.VideoModerationTask // 审核任务
// 动态元素
IsTaskPassed bool // 任务状态,仅当任务已确定完成,即已完成审核任务的分片数 = 审核任务分片数时,才有意义
AuditedFragmentsNum int // 已完成审核任务的分片数
}
// 新建视频审核任务块
func NewVideoModerationTaskControlBlock(task *dbstruct.VideoModerationTask) (tcb *VideoModerationTaskControlBlock) {
tcb = &VideoModerationTaskControlBlock{
ActionId: fmt.Sprintf("%v%v%v%v", task.GetAssociativeDatabase(), task.GetAssociativeTableName(),
task.GetAssociativeTableId(), task.GetAssociativeTableColumn()),
VideoModerationTask: task,
IsTaskPassed: true,
AuditedFragmentsNum: 0,
}
return
}