-
Notifications
You must be signed in to change notification settings - Fork 28
/
service_task_acc.go
68 lines (57 loc) · 1.78 KB
/
service_task_acc.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
package aiven
import (
"context"
"time"
)
type (
// ServiceTaskHandler Aiven go-client handler for Service tesks
ServiceTaskHandler struct {
client *Client
}
// ServiceTaskResponse represents service task response
ServiceTaskResponse struct {
APIResponse
Task ServiceTask `json:"task"`
}
// ServiceTask represents a service task
ServiceTask struct {
CreateTime *time.Time `json:"create_time"`
Result string `json:"result"`
TaskType string `json:"task_type"`
Success *bool `json:"success"`
SourcePgVersion string `json:"source_pg_version,omitempty"`
TargetPgVersion string `json:"target_pg_version,omitempty"`
Id string `json:"task_id,omitempty"`
}
// ServiceTaskRequest represents service task request
ServiceTaskRequest struct {
TargetVersion string `json:"target_version"`
TaskType string `json:"task_type"`
}
)
// Create creates a bew service task
func (h ServiceTaskHandler) Create(ctx context.Context, project, service string, r ServiceTaskRequest) (*ServiceTaskResponse, error) {
path := buildPath("project", project, "service", service, "task")
bts, err := h.client.doPostRequest(ctx, path, r)
if err != nil {
return nil, err
}
var rsp ServiceTaskResponse
if errR := checkAPIResponse(bts, &rsp); errR != nil {
return nil, errR
}
return &rsp, nil
}
// Get retrieves a new service task
func (h ServiceTaskHandler) Get(ctx context.Context, project, service, id string) (*ServiceTaskResponse, error) {
path := buildPath("project", project, "service", service, "task", id)
bts, err := h.client.doGetRequest(ctx, path, nil)
if err != nil {
return nil, err
}
var rsp ServiceTaskResponse
if errR := checkAPIResponse(bts, &rsp); errR != nil {
return nil, errR
}
return &rsp, nil
}