MySQL · 2063 bytes Raw Blame History
1 -- SPDX-License-Identifier: AGPL-3.0-or-later
2
3 -- name: InsertRunner :one
4 INSERT INTO workflow_runners (name, labels, capacity, registered_by_user_id)
5 VALUES ($1, $2, $3, $4)
6 RETURNING id, name, labels, capacity, status, last_heartbeat_at,
7 registered_by_user_id, created_at, updated_at;
8
9 -- name: GetRunnerByID :one
10 SELECT id, name, labels, capacity, status, last_heartbeat_at,
11 registered_by_user_id, created_at, updated_at
12 FROM workflow_runners
13 WHERE id = $1;
14
15 -- name: GetRunnerByName :one
16 SELECT id, name, labels, capacity, status, last_heartbeat_at,
17 registered_by_user_id, created_at, updated_at
18 FROM workflow_runners
19 WHERE name = $1;
20
21 -- name: ListRunners :many
22 SELECT id, name, labels, capacity, status, last_heartbeat_at, created_at
23 FROM workflow_runners
24 ORDER BY name ASC;
25
26 -- name: LockRunnerByID :one
27 SELECT id, name, labels, capacity, status, last_heartbeat_at,
28 registered_by_user_id, created_at, updated_at
29 FROM workflow_runners
30 WHERE id = $1
31 FOR UPDATE;
32
33 -- name: HeartbeatRunner :one
34 UPDATE workflow_runners
35 SET labels = $2,
36 capacity = $3,
37 last_heartbeat_at = now(),
38 status = $4,
39 updated_at = now()
40 WHERE id = $1
41 RETURNING id, name, labels, capacity, status, last_heartbeat_at,
42 registered_by_user_id, created_at, updated_at;
43
44 -- name: TouchRunnerHeartbeat :exec
45 UPDATE workflow_runners
46 SET last_heartbeat_at = now(),
47 status = $2,
48 updated_at = now()
49 WHERE id = $1;
50
51 -- name: InsertRunnerToken :one
52 INSERT INTO runner_tokens (runner_id, token_hash, expires_at)
53 VALUES ($1, $2, $3)
54 RETURNING id, runner_id, token_hash, expires_at, revoked_at, created_at;
55
56 -- name: GetRunnerByTokenHash :one
57 SELECT r.id, r.name, r.labels, r.capacity, r.status,
58 r.last_heartbeat_at, r.created_at
59 FROM workflow_runners r
60 JOIN runner_tokens t ON t.runner_id = r.id
61 WHERE t.token_hash = $1
62 AND t.revoked_at IS NULL
63 AND (t.expires_at IS NULL OR t.expires_at > now());
64
65 -- name: RevokeAllTokensForRunner :exec
66 UPDATE runner_tokens
67 SET revoked_at = now()
68 WHERE runner_id = $1 AND revoked_at IS NULL;
69