-
Notifications
You must be signed in to change notification settings - Fork 932
/
Copy pathtask.go
79 lines (65 loc) · 2.25 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package ccv3
import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
"code.cloudfoundry.org/cli/resources"
)
// CreateApplication resources.Task runs a command in the Application environment
// associated with the provided Application GUID.
func (client *Client) CreateApplicationTask(appGUID string, task resources.Task) (resources.Task, Warnings, error) {
var responseBody resources.Task
_, warnings, err := client.MakeRequest(RequestParams{
RequestName: internal.PostApplicationTasksRequest,
URIParams: internal.Params{"app_guid": appGUID},
RequestBody: task,
ResponseBody: &responseBody,
})
return responseBody, warnings, err
}
// GetApplicationTasks returns a list of tasks associated with the provided
// application GUID. Results can be filtered by providing URL queries.
func (client *Client) GetApplicationTasks(appGUID string, query ...Query) ([]resources.Task, Warnings, error) {
var tasks []resources.Task
foundPerPageQuery := false
for _, keyVal := range query {
if keyVal.Key == PerPage {
foundPerPageQuery = true
}
}
if !foundPerPageQuery {
query = append(query, Query{Key: PerPage, Values: []string{MaxPerPage}})
}
_, warnings, err := client.MakeListRequest(RequestParams{
RequestName: internal.GetApplicationTasksRequest,
URIParams: internal.Params{"app_guid": appGUID},
Query: query,
ResponseBody: resources.Task{},
AppendToList: func(item interface{}) error {
tasks = append(tasks, item.(resources.Task))
return nil
},
})
return tasks, warnings, err
}
// UpdateTaskCancel cancels a task.
func (client *Client) UpdateTaskCancel(taskGUID string) (resources.Task, Warnings, error) {
var responseBody resources.Task
_, warnings, err := client.MakeRequest(RequestParams{
RequestName: internal.PutTaskCancelRequest,
URIParams: internal.Params{
"task_guid": taskGUID,
},
ResponseBody: &responseBody,
})
return responseBody, warnings, err
}
func (client *Client) GetTask(guid string) (resources.Task, Warnings, error) {
var responseBody resources.Task
_, warnings, err := client.MakeRequest(RequestParams{
RequestName: internal.GetTaskRequest,
URIParams: internal.Params{
"task_guid": guid,
},
ResponseBody: &responseBody,
})
return responseBody, warnings, err
}