forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 1
/
0026.yml
242 lines (242 loc) · 8.63 KB
/
0026.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
version: 26
description: index phase 2 step 2
methods:
get_index_namespaces:
description: |-
Get existing index_namespaces filtered by the optional arguments,
ordered by the `parent` and `name`.
If the pagination arguments are both NULL, all rows are returned.
Otherwise, page_size rows are returned at offset page_offset.
mode: read
serviceName: index
args: parent_in text, name_in text, page_size_in integer, page_offset_in integer
returns: table(parent text, name text, expires timestamptz)
body: |-
begin
return query
select
index_namespaces.parent,
index_namespaces.name,
index_namespaces.expires
from index_namespaces
where
(index_namespaces.parent = parent_in or parent_in is null) and
(index_namespaces.name = name_in or name_in is null) and
(index_namespaces.expires > now())
-- we previously used to order by the hashed parent but there's probably no need to add this complication.
order by index_namespaces.parent, name
limit get_page_limit(page_size_in)
offset get_page_offset(page_offset_in);
end
create_index_namespace:
description: |-
Create a new namespace. Raises UNIQUE_VIOLATION if the namespace already exists.
Returns the newly created namespace.
mode: write
serviceName: index
args: parent_in text, name_in text, expires_in timestamptz
returns: table(parent text, name text, expires timestamptz)
body: |-
begin
return query insert
into index_namespaces (parent, name, expires)
values (parent_in, name_in, expires_in)
returning index_namespaces.parent, index_namespaces.name, index_namespaces.expires;
end
get_index_namespace:
description: |-
Get a namespace. The returned table will have one or zero rows.
mode: read
serviceName: index
args: parent_in text, name_in text
returns: table(parent text, name text, expires timestamptz)
body: |-
begin
return query select
index_namespaces.parent,
index_namespaces.name,
index_namespaces.expires
from index_namespaces
where
index_namespaces.parent = parent_in and
index_namespaces.name = name_in;
end
update_index_namespace:
serviceName: index
description: |-
Update a namespace.
Returns the up-to-date namespace row that have the same parent and name.
If the row is not found then an exception with code 'P0002' is thrown.
mode: write
args: parent_in text, name_in text, expires_in timestamptz
returns: table(parent text, name text, expires timestamptz)
body: |-
declare
updated_row index_namespaces%ROWTYPE;
begin
update index_namespaces
set expires = coalesce(expires_in, index_namespaces.expires)
where
index_namespaces.parent = parent_in and
index_namespaces.name = name_in
returning
index_namespaces.parent,
index_namespaces.name,
index_namespaces.expires
into updated_row;
if found then
return query select
updated_row.parent,
updated_row.name,
updated_row.expires;
return;
end if;
raise exception 'no such row' using errcode = 'P0002';
end
expire_index_namespaces:
description: |-
Expire index_namespaces that come before the current time.
Returns a count of rows that have been deleted.
mode: write
serviceName: index
args: ''
returns: integer
body: |-
declare
count integer;
begin
delete from index_namespaces where index_namespaces.expires < now();
if found then
get diagnostics count = row_count;
return count;
end if;
return 0;
end
get_indexed_tasks:
description: |-
Get existing indexed tasks filtered by the optional arguments,
ordered by the `namespace` and `name`.
If the pagination arguments are both NULL, all rows are returned.
Otherwise, page_size rows are returned at offset page_offset.
mode: read
serviceName: index
args: namespace_in text, name_in text, page_size_in integer, page_offset_in integer
returns: table(namespace text, name text, rank integer, task_id text, data jsonb, expires timestamptz)
body: |-
begin
return query
select
indexed_tasks.namespace,
indexed_tasks.name,
indexed_tasks.rank,
uuid_to_slugid(indexed_tasks.task_id) as task_id,
indexed_tasks.data,
indexed_tasks.expires
from indexed_tasks
where
(indexed_tasks.namespace = namespace_in or namespace_in is null) and
(indexed_tasks.name = name_in or name_in is null) and
(indexed_tasks.expires > now())
-- we previously used to order by the hashed namespace but there's probably no need to add this complication.
order by indexed_tasks.namespace, name
limit get_page_limit(page_size_in)
offset get_page_offset(page_offset_in);
end
create_indexed_task:
description: |-
Create a new indexed task. Raises UNIQUE_VIOLATION if the indexed task already exists.
Returns the newly created indexed task.
mode: write
serviceName: index
args: namespace_in text, name_in text, rank_in integer, task_id_in text, data_in jsonb, expires_in timestamptz
returns: table(namespace text, name text, rank integer, task_id text, data jsonb, expires timestamptz)
body: |-
begin
return query insert
into indexed_tasks (namespace, name, rank, task_id, data, expires)
values (namespace_in, name_in, rank_in, slugid_to_uuid(task_id_in), data_in, expires_in)
returning indexed_tasks.namespace, indexed_tasks.name, indexed_tasks.rank, indexed_tasks.task_id, indexed_tasks.data, indexed_tasks.expires;
end
get_indexed_task:
description: |-
Get an indexed task. The returned table will have one or zero rows.
mode: read
serviceName: index
args: namespace_in text, name_in text
returns: table(namespace text, name text, rank integer, task_id text, data jsonb, expires timestamptz)
body: |-
begin
return query select
indexed_tasks.namespace,
indexed_tasks.name,
indexed_tasks.rank,
uuid_to_slugid(indexed_tasks.task_id) as task_id,
indexed_tasks.data,
indexed_tasks.expires
from indexed_tasks
where
indexed_tasks.namespace = namespace_in and
indexed_tasks.name = name_in;
end
update_indexed_task:
serviceName: index
description: |-
Update an indexed task.
Returns the up-to-date indexed task row that have the same namespace and name.
mode: write
args: namespace_in text, name_in text, rank_in integer, task_id_in text, data_in jsonb, expires_in timestamptz
returns: table(namespace text, name text, rank integer, task_id text, data jsonb, expires timestamptz)
body: |-
declare
updated_row indexed_tasks%ROWTYPE;
begin
update indexed_tasks
set (rank, task_id, data, expires) = (
coalesce(rank_in, indexed_tasks.rank),
coalesce(slugid_to_uuid(task_id_in), indexed_tasks.task_id),
coalesce(data_in, indexed_tasks.data),
coalesce(expires_in, indexed_tasks.expires)
)
where
indexed_tasks.namespace = namespace_in and
indexed_tasks.name = name_in
returning
indexed_tasks.namespace,
indexed_tasks.name,
indexed_tasks.rank,
uuid_to_slugid(indexed_tasks.task_id),
indexed_tasks.data,
indexed_tasks.expires
into updated_row;
if found then
return query select
updated_row.namespace,
updated_row.name,
updated_row.rank,
updated_row.task_id,
updated_row.data,
updated_row.expires;
return;
else
raise exception 'no such row' using errcode = 'P0002';
end if;
end
expire_indexed_tasks:
description: |-
Expire indexed tasks that come before the current time.
Returns a count of rows that have been deleted.
mode: write
serviceName: index
args: ''
returns: integer
body: |-
declare
count integer;
begin
delete from indexed_tasks where indexed_tasks.expires < now();
if found then
get diagnostics count = row_count;
return count;
end if;
return 0;
end