作者 tangxvhui

更新定时任务

... ... @@ -7,7 +7,7 @@ import (
"github.com/beego/beego/v2/server/web"
serviceTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task"
serviceSummary "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/service"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
_ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer"
... ... @@ -44,19 +44,5 @@ func startNodeTask() {
// 定时任务-间隔检查时间,发送周期评估
func startSummaryEvaluation() {
go func() {
duration := 10 * time.Minute
if constant.Env != "prd" {
duration = 1 * time.Minute
}
timer := time.NewTimer(duration)
for {
<-timer.C
err := serviceSummary.TaskSendSummaryEvaluation()
if err != nil {
log.Logger.Error(err.Error())
}
timer.Reset(duration) // 重置定时
}
}()
go notify.RunTaskSmsNotify()
}
... ...
... ... @@ -2,10 +2,11 @@ package service
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
"strconv"
"time"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
... ... @@ -153,7 +154,7 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
// 创建发送任务
_, err := staffAssessService.CreateStaffAssessTask(transactionContext, csat)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建发送任务"+err.Error())
}
} else {
task.NextSentAt = nil // 项目不存在,取消周期任务发送
... ...
... ... @@ -2,14 +2,14 @@ package notify
import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
var TaskSmsNotify *notifySms
var taskSmsNotify *notifySms
func RunTaskSmsNotify() {
newSmsNotify := notifySms{}
newSmsNotify.regist(notifyStaffAssess{})
newSmsNotify.regist(notifySummaryEvaluation{})
newSmsNotify.runTask()
taskSmsNotify = &notifySms{}
taskSmsNotify.init()
taskSmsNotify.regist(notifyStaffAssess{})
taskSmsNotify.regist(notifySummaryEvaluation{})
taskSmsNotify.runTask()
}
... ... @@ -17,12 +17,12 @@ func RunTaskSmsNotify() {
func AddNotifyStaffAssess(param *domain.StaffAssess) {
newNotify := notifyStaffAssess{}
newSms := newNotify.makeNotify(param)
TaskSmsNotify.addTask(newSms)
taskSmsNotify.addTask(newSms)
}
// 周期自评短信通知 ,预创建待发送的短信消息
func AddNotifySummaryEvaluation(param *domain.SummaryEvaluation) {
newNotify := notifySummaryEvaluation{}
newSms := newNotify.makeNotify(param)
TaskSmsNotify.addTask(newSms)
taskSmsNotify.addTask(newSms)
}
... ...
... ... @@ -42,7 +42,6 @@ func (notices *notifySms) addTask(task *domain.LogSms) {
// RunTask 执行短信通知任务
func (notices *notifySms) runTask() {
notices.init()
timer := time.NewTimer(notices.interval)
for {
select {
... ... @@ -64,6 +63,7 @@ func (notices *notifySms) runTask() {
}
}
// addNewSms 添加新的通知消息
func (notices *notifySms) addNewSms(newSms *domain.LogSms) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -86,6 +86,7 @@ func (notices *notifySms) addNewSms(newSms *domain.LogSms) error {
return nil
}
// checkSendSms 检查发送短信通知
func (notices *notifySms) checkSendSms() error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -122,7 +123,11 @@ func (notices *notifySms) checkSendSms() error {
return nil
}
// sendSms 发送短信消息
func (notices *notifySms) sendSms(param *domain.LogSms) error {
if constant.Env != "prd" {
return nil
}
//单开处理 数据保存操作,发一条短信更新一条数据
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ...
... ... @@ -7,7 +7,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
)
... ... @@ -278,9 +277,6 @@ func TaskSendSummaryEvaluation() error {
// 发送短信通知
func sendSmsEvalation(param []domain.SummaryEvaluation) error {
if constant.Env != "prd" {
return nil
}
for i := range param {
notify.AddNotifySummaryEvaluation(&param[i])
}
... ...