优化结构
This commit is contained in:
@@ -127,6 +127,9 @@ func taskLogFromPO(v taskLogPO) *taskbiz.TimedTaskLog {
|
||||
return &taskbiz.TimedTaskLog{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, TaskID: v.TaskID, TaskName: v.TaskName, TriggerType: v.TriggerType, StartedAt: v.StartedAt, FinishedAt: v.FinishedAt, DurationMS: v.DurationMS, Status: v.Status, ErrorMsg: v.ErrorMsg, Output: v.Output}
|
||||
}
|
||||
func (r *taskRepo) ListTaskLogs(ctx context.Context, page, size int, taskID uint, status string) ([]*taskbiz.TimedTaskLog, int64, error) {
|
||||
if !r.data.DatabaseReady() {
|
||||
return []*taskbiz.TimedTaskLog{}, 0, nil
|
||||
}
|
||||
db := r.data.DB().WithContext(ctx).Model(&taskLogPO{})
|
||||
if taskID != 0 {
|
||||
db = db.Where("task_id = ?", taskID)
|
||||
|
||||
@@ -15,3 +15,14 @@ func TestTaskRepoListIsEmptyBeforeDatabaseInitialization(t *testing.T) {
|
||||
t.Fatalf("bootstrap tasks = (%d, %d), want empty", total, len(items))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskRepoLogsAreEmptyBeforeDatabaseInitialization(t *testing.T) {
|
||||
repo := NewTaskRepo(&Data{})
|
||||
items, total, err := repo.ListTaskLogs(context.Background(), 0, 0, 0, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if total != 0 || len(items) != 0 {
|
||||
t.Fatalf("bootstrap task logs = (%d, %d), want empty", total, len(items))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user