Not use time pointer in model fields

Signed-off-by: cd1989 <chende@caicloud.io>
This commit is contained in:
cd1989 2019-09-06 17:48:08 +08:00
parent a031e86dba
commit 8990a621d6
5 changed files with 26 additions and 26 deletions

View File

@ -228,7 +228,7 @@ func UpdateExecution(execution *models.Execution, props ...string) (int64, error
func AddTask(task *models.Task) (int64, error) {
o := dao.GetOrmer()
now := time.Now()
task.StartTime = &now
task.StartTime = now
return o.Insert(task)
}

View File

@ -100,7 +100,7 @@ func TestMethodOfTask(t *testing.T) {
JobID: "jobID1",
Status: "Initialized",
StatusRevision: 1,
StartTime: &now,
StartTime: now,
}
task2 := &models.Task{
ExecutionID: 112200,
@ -110,8 +110,8 @@ func TestMethodOfTask(t *testing.T) {
JobID: "jobID2",
Status: "Stopped",
StatusRevision: 1,
StartTime: &now,
EndTime: &now,
StartTime: now,
EndTime: now,
}
// test add
@ -146,7 +146,7 @@ func TestMethodOfTask(t *testing.T) {
taskNew := &models.Task{
ID: id1,
Status: "Failed",
EndTime: &now,
EndTime: now,
}
n, err := UpdateTask(taskNew, models.TaskPropsName.Status, models.TaskPropsName.EndTime)
require.Nil(t, err)
@ -195,8 +195,8 @@ func TestExecutionFill(t *testing.T) {
DstResource: "dstResource1",
JobID: "jobID1",
Status: "Succeed",
StartTime: &now,
EndTime: &et1,
StartTime: now,
EndTime: et1,
}
task2 := &models.Task{
ID: 20192,
@ -206,8 +206,8 @@ func TestExecutionFill(t *testing.T) {
DstResource: "dstResource2",
JobID: "jobID2",
Status: "Stopped",
StartTime: &now,
EndTime: &et2,
StartTime: now,
EndTime: et2,
}
AddTask(task1)
AddTask(task2)
@ -248,7 +248,7 @@ func TestExecutionFill2(t *testing.T) {
JobID: "jobID1",
Status: models.TaskStatusInProgress,
StatusRevision: 1,
StartTime: &now,
StartTime: now,
}
task2 := &models.Task{
ID: 20192,
@ -259,8 +259,8 @@ func TestExecutionFill2(t *testing.T) {
JobID: "jobID2",
Status: "Stopped",
StatusRevision: 1,
StartTime: &now,
EndTime: &now,
StartTime: now,
EndTime: now,
}
taskID1, _ := AddTask(task1)
AddTask(task2)

View File

@ -109,17 +109,17 @@ type TaskFieldsName struct {
// Task represent the tasks in one execution.
type Task struct {
ID int64 `orm:"pk;auto;column(id)" json:"id"`
ExecutionID int64 `orm:"column(execution_id)" json:"execution_id"`
ResourceType string `orm:"column(resource_type)" json:"resource_type"`
SrcResource string `orm:"column(src_resource)" json:"src_resource"`
DstResource string `orm:"column(dst_resource)" json:"dst_resource"`
Operation string `orm:"column(operation)" json:"operation"`
JobID string `orm:"column(job_id)" json:"job_id"`
Status string `orm:"column(status)" json:"status"`
StatusRevision int64 `orm:"column(status_revision)"`
StartTime *time.Time `orm:"column(start_time)" json:"start_time"`
EndTime *time.Time `orm:"column(end_time)" json:"end_time,omitempty"`
ID int64 `orm:"pk;auto;column(id)" json:"id"`
ExecutionID int64 `orm:"column(execution_id)" json:"execution_id"`
ResourceType string `orm:"column(resource_type)" json:"resource_type"`
SrcResource string `orm:"column(src_resource)" json:"src_resource"`
DstResource string `orm:"column(dst_resource)" json:"dst_resource"`
Operation string `orm:"column(operation)" json:"operation"`
JobID string `orm:"column(job_id)" json:"job_id"`
Status string `orm:"column(status)" json:"status"`
StatusRevision int64 `orm:"column(status_revision)"`
StartTime time.Time `orm:"column(start_time)" json:"start_time"`
EndTime time.Time `orm:"column(end_time)" json:"end_time,omitempty"`
}
// TableName is required by by beego orm to map Execution to table replication_execution

View File

@ -83,7 +83,7 @@ func TestMethodOfTaskManager(t *testing.T) {
JobID: "jobID1",
Status: "Initialized",
StatusRevision: 1,
StartTime: &now,
StartTime: now,
}
defer func() {

View File

@ -285,7 +285,7 @@ func schedule(scheduler scheduler.Scheduler, executionMgr execution.Manager, ite
if err = executionMgr.UpdateTask(&models.Task{
ID: result.TaskID,
Status: models.TaskStatusFailed,
EndTime: &now,
EndTime: now,
}, "Status", "EndTime"); err != nil {
log.Errorf("failed to update the task status %d: %v", result.TaskID, err)
}
@ -299,7 +299,7 @@ func schedule(scheduler scheduler.Scheduler, executionMgr execution.Manager, ite
if err = executionMgr.UpdateTask(&models.Task{
ID: result.TaskID,
JobID: result.JobID,
StartTime: &now,
StartTime: now,
}, "JobID", "StartTime"); err != nil {
log.Errorf("failed to update the task %d: %v", result.TaskID, err)
}