GetTasksWithLastStatus returns task list of the pipeline, only the most recently tasks would be returned TODO: adopts GetLatestTasksOfPipeline
(pipelineId uint64, shouldSanitize bool, tx dal.Dal)
| 112 | // GetTasksWithLastStatus returns task list of the pipeline, only the most recently tasks would be returned |
| 113 | // TODO: adopts GetLatestTasksOfPipeline |
| 114 | func GetTasksWithLastStatus(pipelineId uint64, shouldSanitize bool, tx dal.Dal) ([]*models.Task, errors.Error) { |
| 115 | if tx == nil { |
| 116 | tx = db |
| 117 | } |
| 118 | var tasks []*models.Task |
| 119 | err := tx.All(&tasks, dal.Where("pipeline_id = ?", pipelineId), dal.Orderby("id DESC")) |
| 120 | if err != nil { |
| 121 | return nil, err |
| 122 | } |
| 123 | taskIds := make(map[int64]struct{}) |
| 124 | var result []*models.Task |
| 125 | var maxRow, maxCol int |
| 126 | for _, task := range tasks { |
| 127 | if task.PipelineRow > maxRow { |
| 128 | maxRow = task.PipelineRow |
| 129 | } |
| 130 | if task.PipelineCol > maxCol { |
| 131 | maxCol = task.PipelineCol |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | for _, task := range tasks { |
| 136 | index := int64(task.PipelineRow)*int64(maxCol) + int64(task.PipelineCol) |
| 137 | if shouldSanitize { |
| 138 | taskOption, err := SanitizePluginOption(task.Plugin, task.Options) |
| 139 | if err != nil { |
| 140 | return nil, errors.Convert(err) |
| 141 | } |
| 142 | task.Options = taskOption |
| 143 | } |
| 144 | if _, ok := taskIds[index]; !ok { |
| 145 | taskIds[index] = struct{}{} |
| 146 | result = append(result, task) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | runningTasks.FillProgressDetailToTasks(result) |
| 151 | return result, nil |
| 152 | } |
| 153 | |
| 154 | // GetTask FIXME ... |
| 155 | func GetTask(taskId uint64) (*models.Task, errors.Error) { |
no test coverage detected