Merge pull request #7264 from mmpei/replication_ng_bugfix_endtime

Fix execution end time bug
This commit is contained in:
Wenkai Yin 2019-04-01 16:09:16 +08:00 committed by GitHub
commit d6eb700077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -171,7 +171,18 @@ func updateStatusCount(execution *models.Execution, status string, delta int) er
func resetExecutionStatus(execution *models.Execution) error {
execution.Status = generateStatus(execution)
if executionFinished(execution.Status) {
execution.EndTime = time.Now()
o := dao.GetOrmer()
sql := `select max(end_time) from replication_task where execution_id = ?`
queryParam := make([]interface{}, 1)
queryParam = append(queryParam, execution.ID)
var et time.Time
err := o.Raw(sql, queryParam).QueryRow(&et)
if err != nil {
log.Errorf("Query end_time from tasks error execution %d: %v", execution.ID, err)
et = time.Now()
}
execution.EndTime = et
}
return nil
}

View File

@ -179,6 +179,8 @@ func TestExecutionFill(t *testing.T) {
StartTime: time.Now(),
}
executionID, _ := AddExecution(execution)
et1, _ := time.Parse("2016-01-02 15:04:05", "2019-03-21 08:01:01")
et2, _ := time.Parse("2016-01-02 15:04:05", "2019-04-01 10:11:53")
task1 := &models.Task{
ID: 20191,
ExecutionID: executionID,
@ -188,6 +190,7 @@ func TestExecutionFill(t *testing.T) {
JobID: "jobID1",
Status: "Succeed",
StartTime: time.Now(),
EndTime: et1,
}
task2 := &models.Task{
ID: 20192,
@ -198,7 +201,7 @@ func TestExecutionFill(t *testing.T) {
JobID: "jobID2",
Status: "Stopped",
StartTime: time.Now(),
EndTime: time.Now(),
EndTime: et2,
}
AddTask(task1)
AddTask(task2)
@ -216,6 +219,7 @@ func TestExecutionFill(t *testing.T) {
assert.Equal(t, 1, exe.Stopped)
assert.Equal(t, 0, exe.Failed)
assert.Equal(t, 1, exe.Succeed)
assert.Equal(t, et2.Second(), exe.EndTime.Second())
}
func TestExecutionFill2(t *testing.T) {