forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0014.yml
119 lines (116 loc) · 4.66 KB
/
0014.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
version: 14
description: add secret to workers
migrationScript: 0014-migration.sql
downgradeScript: 0014-downgrade.sql
methods:
get_worker:
deprecated: true
# no changes required
update_worker:
deprecated: true
# no changes required
get_worker_2:
description: Get an existing worker. The returned table will have one or (if no such worker is defined) zero rows.
mode: read
serviceName: worker_manager
args: worker_pool_id_in text, worker_group_in text, worker_id_in text
returns: table(worker_pool_id text, worker_group text, worker_id text, provider_id text, created timestamptz, expires timestamptz, state text, provider_data jsonb, capacity integer, last_modified timestamptz, last_checked timestamptz, secret jsonb, etag uuid)
body: |-
begin
return query
select
workers.worker_pool_id,
workers.worker_group,
workers.worker_id,
workers.provider_id,
workers.created,
workers.expires,
workers.state,
workers.provider_data,
workers.capacity,
workers.last_modified,
workers.last_checked,
workers.secret,
workers.etag
from workers
where
workers.worker_pool_id = worker_pool_id_in and
workers.worker_group = worker_group_in and
workers.worker_id = worker_id_in;
end
update_worker_2:
serviceName: worker_manager
description: |-
Update a worker.
Returns the up-to-date worker row that have the same worker_pool_id, worker_group, and worker_id.
If the etag argument is empty then the update will overwrite the matched row.
Else, the function will fail if the etag is out of date. This is useful for concurency handling.
mode: write
args: worker_pool_id_in text, worker_group_in text, worker_id_in text, provider_id_in text, created_in timestamptz, expires_in timestamptz, state_in text, provider_data_in jsonb, capacity_in integer, last_modified_in timestamptz, last_checked_in timestamptz, etag_in uuid, secret_in jsonb
returns: table(worker_pool_id text, worker_group text, worker_id text, provider_id text, created timestamptz, expires timestamptz, state text, provider_data jsonb, capacity integer, last_modified timestamptz, last_checked timestamptz, etag uuid, secret jsonb)
body: |-
declare
new_etag uuid := public.gen_random_uuid();
updated_row workers%ROWTYPE;
begin
update workers
set (provider_id, created, expires, state, provider_data, capacity, last_modified, last_checked, etag, secret) = (
coalesce(provider_id_in, workers.provider_id),
coalesce(created_in, workers.created),
coalesce(expires_in, workers.expires),
coalesce(state_in, workers.state),
coalesce(provider_data_in, workers.provider_data),
coalesce(capacity_in, workers.capacity),
coalesce(last_modified_in, workers.last_modified),
coalesce(last_checked_in, workers.last_checked),
new_etag,
coalesce(secret_in, workers.secret)
)
where
workers.worker_pool_id = worker_pool_id_in and
workers.worker_group = worker_group_in and
workers.worker_id = worker_id_in and
workers.etag = coalesce(etag_in, workers.etag)
returning
workers.worker_pool_id,
workers.worker_group,
workers.worker_id,
workers.provider_id,
workers.created,
workers.expires,
workers.state,
workers.provider_data,
workers.capacity,
workers.last_modified,
workers.last_checked,
workers.etag,
workers.secret
into updated_row;
if found then
return query select
updated_row.worker_pool_id,
updated_row.worker_group,
updated_row.worker_id,
updated_row.provider_id,
updated_row.created,
updated_row.expires,
updated_row.state,
updated_row.provider_data,
updated_row.capacity,
updated_row.last_modified,
updated_row.last_checked,
updated_row.etag,
updated_row.secret;
return;
end if;
perform workers.etag from workers
where
workers.worker_pool_id = worker_pool_id_in and
workers.worker_group = worker_group_in and
workers.worker_id = worker_id_in;
if found then
raise exception 'unsuccessful update' using errcode = 'P0004';
else
raise exception 'no such row' using errcode = 'P0002';
end if;
end