forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 1
/
0029.yml
284 lines (281 loc) · 10.4 KB
/
0029.yml
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
version: 29
description: worker-manager worker pools phase 2
migrationScript: 0029-migration.sql
downgradeScript: 0029-downgrade.sql
methods:
wmworker_pool_errors_entities_load:
deprecated: true
description: See taskcluster-lib-entities
mode: read
serviceName: worker_manager
args: partition_key text, row_key text
returns: table (partition_key_out text, row_key_out text, value jsonb, version integer, etag uuid)
body: |-
begin
return query
select
wmworker_pool_errors_entities_load.partition_key,
wmworker_pool_errors_entities_load.row_key,
entity_buf_encode(
jsonb_build_object(
'PartitionKey', wmworker_pool_errors_entities_load.partition_key,
'RowKey', wmworker_pool_errors_entities_load.row_key,
'errorId', slugid_to_uuid(error_id),
'workerPoolId', worker_pool_id,
'reported', reported,
'kind', kind,
'title', title,
'description', description),
'extra', extra::text) as value,
1 as version,
worker_pool_errors.etag as etag
from worker_pool_errors
where
worker_pool_errors.worker_pool_id = decode_string_key(wmworker_pool_errors_entities_load.partition_key) and
worker_pool_errors.error_id = decode_string_key(wmworker_pool_errors_entities_load.row_key);
end
wmworker_pool_errors_entities_create:
deprecated: true
serviceName: worker_manager
description: See taskcluster-lib-entities
mode: write
args: pk text, rk text, properties jsonb, overwrite boolean, version integer
returns: uuid
body: |-
declare
new_row worker_pool_errors%ROWTYPE;
begin
select
uuid_to_slugid(properties ->> 'errorId')::text as error_id,
(properties ->> 'workerPoolId')::text as worker_pool_id,
(properties ->> 'reported')::timestamptz as reported,
(properties ->> 'kind')::text as kind,
(properties ->> 'title')::text as title,
(properties ->> 'description')::text as description,
entity_buf_decode(properties, 'extra')::jsonb as extra,
public.gen_random_uuid() as etag
into new_row;
if overwrite then
raise exception 'overwrite not implemented';
else
execute 'insert into worker_pool_errors select $1.*' using new_row;
end if;
return new_row.etag;
end
wmworker_pool_errors_entities_remove:
deprecated: true
serviceName: worker_manager
description: See taskcluster-lib-entities
mode: write
args: partition_key text, row_key text
returns: table (etag uuid)
body: |-
begin
return query delete from worker_pool_errors
where
worker_pool_errors.worker_pool_id = decode_string_key(wmworker_pool_errors_entities_remove.partition_key) and
worker_pool_errors.error_id = decode_string_key(wmworker_pool_errors_entities_remove.row_key)
returning worker_pool_errors.etag;
end
wmworker_pool_errors_entities_modify:
deprecated: true
serviceName: worker_manager
description: See taskcluster-lib-entities
mode: write
args: partition_key text, row_key text, properties jsonb, version integer, old_etag uuid
returns: table (etag uuid)
body: |-
declare
new_row worker_pool_errors%ROWTYPE;
begin
select
uuid_to_slugid(properties ->> 'errorId')::text as error_id,
(properties ->> 'workerPoolId')::text as worker_pool_id,
(properties ->> 'reported')::timestamptz as reported,
(properties ->> 'kind')::text as kind,
(properties ->> 'title')::text as title,
(properties ->> 'description')::text as description,
entity_buf_decode(properties, 'extra')::jsonb as extra,
public.gen_random_uuid() as etag
into new_row;
update worker_pool_errors
set (
error_id,
worker_pool_id,
reported,
kind,
title,
description,
extra,
etag
) = (
new_row.error_id,
new_row.worker_pool_id,
new_row.reported,
new_row.kind,
new_row.title,
new_row.description,
new_row.extra,
new_row.etag
)
where
worker_pool_errors.worker_pool_id = decode_string_key(wmworker_pool_errors_entities_modify.partition_key) and
worker_pool_errors.error_id = decode_string_key(wmworker_pool_errors_entities_modify.row_key) and
worker_pool_errors.etag = wmworker_pool_errors_entities_modify.old_etag;
if found then
return query select new_row.etag;
return;
end if;
perform worker_pool_errors.etag from worker_pool_errors
where
worker_pool_errors.worker_pool_id = decode_string_key(wmworker_pool_errors_entities_modify.partition_key) and
worker_pool_errors.error_id = decode_string_key(wmworker_pool_errors_entities_modify.row_key);
if found then
raise exception 'unsuccessful update' using errcode = 'P0004';
else
raise exception 'no such row' using errcode = 'P0002';
end if;
end
wmworker_pool_errors_entities_scan:
deprecated: true
description: See taskcluster-lib-entities
mode: read
serviceName: worker_manager
args: pk text, rk text, condition text, size integer, page integer
returns: table (partition_key text, row_key text, value jsonb, version integer, etag uuid)
body: |-
declare
begin
if not condition is null then
raise exception 'condition not supported';
end if;
return query
select
encode_string_key(wmworker_pool_errors_entities_scan.partition_key),
encode_string_key(wmworker_pool_errors_entities_scan.row_key),
entity_buf_encode(
jsonb_build_object(
'PartitionKey', encode_string_key(worker_pool_id),
'RowKey', encode_string_key(error_id),
'errorId', slugid_to_uuid(error_id),
'workerPoolId', worker_pool_id,
'reported', reported,
'kind', kind,
'title', title,
'description', description),
'extra', extra::text) as value,
1 as version,
worker_pool_errors.etag as etag
from worker_pool_errors
where
partition_key is null or
worker_pool_id = decode_string_key(partition_key) and
row_key is null or
error_id = decode_string_key(row_key)
order by error_id
limit case
when (size is not null and size > 0) then size + 1
else null
end
offset case
when (page is not null and page > 0) then page
else 0
end;
end
create_worker_pool_error:
description: |-
Create a new worker pool error. Raises UNIQUE_VIOLATION if the error already exists.
mode: write
serviceName: worker_manager
args: error_id_in text, worker_pool_id_in text, reported_in timestamptz, kind_in text, title_in text, description_in text, extra_in jsonb
returns: uuid
body: |-
declare
new_etag uuid := public.gen_random_uuid();
begin
insert
into worker_pool_errors (error_id, worker_pool_id, reported, kind, title, description, extra)
values (error_id_in, worker_pool_id_in, reported_in, kind_in, title_in, description_in, extra_in);
return new_etag;
end
get_worker_pool_error:
description: |-
Get an existing worker pool error. The returned table will have one or (if no such worker pool error is defined) zero rows.
mode: read
serviceName: worker_manager
args: error_id_in text, worker_pool_id_in text
returns: table(error_id text, worker_pool_id text, reported timestamptz, kind text, title text, description text, extra jsonb)
body: |-
begin
return query
select
worker_pool_errors.error_id,
worker_pool_errors.worker_pool_id,
worker_pool_errors.reported,
worker_pool_errors.kind,
worker_pool_errors.title,
worker_pool_errors.description,
worker_pool_errors.extra
from worker_pool_errors
where
worker_pool_errors.worker_pool_id = worker_pool_id_in and
worker_pool_errors.error_id = error_id_in;
end
get_worker_pool_errors:
description: |-
Get existing worker pool errors, ordered by `reported` date. If the pagination arguments are both NULL, all rows are returned.
Otherwise, page_size rows are returned at offset page_offset.
mode: read
serviceName: worker_manager
args: page_size_in integer, page_offset_in integer
returns: table(error_id text, worker_pool_id text, reported timestamptz, kind text, title text, description text, extra jsonb)
body: |-
begin
return query
select
worker_pool_errors.error_id,
worker_pool_errors.worker_pool_id,
worker_pool_errors.reported,
worker_pool_errors.kind,
worker_pool_errors.title,
worker_pool_errors.description,
worker_pool_errors.extra
from worker_pool_errors
order by worker_pool_errors.reported desc
limit get_page_limit(page_size_in)
offset get_page_offset(page_offset_in);
end
delete_worker_pool_error:
description: |-
Delete a worker pool error immediately.
mode: write
serviceName: worker_manager
args: error_id_in text, worker_pool_id_in text
returns: void
body: |-
begin
delete
from worker_pool_errors
where
worker_pool_errors.worker_pool_id = worker_pool_id_in and
worker_pool_errors.error_id = error_id_in;
end
expire_worker_pool_errors:
description: |-
Expire worker pool errors reported before `expires_in`.
Returns a count of rows that have been deleted.
mode: write
serviceName: worker_manager
args: expires_in timestamptz
returns: integer
body: |-
declare
count integer;
begin
delete from worker_pool_errors where worker_pool_errors.reported < expires_in;
if found then
get diagnostics count = row_count;
return count;
end if;
return 0;
end