Pārlūkot izejas kodu

feat:是否取消

wangshan 1 gadu atpakaļ
vecāks
revīzija
7f419cab86

+ 10 - 11
internal/dao/internal/analyzeTask.go

@@ -60,16 +60,6 @@ func (a *AnalyzeTask) Run() {
 		es.NewRangeQuery("jgtime").Gte(a.StartTime).Lte(a.EndTime),
 		es.NewTermsQuery("bidstatus", consts.BidStatus...),
 	)
-	// 打印查询语句
-	//source, err := query.Source()
-	//if err != nil {
-	//	g.Log().Info(model.Ctx, "---1---", err)
-	//}
-	//queryJSON, err := json.MarshalIndent(source, "", "  ")
-	//if err != nil {
-	//	g.Log().Info(model.Ctx, "---2---", err)
-	//}
-	//g.Log().Info(model.Ctx, "---3---", string(queryJSON))
 	client := do.Es.GetEsConn()
 	defer do.Es.DestoryEsConn(client)
 	// 创建一个搜索服务对象,并设置查询条件和排序
@@ -107,10 +97,19 @@ func (a *AnalyzeTask) Run() {
 			for _, hit := range results.Hits.Hits {
 				p := &entity.ProjectInfo{}
 				if err := json.Unmarshal(hit.Source, p); err == nil {
-					for _, ui := range a.UI {
+					for uk, ui := range a.UI {
 						if ui.FormatParam.STime <= p.JgTime && ui.FormatParam.ETime >= p.JgTime {
 							ui.Start()
 							ui.Push(p)
+							//
+							if iterationTimes%20 == 0 {
+								ui.IsCancel = utility.IsAnalyzeCancel(ui.RId)
+							}
+							if ui.IsCancel {
+								ui.Reset()
+								a.UI = append(a.UI[:uk], a.UI[uk+1:]...)
+								continue
+							}
 						}
 					}
 				} else {

+ 10 - 4
internal/dao/internal/userTask.go

@@ -79,7 +79,7 @@ func (ut *UserTask) Start() {
 
 func (ut *UserTask) Run() {
 	for {
-		if ut.IsEnd {
+		if ut.IsEnd || ut.IsCancel {
 			break
 		}
 		select {
@@ -92,9 +92,15 @@ func (ut *UserTask) Run() {
 				ut.DataCollation()
 			}
 		case <-ut.Ticker.C:
-			ut.ResultSave()
-			ut.SendMsg()
-			ut.IsEnd = true
+			//是否已取消
+			if !ut.IsCancel {
+				ut.IsCancel = utility.IsAnalyzeCancel(ut.RId)
+			}
+			if !ut.IsCancel {
+				ut.ResultSave()
+				ut.SendMsg()
+				ut.IsEnd = true
+			}
 			break
 		}
 	}

+ 2 - 2
utility/userTask.go

@@ -260,7 +260,7 @@ func GetSortedKeyOfRedis(prev int, key, id, suffix string) string {
 }
 
 // --
-func IsAnalyzeCancel(key string) bool {
-	n, _ := g.Redis().Exists(model.Ctx, key)
+func IsAnalyzeCancel(id string) bool {
+	n, _ := g.Redis().Exists(model.Ctx, fmt.Sprintf(consts.ReportCanceledKey, id))
 	return n > 0
 }