作者 tangxvhui

更新

... ... @@ -40,10 +40,12 @@ func startNodeTask() {
duration = time.Minute * 1
}
timer := time.NewTimer(duration)
var nowTime time.Time
var err error
for {
<-timer.C
nowTime := time.Now()
if err := nodeTaskService.SendEvaluationNode(nowTime); err != nil {
nowTime = time.Now()
if err = nodeTaskService.SendEvaluationNode(nowTime); err != nil {
log.Logger.Error(err.Error())
}
timer.Reset(duration) // 重置定时
... ... @@ -61,9 +63,10 @@ func startSummaryEvaluation() {
duration = time.Minute * 1
}
timer := time.NewTimer(duration)
var err error
for {
<-timer.C
if err := serviceSummary.TaskSendSummaryEvaluationV2(); err != nil {
if err = serviceSummary.TaskSendSummaryEvaluationV2(); err != nil {
log.Logger.Error(err.Error())
}
timer.Reset(duration) // 重置定时
... ... @@ -81,9 +84,10 @@ func startConfirmEvaluationScore() {
duration = time.Minute * 1
}
timer := time.NewTimer(duration)
var err error
for {
<-timer.C
if err := serviceSummary.TaskConfirmScore(); err != nil {
if err = serviceSummary.TaskConfirmScore(); err != nil {
log.Logger.Error(err.Error())
}
timer.Reset(duration) // 重置定时
... ...
package service
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
"time"
... ... @@ -21,12 +19,18 @@ func CheckYesterdayTaskRecord() {
interval = (24 * time.Hour) + interval
}
timer := time.NewTimer(interval)
var (
nowDay string
err error
taskRecordList []*domain.TaskRecord
)
for {
<-timer.C
nowDay := time.Now().Format("2006-01-02")
taskRecordList, err := getYesterdayTaskRecord(nowDay)
nowDay = time.Now().Format("2006-01-02")
taskRecordList, err = getYesterdayTaskRecord(nowDay)
if err != nil {
log.Logger.Info("获取每日任务反馈" + err.Error())
log.Logger.Error("获取每日任务反馈" + err.Error())
continue
}
for _, val := range taskRecordList {
err = checkTaskRecordV3(val)
... ... @@ -39,44 +43,44 @@ func CheckYesterdayTaskRecord() {
}
func checkTaskRecord(param *domain.TaskRecord) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
}
if err := transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
// func checkTaskRecord(param *domain.TaskRecord) error {
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return err
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return err
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
// taskRepo := factory.CreateTaskRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
_, taskDataList, err := taskRepo.Find(map[string]interface{}{"id": param.TaskId})
if err != nil {
return fmt.Errorf("获取任务数据失败:%s", err)
}
if len(taskDataList) == 0 {
return nil
}
taskData := taskDataList[0]
if param.AnomalyState != domain.AnomalyState1 {
taskData.Anomaly += 1
} else {
taskData.Anomaly = 0
}
// _, taskDataList, err := taskRepo.Find(map[string]interface{}{"id": param.TaskId})
// if err != nil {
// return fmt.Errorf("获取任务数据失败:%s", err)
// }
// if len(taskDataList) == 0 {
// return nil
// }
// taskData := taskDataList[0]
// if param.AnomalyState != domain.AnomalyState1 {
// taskData.Anomaly += 1
// } else {
// taskData.Anomaly = 0
// }
err = taskRepo.Save(taskData)
if err != nil {
return fmt.Errorf("保存任务数据:%s", err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
// err = taskRepo.Save(taskData)
// if err != nil {
// return fmt.Errorf("保存任务数据:%s", err)
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return err
// }
// return nil
// }
func getYesterdayTaskRecord(nowDay string) ([]*domain.TaskRecord, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
... ...