正在显示
5 个修改的文件
包含
50 行增加
和
6 行删除
@@ -40,7 +40,8 @@ func startNodeTask() { | @@ -40,7 +40,8 @@ func startNodeTask() { | ||
40 | timer := time.NewTimer(duration) | 40 | timer := time.NewTimer(duration) |
41 | for { | 41 | for { |
42 | <-timer.C | 42 | <-timer.C |
43 | - if err := nodeTaskService.SendEvaluationNode(); err != nil { | 43 | + nowTime := time.Now() |
44 | + if err := nodeTaskService.SendEvaluationNode(nowTime); err != nil { | ||
44 | log.Logger.Error(err.Error()) | 45 | log.Logger.Error(err.Error()) |
45 | } | 46 | } |
46 | timer.Reset(duration) // 重置定时 | 47 | timer.Reset(duration) // 重置定时 |
@@ -24,7 +24,7 @@ func NewNodeTaskService() *NodeTaskService { | @@ -24,7 +24,7 @@ func NewNodeTaskService() *NodeTaskService { | ||
24 | } | 24 | } |
25 | 25 | ||
26 | // SendEvaluationNode 发送评估环节 | 26 | // SendEvaluationNode 发送评估环节 |
27 | -func (rs *NodeTaskService) SendEvaluationNode() error { | 27 | +func (rs *NodeTaskService) SendEvaluationNode(nowTime time.Time) error { |
28 | transactionContext, err := factory.StartTransaction() | 28 | transactionContext, err := factory.StartTransaction() |
29 | if err != nil { | 29 | if err != nil { |
30 | return err | 30 | return err |
@@ -37,7 +37,7 @@ func (rs *NodeTaskService) SendEvaluationNode() error { | @@ -37,7 +37,7 @@ func (rs *NodeTaskService) SendEvaluationNode() error { | ||
37 | } | 37 | } |
38 | }() | 38 | }() |
39 | taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext}) | 39 | taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext}) |
40 | - tasks, err := taskRepository.Find(map[string]interface{}{"lessNextSentAt": time.Now().Local()}) | 40 | + tasks, err := taskRepository.Find(map[string]interface{}{"lessNextSentAt": nowTime}) |
41 | if err != nil { | 41 | if err != nil { |
42 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 42 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
43 | } | 43 | } |
pkg/application/node_task/node_task_test.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "testing" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +func TestSendEvaluationNode(t *testing.T) { | ||
9 | + // nowTime, _ := time.ParseInLocation("2006-01-02 15:04:05", "2023-05-12 23:00:00", time.Local) | ||
10 | + // nowTime, _ := time.ParseInLocation("2006-01-02 15:04:05", "2023-05-13 23:00:00", time.Local) | ||
11 | + nowTime, _ := time.ParseInLocation("2006-01-02 15:04:05", "2023-05-14 23:00:00", time.Local) | ||
12 | + // nowTime, _ := time.ParseInLocation("2006-01-02 15:04:05", "2023-05-10 23:00:00", time.Local) | ||
13 | + // nowTime, _ := time.ParseInLocation("2006-01-02 15:04:05", "2023-05-10 23:00:00", time.Local) | ||
14 | + srv := NewNodeTaskService() | ||
15 | + err := srv.SendEvaluationNode(nowTime) | ||
16 | + if err != nil { | ||
17 | + t.Error(err) | ||
18 | + } | ||
19 | +} |
@@ -23,7 +23,8 @@ func CheckYesterdayTaskRecord() { | @@ -23,7 +23,8 @@ func CheckYesterdayTaskRecord() { | ||
23 | timer := time.NewTimer(interval) | 23 | timer := time.NewTimer(interval) |
24 | for { | 24 | for { |
25 | <-timer.C | 25 | <-timer.C |
26 | - taskRecordList, err := getYesterdayTaskRecord() | 26 | + nowDay := time.Now().Format("2006-01-02") |
27 | + taskRecordList, err := getYesterdayTaskRecord(nowDay) | ||
27 | if err != nil { | 28 | if err != nil { |
28 | log.Logger.Info("获取每日任务反馈" + err.Error()) | 29 | log.Logger.Info("获取每日任务反馈" + err.Error()) |
29 | } | 30 | } |
@@ -77,7 +78,7 @@ func checkTaskRecord(param *domain.TaskRecord) error { | @@ -77,7 +78,7 @@ func checkTaskRecord(param *domain.TaskRecord) error { | ||
77 | return nil | 78 | return nil |
78 | } | 79 | } |
79 | 80 | ||
80 | -func getYesterdayTaskRecord() ([]*domain.TaskRecord, error) { | 81 | +func getYesterdayTaskRecord(nowDay string) ([]*domain.TaskRecord, error) { |
81 | transactionContext, err := factory.CreateTransactionContext(nil) | 82 | transactionContext, err := factory.CreateTransactionContext(nil) |
82 | if err != nil { | 83 | if err != nil { |
83 | return nil, err | 84 | return nil, err |
@@ -89,7 +90,7 @@ func getYesterdayTaskRecord() ([]*domain.TaskRecord, error) { | @@ -89,7 +90,7 @@ func getYesterdayTaskRecord() ([]*domain.TaskRecord, error) { | ||
89 | _ = transactionContext.RollbackTransaction() | 90 | _ = transactionContext.RollbackTransaction() |
90 | }() | 91 | }() |
91 | 92 | ||
92 | - nowDay := time.Now().Format("2006-01-02") | 93 | + // nowDay := time.Now().Format("2006-01-02") |
93 | nowDayTime, _ := time.ParseInLocation("2006-01-02", nowDay, time.Local) | 94 | nowDayTime, _ := time.ParseInLocation("2006-01-02", nowDay, time.Local) |
94 | yesterday := nowDayTime.Add(-23 * time.Hour).Format("2006-01-02") | 95 | yesterday := nowDayTime.Add(-23 * time.Hour).Format("2006-01-02") |
95 | 96 |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "testing" | ||
5 | +) | ||
6 | + | ||
7 | +func TestCheckYesterdayTaskRecord(t *testing.T) { | ||
8 | + // nowDay := "2023-05-10" | ||
9 | + // nowDay := "2023-05-11" | ||
10 | + // nowDay := "2023-05-12" | ||
11 | + // nowDay := "2023-05-13" | ||
12 | + nowDay := "2023-05-14" | ||
13 | + taskRecordList, err := getYesterdayTaskRecord(nowDay) | ||
14 | + if err != nil { | ||
15 | + t.Log("获取每日任务反馈" + err.Error()) | ||
16 | + } | ||
17 | + for _, val := range taskRecordList { | ||
18 | + err = checkTaskRecord(val) | ||
19 | + if err != nil { | ||
20 | + t.Log("检查每日任务反馈" + err.Error()) | ||
21 | + } | ||
22 | + } | ||
23 | +} |
-
请 注册 或 登录 后发表评论