service/library/contentaudit/video_moderation/taskscheduler.go

56 lines
1.5 KiB
Go
Raw Normal View History

2024-04-26 10:46:37 +08:00
package videomoderation
import (
"fmt"
"service/library/configcenter"
2024-04-27 11:14:44 +08:00
"service/library/logger"
2024-04-26 10:46:37 +08:00
"time"
)
var defaultVideoModerationTaskScheduler *VideoModerationTaskScheduler
// 图像审核任务调度器
type VideoModerationTaskScheduler struct {
// 批次审核任务控制块
btcbMp map[string]*VideoModerationTaskBatchControlBlock
}
func initScheduler(cfg *configcenter.VideoModerationConfig) {
defaultVideoModerationTaskScheduler = &VideoModerationTaskScheduler{
btcbMp: make(map[string]*VideoModerationTaskBatchControlBlock),
2024-04-26 10:46:37 +08:00
}
}
// 生成批次号
func genereteBatchId() string {
now := time.Now()
y, m, d := now.Date()
h, mi, s := now.Clock()
return fmt.Sprintf("%d%02d%02d%02d%02d%02d", y, m, d, h, mi, s)
}
// 获取批次审核任务控制块
2024-04-27 11:14:44 +08:00
func getBtcb(batchId string) (*VideoModerationTaskBatchControlBlock, bool) {
for k, v := range defaultVideoModerationTaskScheduler.btcbMp {
logger.Info("batch_id: %v, btcb: %v", k, v)
}
logger.Info("now batch_id: %v", batchId)
btcb, ok := defaultVideoModerationTaskScheduler.btcbMp[batchId]
return btcb, ok
2024-04-26 10:46:37 +08:00
}
// 移除批次审核任务控制块
func removeBtcb(batchId string) {
2024-04-27 11:14:44 +08:00
delete(defaultVideoModerationTaskScheduler.btcbMp, batchId)
}
// 清理过期的批次审核任务控制块
func ClearExpiredBtcb() {
nowTime := time.Now().Unix()
for _, v := range defaultVideoModerationTaskScheduler.btcbMp {
if nowTime-v.Ct > SecElapsedBeforeTaskExpires {
delete(defaultVideoModerationTaskScheduler.btcbMp, v.BatchId)
}
}
2024-04-26 10:46:37 +08:00
}