45 lines
919 B
Go
45 lines
919 B
Go
package imageaudit
|
|
|
|
import (
|
|
"fmt"
|
|
"service/library/configcenter"
|
|
"time"
|
|
)
|
|
|
|
var defaultImageAuditTaskScheduler *ImageAuditTaskScheduler
|
|
|
|
// 图像审核任务调度器
|
|
type ImageAuditTaskScheduler struct {
|
|
// 同步标志
|
|
batchFlag chan bool // 批处理同步标志
|
|
|
|
// 状态记录
|
|
batchId string // 当前批次号
|
|
}
|
|
|
|
func initScheduler(cfg *configcenter.ImageAuditConfig) {
|
|
defaultImageAuditTaskScheduler = &ImageAuditTaskScheduler{
|
|
batchFlag: make(chan bool, 1),
|
|
batchId: genereteBatchId(),
|
|
}
|
|
defaultImageAuditTaskScheduler.batchFlag <- true
|
|
}
|
|
|
|
// 批处理上锁
|
|
func (s *ImageAuditTaskScheduler) lock() {
|
|
<-s.batchFlag
|
|
}
|
|
|
|
// 批处理解锁
|
|
func (s *ImageAuditTaskScheduler) unLock() {
|
|
s.batchFlag <- true
|
|
}
|
|
|
|
// 生成批次号
|
|
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)
|
|
}
|