mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-25 10:07:43 +01:00
Merge pull request #7264 from mmpei/replication_ng_bugfix_endtime
Fix execution end time bug
This commit is contained in:
commit
d6eb700077
@ -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
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user