审查视图

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()
20
	startConfirmEvaluationScore()
tangxvhui authored
21
	go notify.RunTaskSmsNotify()
tangxvhui authored
22
	go consumer.Run()
tangxvhui authored
23 24
	web.Run()
}
郑周 authored
25 26 27 28

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

		var duration time.Duration
		if constant.Env == "prd" {
			duration = time.Minute * 5
		} else {
			duration = time.Minute * 1
		}
		timer := time.NewTimer(duration)
郑周 authored
38 39 40 41 42
		for {
			<-timer.C
			if err := nodeTaskService.SendEvaluationNode(); err != nil {
				log.Logger.Error(err.Error())
			}
郑周 authored
43
			timer.Reset(duration) // 重置定时
郑周 authored
44 45 46
		}
	}()
}
tangxvhui authored
47
tangxvhui authored
48
// 定时任务-间隔检查时间,发送周期评估
tangxvhui authored
49
func startSummaryEvaluation() {
tangxvhui authored
50 51 52 53 54 55 56 57 58 59
	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
60
			if err := serviceSummary.TaskSendSummaryEvaluationV2(); err != nil {
tangxvhui authored
61 62 63 64 65
				log.Logger.Error(err.Error())
			}
			timer.Reset(duration) // 重置定时
		}
	}()
tangxvhui authored
66
}
tangxvhui authored
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

// 定时自动确认周期评估考核结果
func startConfirmEvaluationScore() {
	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
			if err := serviceSummary.TaskConfirmScore(); err != nil {
				log.Logger.Error(err.Error())
			}
			timer.Reset(duration) // 重置定时
		}
	}()
}