2023-12-21 22:17:40 +08:00
|
|
|
package textaudit
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"service/library/configcenter"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var defaultTextAuditTaskScheduler *TextAuditTaskScheduler
|
|
|
|
|
|
|
|
// 文字审核任务调度器
|
|
|
|
type TextAuditTaskScheduler struct {
|
|
|
|
// 缓冲池、同步标志
|
2024-01-20 18:48:38 +08:00
|
|
|
batchFlag chan bool // 批处理同步标志
|
2023-12-21 22:17:40 +08:00
|
|
|
|
|
|
|
// 状态记录
|
|
|
|
batchId string // 当前批次号
|
|
|
|
}
|
|
|
|
|
|
|
|
func initScheduler(cfg *configcenter.TextAuditConfig) {
|
|
|
|
defaultTextAuditTaskScheduler = &TextAuditTaskScheduler{
|
2024-01-20 18:48:38 +08:00
|
|
|
batchFlag: make(chan bool, 1),
|
|
|
|
batchId: genereteBatchId(),
|
2023-12-21 22:17:40 +08:00
|
|
|
}
|
|
|
|
defaultTextAuditTaskScheduler.batchFlag <- true
|
|
|
|
}
|
|
|
|
|
|
|
|
// 批处理上锁
|
|
|
|
func (s *TextAuditTaskScheduler) lock() {
|
|
|
|
<-s.batchFlag
|
|
|
|
}
|
|
|
|
|
|
|
|
// 批处理解锁
|
|
|
|
func (s *TextAuditTaskScheduler) unLock() {
|
|
|
|
s.batchFlag <- true
|
|
|
|
}
|
|
|
|
|
|
|
|
// 生成批次号
|
|
|
|
func genereteBatchId() string {
|
|
|
|
now := time.Now()
|
|
|
|
y, m, d := now.Date()
|
|
|
|
h, mi, s := now.Clock()
|
2024-01-20 18:48:38 +08:00
|
|
|
return fmt.Sprintf("%d%02d%02d%02d%02d%02d", y, m, d, h, mi, s)
|
2023-12-21 22:17:40 +08:00
|
|
|
}
|