forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0020.yml
504 lines (490 loc) · 17.7 KB
/
0020.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
version: 20
description: "queue tasks phase 2 step 1 (slow migration: 700-2000μs per row in table `queue_tasks_entities`)"
migrationScript: 0020-migration.sql
downgradeScript: 0020-downgrade.sql
methods:
####
# queue_tasks_entities
queue_tasks_entities_load:
deprecated: true
description: See taskcluster-lib-entities
mode: read
serviceName: queue
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
queue_tasks_entities_load.partition_key,
queue_tasks_entities_load.row_key,
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
jsonb_build_object(
'PartitionKey', task_id,
'RowKey', 'task',
'taskId', slugid_to_uuid(task_id),
'provisionerId', provisioner_id,
'workerType', worker_type,
'schedulerId', scheduler_id,
'taskGroupId', slugid_to_uuid(task_group_id),
'requires', requires::text,
'priority', priority::text,
'retries', retries,
'retriesLeft', retries_left,
'created', created,
'deadline', deadline,
'expires', expires,
'takenUntil', coalesce(taken_until, '1970-01-01 00:00:00+00'::timestamptz)),
'dependencies', dependencies::text),
'routes', routes::text),
'scopes', scopes::text),
'payload', payload::text),
'metadata', metadata::text),
'tags', tags::text),
'extra', extra::text),
'runs', runs::text) as value,
1 as version,
tasks.etag as etag
from tasks
where
tasks.task_id = partition_key;
end
queue_tasks_entities_create:
deprecated: true
serviceName: queue
description: See taskcluster-lib-entities
mode: write
args: pk text, rk text, properties jsonb, overwrite boolean, version integer
returns: uuid
body: |-
declare
new_row tasks%ROWTYPE;
begin
select
uuid_to_slugid(properties ->> 'taskId'),
(properties ->> 'provisionerId')::text,
(properties ->> 'workerType')::text,
(properties ->> 'schedulerId')::text,
uuid_to_slugid(properties ->> 'taskGroupId')::text,
entity_buf_decode(properties, 'dependencies')::jsonb,
(properties ->> 'requires')::task_requires,
entity_buf_decode(properties, 'routes')::jsonb,
(properties ->> 'priority')::task_priority,
(properties ->> 'retries')::int,
(properties ->> 'retriesLeft')::int,
(properties ->> 'created')::timestamptz,
(properties ->> 'deadline')::timestamptz,
(properties ->> 'expires')::timestamptz,
entity_buf_decode(properties, 'scopes')::jsonb,
entity_buf_decode(properties, 'payload')::jsonb,
entity_buf_decode(properties, 'metadata')::jsonb,
entity_buf_decode(properties, 'tags')::jsonb,
entity_buf_decode(properties, 'extra')::jsonb,
entity_buf_decode(properties, 'runs')::jsonb,
case (properties ->> 'takenUntil')::timestamptz
when '1970-01-01 00:00:00+00'::timestamptz then null
else (properties ->> 'takenUntil')::timestamptz
end,
false,
public.gen_random_uuid()
into new_row;
if overwrite then
raise exception 'overwrite not implemented';
else
execute 'insert into tasks select $1.*' using new_row;
end if;
return new_row.etag;
end
queue_tasks_entities_remove:
deprecated: true
serviceName: queue
description: See taskcluster-lib-entities
mode: write
args: partition_key text, row_key text
returns: table (etag uuid)
body: |-
begin
return query delete from tasks
where
tasks.task_id = partition_key
returning tasks.etag;
end
queue_tasks_entities_modify:
deprecated: true
serviceName: queue
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_etag uuid;
begin
-- NOTE: queue only updates runs, retriesLeft, and takenUntil, so only those fields are
-- supported here.
new_etag = public.gen_random_uuid();
update tasks
set (
runs,
retries_left,
taken_until,
etag
) = (
entity_buf_decode(properties, 'runs')::jsonb,
(properties ->> 'retriesLeft')::int,
case (properties ->> 'takenUntil')::timestamptz
when '1970-01-01 00:00:00+00'::timestamptz then null
else (properties ->> 'takenUntil')::timestamptz
end,
new_etag
)
where
tasks.task_id = partition_key and
tasks.etag = queue_tasks_entities_modify.old_etag;
if found then
return query select new_etag;
return;
end if;
perform tasks.etag from tasks
where
tasks.task_id = partition_key;
if found then
raise exception 'unsuccessful update' using errcode = 'P0004';
else
raise exception 'no such row' using errcode = 'P0002';
end if;
end
queue_tasks_entities_scan:
deprecated: true
description: See taskcluster-lib-entities
mode: read
serviceName: queue
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
cond text[];
exp_cond_field text;
exp_cond_operator text;
exp_cond_operand timestamptz;
begin
if not condition is null then
cond := regexp_split_to_array(condition, '\s+');
exp_cond_field := trim(cond[3], '''');
exp_cond_operator := cond[4];
exp_cond_operand := cond[5] :: timestamptz;
if not (exp_cond_field || exp_cond_operator) in ('takenUntil=', 'deadline=', 'expires<') then
raise exception 'queue_tasks_entities_scan only supports certain takenUntil, deadline, and expires conditions';
end if;
end if;
return query select
task_id as partition_key,
'task' as row_key,
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
entity_buf_encode(
jsonb_build_object(
'PartitionKey', task_id,
'RowKey', 'task',
'taskId', slugid_to_uuid(task_id),
'provisionerId', provisioner_id,
'workerType', worker_type,
'schedulerId', scheduler_id,
'taskGroupId', slugid_to_uuid(task_group_id),
'requires', requires::text,
'priority', priority::text,
'retries', retries,
'retriesLeft', retries_left,
'created', created,
'deadline', deadline,
'expires', expires,
'takenUntil', coalesce(taken_until, '1970-01-01 00:00:00+00'::timestamptz)),
'dependencies', dependencies::text),
'routes', routes::text),
'scopes', scopes::text),
'payload', payload::text),
'metadata', metadata::text),
'tags', tags::text),
'extra', extra::text),
'runs', runs::text) as value,
1 as version,
tasks.etag as etag from tasks
where
(pk is NULL or pk = task_id) and
case
when exp_cond_field = 'deadline' then deadline = exp_cond_operand
-- note that queue never queries for takenUntil = new Date(0)
when exp_cond_field = 'takenUntil' then taken_until = exp_cond_operand
when exp_cond_field = 'expires' then expires < exp_cond_operand
else true
end
order by tasks.task_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
####
# queue_task_group_members_entities
#
# This table is just an index into tasks by taskGroupId, and is now read-only -- writes
# are just ignored.
queue_task_group_members_entities_load:
deprecated: true
description: See taskcluster-lib-entities
mode: read
serviceName: queue
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
task_group_id,
task_id,
jsonb_build_object(
'PartitionKey', task_group_id,
'RowKey', task_id,
'taskId', slugid_to_uuid(task_id),
'taskGroupId', slugid_to_uuid(task_group_id),
'expires', expires) as value,
1 as version,
tasks.etag as etag
from tasks
where
tasks.task_group_id = partition_key and
tasks.task_id = row_key;
end
queue_task_group_members_entities_create:
deprecated: true
serviceName: queue
description: See taskcluster-lib-entities
mode: write
args: pk text, rk text, properties jsonb, overwrite boolean, version integer
returns: uuid
body: |-
begin
return public.gen_random_uuid();
end
queue_task_group_members_entities_remove:
deprecated: true
serviceName: queue
description: See taskcluster-lib-entities
mode: write
args: partition_key text, row_key text
returns: table (etag uuid)
body: |-
begin
return query
select tasks.etag
from tasks
where
tasks.task_group_id = partition_key and
tasks.task_id = row_key;
end
queue_task_group_members_entities_modify:
deprecated: true
serviceName: queue
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: |-
begin
raise exception 'modify not implemented for queue_task_group_members_entities';
end
queue_task_group_members_entities_scan:
deprecated: true
description: See taskcluster-lib-entities
mode: read
serviceName: queue
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
cond text[];
exp_cond_field text;
exp_cond_operator text;
exp_cond_operand timestamptz;
begin
if pk is null then
-- if pk is null, then this is the expiration scan for the members table; since
-- there is no members table, we stub this out by simply returning an empty set,
-- ignoring the condition
return;
end if;
if not condition is null then
cond := regexp_split_to_array(condition, '\s+');
exp_cond_field := trim(cond[3], '''');
exp_cond_operator := cond[4];
exp_cond_operand := cond[5] :: timestamptz;
if exp_cond_operator != '>=' or exp_cond_field != 'expires' then
raise exception 'queue_task_group_memberss_entities_scan only supports `expires >= <timestamp>` conditions';
end if;
end if;
return query
select
task_group_id,
task_id,
jsonb_build_object(
'PartitionKey', task_group_id,
'RowKey', task_id,
'taskId', slugid_to_uuid(task_id),
'taskGroupId', slugid_to_uuid(task_group_id),
'expires', expires) as value,
1 as version,
tasks.etag as etag
from tasks
where
tasks.task_group_id = pk and
(exp_cond_operand is NULL or expires >= exp_cond_operand)
order by tasks.task_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
####
# queue_task_group_active_sets_entities
#
# This table is just an index into tasks by taskGroupId, and is now read-only -- writes
# and removals are translated to changes to the `ever_resolved` column of the tasks table.
queue_task_group_active_sets_entities_load:
deprecated: true
description: See taskcluster-lib-entities
mode: read
serviceName: queue
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
task_group_id,
task_id,
jsonb_build_object(
'PartitionKey', task_group_id,
'RowKey', task_id,
'taskId', slugid_to_uuid(task_id),
'taskGroupId', slugid_to_uuid(task_group_id),
'expires', expires) as value,
1 as version,
tasks.etag as etag
from tasks
where
not ever_resolved and
tasks.task_group_id = partition_key and
tasks.task_id = row_key;
end
queue_task_group_active_sets_entities_create:
deprecated: true
serviceName: queue
description: See taskcluster-lib-entities
mode: write
args: pk text, rk text, properties jsonb, overwrite boolean, version integer
returns: uuid
body: |-
begin
-- this method is only called before the task is created, and tasks are
-- created in an unresolved state, so there's nothing to do here. Note
-- that the service does not mark a task as unresolved when rerunning it
return public.gen_random_uuid();
end
queue_task_group_active_sets_entities_remove:
deprecated: true
serviceName: queue
description: See taskcluster-lib-entities
mode: write
args: partition_key text, row_key text
returns: table (etag uuid)
body: |-
begin
-- DependencyTracker uses this to mark a task as ever_resolved
update tasks
set ever_resolved = true
where
tasks.task_group_id = partition_key and
tasks.task_id = row_key;
return query select public.gen_random_uuid() as etag;
end
queue_task_group_active_sets_entities_modify:
deprecated: true
serviceName: queue
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: |-
begin
raise exception 'modify not supported';
end
queue_task_group_active_sets_entities_scan:
deprecated: true
description: See taskcluster-lib-entities
mode: read
serviceName: queue
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
cond text[];
exp_cond_field text;
exp_cond_operator text;
exp_cond_operand timestamptz;
begin
if not condition is null then
cond := regexp_split_to_array(condition, '\s+');
exp_cond_field := trim(cond[3], '''');
if exp_cond_field != 'expires' then
raise exception 'queue_task_group_active_sets_entities_scan only supports filtering for expired rows';
end if;
-- there's no distinct table to expire, so just return an empty set to make the
-- expiration crontask finish immediately
return;
end if;
-- the idea here is to use the tasks_task_group_id_unresolved_idx index for a quick response
return query select
task_group_id as partition_key,
task_id as row_key,
jsonb_build_object(
'PartitionKey', task_group_id,
'RowKey', task_id,
'taskGroupId', slugid_to_uuid(task_group_id),
'taskId', slugid_to_uuid(task_id),
'expires', expires) as value,
1 as version,
public.gen_random_uuid() as etag
from tasks
where
(pk is NULL or pk = task_group_id) and
not ever_resolved
order by tasks.task_group_id, tasks.task_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