审查视图

tangxvhui authored
1
package main
tangxvhui authored
2 3

import (
Your Name authored
4 5
	"time"
tangxvhui authored
6 7
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
tangxvhui authored
8
	"github.com/beego/beego/v2/server/web"
郑周 authored
9
	serviceTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task"
tangxvhui authored
10
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
tangxvhui authored
11
	serviceSummary "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/service"
郑周 authored
12
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
tangxvhui authored
13
	_ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego"
tangxvhui authored
14
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer"
tangxvhui authored
15 16 17
)

func main() {
郑周 authored
18
	startNodeTask()
tangxvhui authored
19
	startSummaryEvaluation()
tangxvhui authored
20
	go notify.RunTaskSmsNotify()
tangxvhui authored
21
	go consumer.Run()
tangxvhui authored
22 23
	web.Run()
}
郑周 authored
24 25 26 27

// 定时任务-间隔发送评估环节
func startNodeTask() {
	go func() {
郑周 authored
28
		nodeTaskService := serviceTask.NewNodeTaskService()
郑周 authored
29 30 31 32 33 34 35 36

		var duration time.Duration
		if constant.Env == "prd" {
			duration = time.Minute * 5
		} else {
			duration = time.Minute * 1
		}
		timer := time.NewTimer(duration)
郑周 authored
37 38 39 40 41
		for {
			<-timer.C
			if err := nodeTaskService.SendEvaluationNode(); err != nil {
				log.Logger.Error(err.Error())
			}
郑周 authored
42
			timer.Reset(duration) // 重置定时
郑周 authored
43 44 45
		}
	}()
}
tangxvhui authored
46
tangxvhui authored
47
// 定时任务-间隔检查时间,发送周期评估
tangxvhui authored
48
func startSummaryEvaluation() {
tangxvhui authored
49 50 51 52 53 54 55 56 57 58
	go func() {
		var duration time.Duration
		if constant.Env == "prd" {
			duration = time.Minute * 5
		} else {
			duration = time.Minute * 1
		}
		timer := time.NewTimer(duration)
		for {
			<-timer.C
59
			if err := serviceSummary.TaskSendSummaryEvaluationV2(); err != nil {
tangxvhui authored
60 61 62 63 64
				log.Logger.Error(err.Error())
			}
			timer.Reset(duration) // 重置定时
		}
	}()
tangxvhui authored
65
}