-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcloud_database_tasks.go
62 lines (49 loc) · 1.43 KB
/
cloud_database_tasks.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
// This file is part of gobizfly
package gobizfly
import (
"context"
"encoding/json"
"net/http"
)
const (
cloudDatabaseTasksResourcePath = "/tasks"
)
type cloudDatabaseTasks struct {
client *Client
}
// CloudDatabaseTaskResult contains task result detail.
type CloudDatabaseTaskResult struct {
Action string `json:"action"`
Data map[string]interface{} `json:"data"`
Message string `json:"message"`
Progress int `json:"progress"`
}
// CloudDatabaseTask contains task result.
type CloudDatabaseTask struct {
Ready bool `json:"ready"`
Result CloudDatabaseTaskResult `json:"result"`
}
func (db *cloudDatabaseService) Tasks() *cloudDatabaseTasks {
return &cloudDatabaseTasks{client: db.client}
}
// CloudDatabase Task Resource Path
func (ta *cloudDatabaseTasks) resourcePath(taskID string) string {
return cloudDatabaseTasksResourcePath + "/" + taskID + "/status"
}
// Get a task status.
func (ta *cloudDatabaseTasks) Get(ctx context.Context, taskID string) (*CloudDatabaseTask, error) {
req, err := ta.client.NewRequest(ctx, http.MethodGet, databaseServiceName, ta.resourcePath(taskID), nil)
if err != nil {
return nil, err
}
resp, err := ta.client.Do(ctx, req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var task *CloudDatabaseTask
if err := json.NewDecoder(resp.Body).Decode(&task); err != nil {
return nil, err
}
return task, nil
}