DeleteTaskByID deletes given task from list. Only finished tasks can be deleted.
(ID int)
| 122 | // DeleteTaskByID deletes given task from list. Only finished |
| 123 | // tasks can be deleted. |
| 124 | func (list *List) DeleteTaskByID(ID int) (Task, error) { |
| 125 | list.Lock() |
| 126 | defer list.Unlock() |
| 127 | |
| 128 | tasks := list.tasks |
| 129 | for i, task := range tasks { |
| 130 | if task.ID == ID { |
| 131 | if task.State == SUCCEEDED || task.State == FAILED { |
| 132 | list.tasks = append(tasks[:i], tasks[i+1:]...) |
| 133 | return *task, nil |
| 134 | } |
| 135 | |
| 136 | return *task, fmt.Errorf("task with id %v is still in state=%d", ID, task.State) |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | return Task{}, fmt.Errorf("could not find task with id %v", ID) |
| 141 | } |
| 142 | |
| 143 | // GetTaskByID returns task with given id |
| 144 | func (list *List) GetTaskByID(ID int) (Task, error) { |
no outgoing calls