Go · 5518 bytes Raw Blame History
1 // Code generated by sqlc. DO NOT EDIT.
2 // versions:
3 // sqlc v1.31.1
4 // source: workflow_runners.sql
5
6 package actionsdb
7
8 import (
9 "context"
10
11 "github.com/jackc/pgx/v5/pgtype"
12 )
13
14 const getRunnerByID = `-- name: GetRunnerByID :one
15 SELECT id, name, labels, capacity, status, last_heartbeat_at,
16 registered_by_user_id, created_at, updated_at
17 FROM workflow_runners
18 WHERE id = $1
19 `
20
21 func (q *Queries) GetRunnerByID(ctx context.Context, db DBTX, id int64) (WorkflowRunner, error) {
22 row := db.QueryRow(ctx, getRunnerByID, id)
23 var i WorkflowRunner
24 err := row.Scan(
25 &i.ID,
26 &i.Name,
27 &i.Labels,
28 &i.Capacity,
29 &i.Status,
30 &i.LastHeartbeatAt,
31 &i.RegisteredByUserID,
32 &i.CreatedAt,
33 &i.UpdatedAt,
34 )
35 return i, err
36 }
37
38 const getRunnerByName = `-- name: GetRunnerByName :one
39 SELECT id, name, labels, capacity, status, last_heartbeat_at,
40 registered_by_user_id, created_at, updated_at
41 FROM workflow_runners
42 WHERE name = $1
43 `
44
45 func (q *Queries) GetRunnerByName(ctx context.Context, db DBTX, name string) (WorkflowRunner, error) {
46 row := db.QueryRow(ctx, getRunnerByName, name)
47 var i WorkflowRunner
48 err := row.Scan(
49 &i.ID,
50 &i.Name,
51 &i.Labels,
52 &i.Capacity,
53 &i.Status,
54 &i.LastHeartbeatAt,
55 &i.RegisteredByUserID,
56 &i.CreatedAt,
57 &i.UpdatedAt,
58 )
59 return i, err
60 }
61
62 const getRunnerByTokenHash = `-- name: GetRunnerByTokenHash :one
63 SELECT r.id, r.name, r.labels, r.capacity, r.status,
64 r.last_heartbeat_at, r.created_at
65 FROM workflow_runners r
66 JOIN runner_tokens t ON t.runner_id = r.id
67 WHERE t.token_hash = $1
68 AND t.revoked_at IS NULL
69 AND (t.expires_at IS NULL OR t.expires_at > now())
70 `
71
72 type GetRunnerByTokenHashRow struct {
73 ID int64
74 Name string
75 Labels []string
76 Capacity int32
77 Status WorkflowRunnerStatus
78 LastHeartbeatAt pgtype.Timestamptz
79 CreatedAt pgtype.Timestamptz
80 }
81
82 func (q *Queries) GetRunnerByTokenHash(ctx context.Context, db DBTX, tokenHash []byte) (GetRunnerByTokenHashRow, error) {
83 row := db.QueryRow(ctx, getRunnerByTokenHash, tokenHash)
84 var i GetRunnerByTokenHashRow
85 err := row.Scan(
86 &i.ID,
87 &i.Name,
88 &i.Labels,
89 &i.Capacity,
90 &i.Status,
91 &i.LastHeartbeatAt,
92 &i.CreatedAt,
93 )
94 return i, err
95 }
96
97 const insertRunner = `-- name: InsertRunner :one
98
99 INSERT INTO workflow_runners (name, labels, capacity, registered_by_user_id)
100 VALUES ($1, $2, $3, $4)
101 RETURNING id, name, labels, capacity, status, last_heartbeat_at,
102 registered_by_user_id, created_at, updated_at
103 `
104
105 type InsertRunnerParams struct {
106 Name string
107 Labels []string
108 Capacity int32
109 RegisteredByUserID pgtype.Int8
110 }
111
112 // SPDX-License-Identifier: AGPL-3.0-or-later
113 func (q *Queries) InsertRunner(ctx context.Context, db DBTX, arg InsertRunnerParams) (WorkflowRunner, error) {
114 row := db.QueryRow(ctx, insertRunner,
115 arg.Name,
116 arg.Labels,
117 arg.Capacity,
118 arg.RegisteredByUserID,
119 )
120 var i WorkflowRunner
121 err := row.Scan(
122 &i.ID,
123 &i.Name,
124 &i.Labels,
125 &i.Capacity,
126 &i.Status,
127 &i.LastHeartbeatAt,
128 &i.RegisteredByUserID,
129 &i.CreatedAt,
130 &i.UpdatedAt,
131 )
132 return i, err
133 }
134
135 const insertRunnerToken = `-- name: InsertRunnerToken :one
136 INSERT INTO runner_tokens (runner_id, token_hash, expires_at)
137 VALUES ($1, $2, $3)
138 RETURNING id, runner_id, token_hash, expires_at, revoked_at, created_at
139 `
140
141 type InsertRunnerTokenParams struct {
142 RunnerID int64
143 TokenHash []byte
144 ExpiresAt pgtype.Timestamptz
145 }
146
147 func (q *Queries) InsertRunnerToken(ctx context.Context, db DBTX, arg InsertRunnerTokenParams) (RunnerToken, error) {
148 row := db.QueryRow(ctx, insertRunnerToken, arg.RunnerID, arg.TokenHash, arg.ExpiresAt)
149 var i RunnerToken
150 err := row.Scan(
151 &i.ID,
152 &i.RunnerID,
153 &i.TokenHash,
154 &i.ExpiresAt,
155 &i.RevokedAt,
156 &i.CreatedAt,
157 )
158 return i, err
159 }
160
161 const listRunners = `-- name: ListRunners :many
162 SELECT id, name, labels, capacity, status, last_heartbeat_at, created_at
163 FROM workflow_runners
164 ORDER BY name ASC
165 `
166
167 type ListRunnersRow struct {
168 ID int64
169 Name string
170 Labels []string
171 Capacity int32
172 Status WorkflowRunnerStatus
173 LastHeartbeatAt pgtype.Timestamptz
174 CreatedAt pgtype.Timestamptz
175 }
176
177 func (q *Queries) ListRunners(ctx context.Context, db DBTX) ([]ListRunnersRow, error) {
178 rows, err := db.Query(ctx, listRunners)
179 if err != nil {
180 return nil, err
181 }
182 defer rows.Close()
183 items := []ListRunnersRow{}
184 for rows.Next() {
185 var i ListRunnersRow
186 if err := rows.Scan(
187 &i.ID,
188 &i.Name,
189 &i.Labels,
190 &i.Capacity,
191 &i.Status,
192 &i.LastHeartbeatAt,
193 &i.CreatedAt,
194 ); err != nil {
195 return nil, err
196 }
197 items = append(items, i)
198 }
199 if err := rows.Err(); err != nil {
200 return nil, err
201 }
202 return items, nil
203 }
204
205 const revokeAllTokensForRunner = `-- name: RevokeAllTokensForRunner :exec
206 UPDATE runner_tokens
207 SET revoked_at = now()
208 WHERE runner_id = $1 AND revoked_at IS NULL
209 `
210
211 func (q *Queries) RevokeAllTokensForRunner(ctx context.Context, db DBTX, runnerID int64) error {
212 _, err := db.Exec(ctx, revokeAllTokensForRunner, runnerID)
213 return err
214 }
215
216 const touchRunnerHeartbeat = `-- name: TouchRunnerHeartbeat :exec
217 UPDATE workflow_runners
218 SET last_heartbeat_at = now(),
219 status = $2,
220 updated_at = now()
221 WHERE id = $1
222 `
223
224 type TouchRunnerHeartbeatParams struct {
225 ID int64
226 Status WorkflowRunnerStatus
227 }
228
229 func (q *Queries) TouchRunnerHeartbeat(ctx context.Context, db DBTX, arg TouchRunnerHeartbeatParams) error {
230 _, err := db.Exec(ctx, touchRunnerHeartbeat, arg.ID, arg.Status)
231 return err
232 }
233