forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_task.go
57 lines (44 loc) · 1.16 KB
/
get_task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package action
import (
"errors"
boshtask "github.com/cloudfoundry/bosh-agent/agent/task"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type GetTaskAction struct {
taskService boshtask.Service
}
func NewGetTask(taskService boshtask.Service) (getTask GetTaskAction) {
getTask.taskService = taskService
return
}
func (a GetTaskAction) IsAsynchronous(_ ProtocolVersion) bool {
return false
}
func (a GetTaskAction) IsPersistent() bool {
return false
}
func (a GetTaskAction) IsLoggable() bool {
return true
}
func (a GetTaskAction) Run(taskID string) (interface{}, error) {
task, found := a.taskService.FindTaskWithID(taskID)
if !found {
return nil, bosherr.Errorf("Task with id %s could not be found", taskID)
}
if task.State == boshtask.StateRunning {
return boshtask.StateValue{
AgentTaskID: task.ID,
State: task.State,
}, nil
}
if task.Error != nil {
return task.Value, bosherr.WrapErrorf(task.Error, "Task %s result", taskID)
}
return task.Value, nil
}
func (a GetTaskAction) Resume() (interface{}, error) {
return nil, errors.New("not supported")
}
func (a GetTaskAction) Cancel() error {
return errors.New("not supported")
}