-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathqueue.go
97 lines (78 loc) · 1.97 KB
/
queue.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package cloud66
import "encoding/json"
type Queue struct {
Name string `json:"name"`
}
type AgentRegistration struct {
LogKey string `json:"log_key"`
AgentUUID string `json:"agent_uuid"`
}
func (c *Client) RegisterAgent() (*AgentRegistration, error) {
var payload = struct {
Hostname string `json:"host_name"`
}{
Hostname: c.Hostname,
}
req, err := c.NewRequest("POST", "/queues/register.json", payload, nil)
if err != nil {
return nil, err
}
var queueRes AgentRegistration
err = c.DoReq(req, &queueRes, nil)
if err != nil {
return nil, err
}
return &queueRes, nil
}
func (c *Client) GetQueues() ([]Queue, error) {
req, err := c.NewRequest("GET", "/queues.json", nil, nil)
if err != nil {
return nil, err
}
var queueRes []Queue
queueRes = nil
err = c.DoReq(req, &queueRes, nil)
if err != nil {
return nil, err
}
return queueRes, nil
}
func (c *Client) PopQueue(queueName string) (json.RawMessage, error) {
queryStrings := make(map[string]string)
queryStrings["host_name"] = c.Hostname
req, err := c.NewRequest("GET", "/queues/"+queueName+".json", nil, queryStrings)
if err != nil {
return nil, err
}
var queueRes json.RawMessage
err = c.DoReq(req, &queueRes, nil)
if err != nil {
return nil, err
}
return queueRes, nil
}
func (c *Client) UpdateQueue(queueName string, taskUUID string, state string, runResult string, sessionID string) (json.RawMessage, error) {
var payload = struct {
TaskUUID string `json:"task_uuid"`
State string `json:"state"`
RunResult string `json:"run_result"`
Hostname string `json:"host_name"`
SessionID string `json:"session_id"`
}{
TaskUUID: taskUUID,
State: state,
RunResult: runResult,
Hostname: c.Hostname,
SessionID: sessionID,
}
req, err := c.NewRequest("PUT", "/queues/"+queueName+".json", payload, nil)
if err != nil {
return nil, err
}
var queueRes json.RawMessage
err = c.DoReq(req, &queueRes, nil)
if err != nil {
return nil, err
}
return queueRes, nil
}