service/library/contentaudit/imageaudit/control_block.go

60 lines
2.2 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 imageaudit
import (
"fmt"
"service/api/consts"
"service/bizcommon/util"
"service/dbstruct"
goproto "google.golang.org/protobuf/proto"
)
// 图像审核任务控制块
// ActionId设计初衷由于图像审核是定时任务触发的批量作业如果在一次作业间隔有针对同一个图像媒体的多次更新则会提交关于它的多次审核需要配合乐观锁保证数据一致性
type ImageAuditTaskControlBlock struct {
// 静态元素
ActionId string // 审核动作id号由图像审核实体数据库四要素拼接而成用于指示对数据库-表-单条数据-图像字段的审核动作
ImageAuditTask *dbstruct.ImageAuditTask // 审核任务
RollbackFunc func() error // 审核失败时的回退方法
// 操作对象
Images []*dbstruct.MediaComponent // 被审核的图像序列
// 动态元素
IsTaskPassed bool // 任务状态,仅当任务已确定完成,即已完成审核任务的分片数 = 审核任务分片数时,才有意义
AuditedFragmentsNum int // 已完成审核任务的分片数
IsGivingNoticeToBatch bool // 是否进行批处理
}
// 新建图像审核任务块
func NewImageAuditTaskControlBlock(task *dbstruct.ImageAuditTask, rollbackFunc func() error) (tcb *ImageAuditTaskControlBlock) {
if task == nil || task.AuditedMedia == nil {
return
}
fragmentNum := len(util.DerefInt64Slice(task.AuditedMedia.ImageIds))
if fragmentNum == 0 {
return
}
task.BatchId = goproto.String(defaultImageAuditTaskScheduler.batchId)
task.Status = goproto.Int64(consts.ImageAudit_Created)
if fragmentNum == 1 {
task.IsFragmented = goproto.Int64(0)
task.FragmentsNum = goproto.Int64(1)
} else {
task.IsFragmented = goproto.Int64(1)
task.FragmentsNum = goproto.Int64(int64(fragmentNum))
}
tcb = &ImageAuditTaskControlBlock{
ActionId: fmt.Sprintf("%v%v%v%v", util.DerefString(task.AssociativeDatabase), util.DerefString(task.AssociativeTableName),
util.DerefInt64(task.AssociativeTableId), util.DerefString(task.AssociativeTableColumn)),
ImageAuditTask: task,
RollbackFunc: rollbackFunc,
IsTaskPassed: true,
AuditedFragmentsNum: 0,
IsGivingNoticeToBatch: false,
}
return
}