-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathcluster_queues.go
More file actions
164 lines (135 loc) · 5.29 KB
/
cluster_queues.go
File metadata and controls
164 lines (135 loc) · 5.29 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package buildkite
import (
"context"
"fmt"
)
// ClusterQueuesService handles communication with cluster queue related
// methods of the Buildkite API.
//
// Buildkite API docs: https://buildkite.com/docs/apis/rest-api/clusters#cluster-queues
type ClusterQueuesService struct {
client *Client
}
type RetryAgentAffinity string
const (
RetryAgentAffinityPreferWarmest RetryAgentAffinity = "prefer-warmest"
RetryAgentAffinityPreferDifferent RetryAgentAffinity = "prefer-different"
)
type ClusterQueue struct {
ID string `json:"id,omitempty"`
GraphQLID string `json:"graphql_id,omitempty"`
Key string `json:"key,omitempty"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
WebURL string `json:"web_url,omitempty"`
ClusterURL string `json:"cluster_url,omitempty"`
RetryAgentAffinity RetryAgentAffinity `json:"retry_agent_affinity,omitempty"`
DispatchPaused bool `json:"dispatch_paused"`
DispatchPausedBy *ClusterCreator `json:"dispatch_paused_by,omitempty"`
DispatchPausedAt *Timestamp `json:"dispatch_paused_at,omitempty"`
DispatchPausedNote string `json:"dispatch_paused_note,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
CreatedBy ClusterCreator `json:"created_by,omitempty"`
}
// ClusterQueueCreate represents the request body for creating a cluster queue.
type ClusterQueueCreate struct {
Key string `json:"key,omitempty"`
Description string `json:"description,omitempty"`
RetryAgentAffinity RetryAgentAffinity `json:"retry_agent_affinity,omitempty"`
}
// ClusterQueueUpdate represents the request body for updating a cluster queue.
type ClusterQueueUpdate struct {
Description Optional[string] `json:"description,omitzero"`
RetryAgentAffinity Optional[RetryAgentAffinity] `json:"retry_agent_affinity,omitzero"`
}
type ClusterQueuePause struct {
Note string `json:"dispatch_paused_note,omitempty"`
}
type ClusterQueuesListOptions struct {
ListOptions
}
func (cqs *ClusterQueuesService) List(ctx context.Context, org, clusterID string, opt *ClusterQueuesListOptions) ([]ClusterQueue, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/clusters/%s/queues", org, clusterID)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := cqs.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
var queues []ClusterQueue
resp, err := cqs.client.Do(req, &queues)
if err != nil {
return nil, resp, err
}
return queues, resp, err
}
func (cqs *ClusterQueuesService) Get(ctx context.Context, org, clusterID, queueID string) (ClusterQueue, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/clusters/%s/queues/%s", org, clusterID, queueID)
req, err := cqs.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return ClusterQueue{}, nil, err
}
var queue ClusterQueue
resp, err := cqs.client.Do(req, &queue)
if err != nil {
return ClusterQueue{}, resp, err
}
return queue, resp, err
}
func (cqs *ClusterQueuesService) Create(ctx context.Context, org, clusterID string, qc ClusterQueueCreate) (ClusterQueue, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/clusters/%s/queues", org, clusterID)
req, err := cqs.client.NewRequest(ctx, "POST", u, qc)
if err != nil {
return ClusterQueue{}, nil, err
}
var queue ClusterQueue
resp, err := cqs.client.Do(req, &queue)
if err != nil {
return ClusterQueue{}, resp, err
}
return queue, resp, err
}
func (cqs *ClusterQueuesService) Update(ctx context.Context, org, clusterID, queueID string, qu ClusterQueueUpdate) (ClusterQueue, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/clusters/%s/queues/%s", org, clusterID, queueID)
req, err := cqs.client.NewRequest(ctx, "PATCH", u, qu)
if err != nil {
return ClusterQueue{}, nil, err
}
var cq ClusterQueue
resp, err := cqs.client.Do(req, &cq)
if err != nil {
return ClusterQueue{}, resp, err
}
return cq, resp, err
}
func (cqs *ClusterQueuesService) Delete(ctx context.Context, org, clusterID, queueID string) (*Response, error) {
u := fmt.Sprintf("v2/organizations/%s/clusters/%s/queues/%s", org, clusterID, queueID)
req, err := cqs.client.NewRequest(ctx, "DELETE", u, nil)
if err != nil {
return nil, err
}
return cqs.client.Do(req, nil)
}
func (cqs *ClusterQueuesService) Pause(ctx context.Context, org, clusterID, queueID string, qp ClusterQueuePause) (ClusterQueue, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/clusters/%s/queues/%s/pause_dispatch", org, clusterID, queueID)
req, err := cqs.client.NewRequest(ctx, "POST", u, qp)
if err != nil {
return ClusterQueue{}, nil, err
}
var cq ClusterQueue
resp, err := cqs.client.Do(req, &cq)
if err != nil {
return ClusterQueue{}, resp, err
}
return cq, resp, err
}
func (cqs *ClusterQueuesService) Resume(ctx context.Context, org, clusterID, queueID string) (*Response, error) {
u := fmt.Sprintf("v2/organizations/%s/clusters/%s/queues/%s/resume_dispatch", org, clusterID, queueID)
req, err := cqs.client.NewRequest(ctx, "POST", u, nil)
if err != nil {
return nil, err
}
return cqs.client.Do(req, nil)
}