Przeglądaj źródła

wip:防止运行多个查询

wangkaiyue 2 lat temu
rodzic
commit
23234ff8b5
1 zmienionych plików z 11 dodań i 2 usunięć
  1. 11 2
      entity/mananger/customManager.go

+ 11 - 2
entity/mananger/customManager.go

@@ -28,6 +28,7 @@ type CustomManager struct {
 	UserGroup  map[string]int // 月活用户
 	BatchFlag  string         // 批次标识
 	StopSearch chan bool      // 停止查询信号
+	IsDoSearch bool           // 是否正在查询
 	sync.RWMutex
 }
 
@@ -93,7 +94,9 @@ func (this *CustomManager) ScheduledTasks() {
 		//开始
 		startJob := cron.New(cron.WithSeconds())
 		if _, err := startJob.AddFunc(this.Conf.SearchLimit.Switch.Start, func() {
-			go this.DoSearch()
+			if !this.IsDoSearch {
+				go this.DoSearch()
+			}
 		}); err != nil {
 			panic(err)
 		}
@@ -101,7 +104,9 @@ func (this *CustomManager) ScheduledTasks() {
 		//结束
 		endJob := cron.New(cron.WithSeconds())
 		if _, err := endJob.AddFunc(this.Conf.SearchLimit.Switch.Stop, func() {
-			this.StopSearch <- true
+			if this.IsDoSearch {
+				this.StopSearch <- true
+			}
 		}); err != nil {
 			panic(err)
 		}
@@ -248,6 +253,10 @@ func (this *CustomManager) newUserQueue(batchFlag string) {
 
 // DoSearch 定制化分析报告查询队列
 func (this *CustomManager) DoSearch() {
+	this.IsDoSearch = true
+	defer func() {
+		this.IsDoSearch = false
+	}()
 	log.Printf("[MANAGER-INFO]CustomManager DoSearch Start\n")
 	for {
 		var obj *SearchEntity