正在显示
5 个修改的文件
包含
19 行增加
和
31 行删除
| @@ -7,7 +7,7 @@ import ( | @@ -7,7 +7,7 @@ import ( | ||
| 7 | 7 | ||
| 8 | "github.com/beego/beego/v2/server/web" | 8 | "github.com/beego/beego/v2/server/web" |
| 9 | serviceTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task" | 9 | serviceTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task" |
| 10 | - serviceSummary "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/service" | 10 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify" |
| 11 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" | 11 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" |
| 12 | _ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego" | 12 | _ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego" |
| 13 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer" | 13 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer" |
| @@ -44,19 +44,5 @@ func startNodeTask() { | @@ -44,19 +44,5 @@ func startNodeTask() { | ||
| 44 | 44 | ||
| 45 | // 定时任务-间隔检查时间,发送周期评估 | 45 | // 定时任务-间隔检查时间,发送周期评估 |
| 46 | func startSummaryEvaluation() { | 46 | func startSummaryEvaluation() { |
| 47 | - go func() { | ||
| 48 | - duration := 10 * time.Minute | ||
| 49 | - if constant.Env != "prd" { | ||
| 50 | - duration = 1 * time.Minute | ||
| 51 | - } | ||
| 52 | - timer := time.NewTimer(duration) | ||
| 53 | - for { | ||
| 54 | - <-timer.C | ||
| 55 | - err := serviceSummary.TaskSendSummaryEvaluation() | ||
| 56 | - if err != nil { | ||
| 57 | - log.Logger.Error(err.Error()) | ||
| 58 | - } | ||
| 59 | - timer.Reset(duration) // 重置定时 | ||
| 60 | - } | ||
| 61 | - }() | 47 | + go notify.RunTaskSmsNotify() |
| 62 | } | 48 | } |
| @@ -2,10 +2,11 @@ package service | @@ -2,10 +2,11 @@ package service | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" | ||
| 6 | "strconv" | 5 | "strconv" |
| 7 | "time" | 6 | "time" |
| 8 | 7 | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" | ||
| 9 | + | ||
| 9 | "github.com/linmadan/egglib-go/core/application" | 10 | "github.com/linmadan/egglib-go/core/application" |
| 10 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | 11 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" |
| 11 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command" | 12 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command" |
| @@ -153,7 +154,7 @@ func (rs *NodeTaskService) SendEvaluationNode() error { | @@ -153,7 +154,7 @@ func (rs *NodeTaskService) SendEvaluationNode() error { | ||
| 153 | // 创建发送任务 | 154 | // 创建发送任务 |
| 154 | _, err := staffAssessService.CreateStaffAssessTask(transactionContext, csat) | 155 | _, err := staffAssessService.CreateStaffAssessTask(transactionContext, csat) |
| 155 | if err != nil { | 156 | if err != nil { |
| 156 | - return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 157 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建发送任务"+err.Error()) |
| 157 | } | 158 | } |
| 158 | } else { | 159 | } else { |
| 159 | task.NextSentAt = nil // 项目不存在,取消周期任务发送 | 160 | task.NextSentAt = nil // 项目不存在,取消周期任务发送 |
| @@ -2,14 +2,14 @@ package notify | @@ -2,14 +2,14 @@ package notify | ||
| 2 | 2 | ||
| 3 | import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 3 | import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
| 4 | 4 | ||
| 5 | -var TaskSmsNotify *notifySms | 5 | +var taskSmsNotify *notifySms |
| 6 | 6 | ||
| 7 | func RunTaskSmsNotify() { | 7 | func RunTaskSmsNotify() { |
| 8 | - newSmsNotify := notifySms{} | ||
| 9 | - newSmsNotify.regist(notifyStaffAssess{}) | ||
| 10 | - newSmsNotify.regist(notifySummaryEvaluation{}) | ||
| 11 | - | ||
| 12 | - newSmsNotify.runTask() | 8 | + taskSmsNotify = ¬ifySms{} |
| 9 | + taskSmsNotify.init() | ||
| 10 | + taskSmsNotify.regist(notifyStaffAssess{}) | ||
| 11 | + taskSmsNotify.regist(notifySummaryEvaluation{}) | ||
| 12 | + taskSmsNotify.runTask() | ||
| 13 | 13 | ||
| 14 | } | 14 | } |
| 15 | 15 | ||
| @@ -17,12 +17,12 @@ func RunTaskSmsNotify() { | @@ -17,12 +17,12 @@ func RunTaskSmsNotify() { | ||
| 17 | func AddNotifyStaffAssess(param *domain.StaffAssess) { | 17 | func AddNotifyStaffAssess(param *domain.StaffAssess) { |
| 18 | newNotify := notifyStaffAssess{} | 18 | newNotify := notifyStaffAssess{} |
| 19 | newSms := newNotify.makeNotify(param) | 19 | newSms := newNotify.makeNotify(param) |
| 20 | - TaskSmsNotify.addTask(newSms) | 20 | + taskSmsNotify.addTask(newSms) |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | // 周期自评短信通知 ,预创建待发送的短信消息 | 23 | // 周期自评短信通知 ,预创建待发送的短信消息 |
| 24 | func AddNotifySummaryEvaluation(param *domain.SummaryEvaluation) { | 24 | func AddNotifySummaryEvaluation(param *domain.SummaryEvaluation) { |
| 25 | newNotify := notifySummaryEvaluation{} | 25 | newNotify := notifySummaryEvaluation{} |
| 26 | newSms := newNotify.makeNotify(param) | 26 | newSms := newNotify.makeNotify(param) |
| 27 | - TaskSmsNotify.addTask(newSms) | 27 | + taskSmsNotify.addTask(newSms) |
| 28 | } | 28 | } |
| @@ -42,7 +42,6 @@ func (notices *notifySms) addTask(task *domain.LogSms) { | @@ -42,7 +42,6 @@ func (notices *notifySms) addTask(task *domain.LogSms) { | ||
| 42 | 42 | ||
| 43 | // RunTask 执行短信通知任务 | 43 | // RunTask 执行短信通知任务 |
| 44 | func (notices *notifySms) runTask() { | 44 | func (notices *notifySms) runTask() { |
| 45 | - notices.init() | ||
| 46 | timer := time.NewTimer(notices.interval) | 45 | timer := time.NewTimer(notices.interval) |
| 47 | for { | 46 | for { |
| 48 | select { | 47 | select { |
| @@ -64,6 +63,7 @@ func (notices *notifySms) runTask() { | @@ -64,6 +63,7 @@ func (notices *notifySms) runTask() { | ||
| 64 | } | 63 | } |
| 65 | } | 64 | } |
| 66 | 65 | ||
| 66 | +// addNewSms 添加新的通知消息 | ||
| 67 | func (notices *notifySms) addNewSms(newSms *domain.LogSms) error { | 67 | func (notices *notifySms) addNewSms(newSms *domain.LogSms) error { |
| 68 | transactionContext, err := factory.CreateTransactionContext(nil) | 68 | transactionContext, err := factory.CreateTransactionContext(nil) |
| 69 | if err != nil { | 69 | if err != nil { |
| @@ -86,6 +86,7 @@ func (notices *notifySms) addNewSms(newSms *domain.LogSms) error { | @@ -86,6 +86,7 @@ func (notices *notifySms) addNewSms(newSms *domain.LogSms) error { | ||
| 86 | return nil | 86 | return nil |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | +// checkSendSms 检查发送短信通知 | ||
| 89 | func (notices *notifySms) checkSendSms() error { | 90 | func (notices *notifySms) checkSendSms() error { |
| 90 | transactionContext, err := factory.CreateTransactionContext(nil) | 91 | transactionContext, err := factory.CreateTransactionContext(nil) |
| 91 | if err != nil { | 92 | if err != nil { |
| @@ -122,7 +123,11 @@ func (notices *notifySms) checkSendSms() error { | @@ -122,7 +123,11 @@ func (notices *notifySms) checkSendSms() error { | ||
| 122 | return nil | 123 | return nil |
| 123 | } | 124 | } |
| 124 | 125 | ||
| 126 | +// sendSms 发送短信消息 | ||
| 125 | func (notices *notifySms) sendSms(param *domain.LogSms) error { | 127 | func (notices *notifySms) sendSms(param *domain.LogSms) error { |
| 128 | + if constant.Env != "prd" { | ||
| 129 | + return nil | ||
| 130 | + } | ||
| 126 | //单开处理 数据保存操作,发一条短信更新一条数据 | 131 | //单开处理 数据保存操作,发一条短信更新一条数据 |
| 127 | transactionContext, err := factory.CreateTransactionContext(nil) | 132 | transactionContext, err := factory.CreateTransactionContext(nil) |
| 128 | if err != nil { | 133 | if err != nil { |
| @@ -7,7 +7,6 @@ import ( | @@ -7,7 +7,6 @@ import ( | ||
| 7 | 7 | ||
| 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" |
| 9 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify" | 9 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify" |
| 10 | - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" | ||
| 11 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
| 12 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" | 11 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" |
| 13 | ) | 12 | ) |
| @@ -278,9 +277,6 @@ func TaskSendSummaryEvaluation() error { | @@ -278,9 +277,6 @@ func TaskSendSummaryEvaluation() error { | ||
| 278 | 277 | ||
| 279 | // 发送短信通知 | 278 | // 发送短信通知 |
| 280 | func sendSmsEvalation(param []domain.SummaryEvaluation) error { | 279 | func sendSmsEvalation(param []domain.SummaryEvaluation) error { |
| 281 | - if constant.Env != "prd" { | ||
| 282 | - return nil | ||
| 283 | - } | ||
| 284 | for i := range param { | 280 | for i := range param { |
| 285 | notify.AddNotifySummaryEvaluation(¶m[i]) | 281 | notify.AddNotifySummaryEvaluation(¶m[i]) |
| 286 | } | 282 | } |
-
请 注册 或 登录 后发表评论