Go · 7327 bytes Raw Blame History
1 // Code generated by sqlc. DO NOT EDIT.
2 // versions:
3 // sqlc v1.31.1
4 // source: workflow_jobs.sql
5
6 package actionsdb
7
8 import (
9 "context"
10
11 "github.com/jackc/pgx/v5/pgtype"
12 )
13
14 const claimQueuedWorkflowJob = `-- name: ClaimQueuedWorkflowJob :one
15 WITH candidate AS (
16 SELECT j.id
17 FROM workflow_jobs j
18 WHERE j.status = 'queued'
19 AND j.runner_id IS NULL
20 AND (j.runs_on = '' OR j.runs_on = ANY($1::text[]))
21 AND NOT EXISTS (
22 SELECT 1
23 FROM workflow_jobs dep
24 WHERE dep.run_id = j.run_id
25 AND dep.job_key = ANY(j.needs_jobs)
26 AND (dep.status <> 'completed' OR dep.conclusion <> 'success')
27 )
28 ORDER BY j.created_at ASC, j.id ASC
29 FOR UPDATE OF j SKIP LOCKED
30 LIMIT 1
31 ),
32 claimed AS (
33 UPDATE workflow_jobs j
34 SET runner_id = $2::bigint,
35 status = 'running',
36 started_at = COALESCE(j.started_at, now()),
37 version = j.version + 1,
38 updated_at = now()
39 FROM candidate c
40 WHERE j.id = c.id
41 RETURNING j.id, j.run_id, j.job_index, j.job_key, j.job_name, j.runs_on,
42 j.runner_id, j.needs_jobs, j.if_expr, j.timeout_minutes,
43 j.permissions, j.job_env, j.status, j.conclusion,
44 j.cancel_requested, j.started_at, j.completed_at, j.version,
45 j.created_at, j.updated_at
46 )
47 SELECT c.id, c.run_id, c.job_index, c.job_key, c.job_name, c.runs_on,
48 c.runner_id, c.needs_jobs, c.if_expr, c.timeout_minutes,
49 c.permissions, c.job_env, c.status, c.conclusion,
50 c.cancel_requested, c.started_at, c.completed_at, c.version,
51 c.created_at, c.updated_at,
52 r.repo_id, r.run_index, r.workflow_file, r.workflow_name,
53 r.head_sha, r.head_ref, r.event
54 FROM claimed c
55 JOIN workflow_runs r ON r.id = c.run_id
56 `
57
58 type ClaimQueuedWorkflowJobParams struct {
59 Labels []string
60 RunnerID int64
61 }
62
63 type ClaimQueuedWorkflowJobRow struct {
64 ID int64
65 RunID int64
66 JobIndex int32
67 JobKey string
68 JobName string
69 RunsOn string
70 RunnerID pgtype.Int8
71 NeedsJobs []string
72 IfExpr string
73 TimeoutMinutes int32
74 Permissions []byte
75 JobEnv []byte
76 Status WorkflowJobStatus
77 Conclusion NullCheckConclusion
78 CancelRequested bool
79 StartedAt pgtype.Timestamptz
80 CompletedAt pgtype.Timestamptz
81 Version int32
82 CreatedAt pgtype.Timestamptz
83 UpdatedAt pgtype.Timestamptz
84 RepoID int64
85 RunIndex int64
86 WorkflowFile string
87 WorkflowName string
88 HeadSha string
89 HeadRef string
90 Event WorkflowRunEvent
91 }
92
93 func (q *Queries) ClaimQueuedWorkflowJob(ctx context.Context, db DBTX, arg ClaimQueuedWorkflowJobParams) (ClaimQueuedWorkflowJobRow, error) {
94 row := db.QueryRow(ctx, claimQueuedWorkflowJob, arg.Labels, arg.RunnerID)
95 var i ClaimQueuedWorkflowJobRow
96 err := row.Scan(
97 &i.ID,
98 &i.RunID,
99 &i.JobIndex,
100 &i.JobKey,
101 &i.JobName,
102 &i.RunsOn,
103 &i.RunnerID,
104 &i.NeedsJobs,
105 &i.IfExpr,
106 &i.TimeoutMinutes,
107 &i.Permissions,
108 &i.JobEnv,
109 &i.Status,
110 &i.Conclusion,
111 &i.CancelRequested,
112 &i.StartedAt,
113 &i.CompletedAt,
114 &i.Version,
115 &i.CreatedAt,
116 &i.UpdatedAt,
117 &i.RepoID,
118 &i.RunIndex,
119 &i.WorkflowFile,
120 &i.WorkflowName,
121 &i.HeadSha,
122 &i.HeadRef,
123 &i.Event,
124 )
125 return i, err
126 }
127
128 const countRunningJobsForRunner = `-- name: CountRunningJobsForRunner :one
129 SELECT COUNT(*)::integer
130 FROM workflow_jobs
131 WHERE runner_id = $1::bigint AND status = 'running'
132 `
133
134 func (q *Queries) CountRunningJobsForRunner(ctx context.Context, db DBTX, runnerID int64) (int32, error) {
135 row := db.QueryRow(ctx, countRunningJobsForRunner, runnerID)
136 var column_1 int32
137 err := row.Scan(&column_1)
138 return column_1, err
139 }
140
141 const getWorkflowJobByID = `-- name: GetWorkflowJobByID :one
142 SELECT id, run_id, job_index, job_key, job_name, runs_on,
143 runner_id, needs_jobs, if_expr, timeout_minutes, permissions,
144 job_env, status, conclusion, cancel_requested,
145 started_at, completed_at, version, created_at, updated_at
146 FROM workflow_jobs
147 WHERE id = $1
148 `
149
150 func (q *Queries) GetWorkflowJobByID(ctx context.Context, db DBTX, id int64) (WorkflowJob, error) {
151 row := db.QueryRow(ctx, getWorkflowJobByID, id)
152 var i WorkflowJob
153 err := row.Scan(
154 &i.ID,
155 &i.RunID,
156 &i.JobIndex,
157 &i.JobKey,
158 &i.JobName,
159 &i.RunsOn,
160 &i.RunnerID,
161 &i.NeedsJobs,
162 &i.IfExpr,
163 &i.TimeoutMinutes,
164 &i.Permissions,
165 &i.JobEnv,
166 &i.Status,
167 &i.Conclusion,
168 &i.CancelRequested,
169 &i.StartedAt,
170 &i.CompletedAt,
171 &i.Version,
172 &i.CreatedAt,
173 &i.UpdatedAt,
174 )
175 return i, err
176 }
177
178 const insertWorkflowJob = `-- name: InsertWorkflowJob :one
179
180 INSERT INTO workflow_jobs (
181 run_id, job_index, job_key, job_name,
182 runs_on, needs_jobs, if_expr, timeout_minutes,
183 permissions, job_env
184 ) VALUES (
185 $1, $2, $3, $4, $5, $6, $7, $8, $9, $10
186 )
187 RETURNING id, run_id, job_index, job_key, job_name, runs_on,
188 runner_id, needs_jobs, if_expr, timeout_minutes, permissions,
189 job_env, status, conclusion, cancel_requested,
190 started_at, completed_at, version, created_at, updated_at
191 `
192
193 type InsertWorkflowJobParams struct {
194 RunID int64
195 JobIndex int32
196 JobKey string
197 JobName string
198 RunsOn string
199 NeedsJobs []string
200 IfExpr string
201 TimeoutMinutes int32
202 Permissions []byte
203 JobEnv []byte
204 }
205
206 // SPDX-License-Identifier: AGPL-3.0-or-later
207 func (q *Queries) InsertWorkflowJob(ctx context.Context, db DBTX, arg InsertWorkflowJobParams) (WorkflowJob, error) {
208 row := db.QueryRow(ctx, insertWorkflowJob,
209 arg.RunID,
210 arg.JobIndex,
211 arg.JobKey,
212 arg.JobName,
213 arg.RunsOn,
214 arg.NeedsJobs,
215 arg.IfExpr,
216 arg.TimeoutMinutes,
217 arg.Permissions,
218 arg.JobEnv,
219 )
220 var i WorkflowJob
221 err := row.Scan(
222 &i.ID,
223 &i.RunID,
224 &i.JobIndex,
225 &i.JobKey,
226 &i.JobName,
227 &i.RunsOn,
228 &i.RunnerID,
229 &i.NeedsJobs,
230 &i.IfExpr,
231 &i.TimeoutMinutes,
232 &i.Permissions,
233 &i.JobEnv,
234 &i.Status,
235 &i.Conclusion,
236 &i.CancelRequested,
237 &i.StartedAt,
238 &i.CompletedAt,
239 &i.Version,
240 &i.CreatedAt,
241 &i.UpdatedAt,
242 )
243 return i, err
244 }
245
246 const listJobsForRun = `-- name: ListJobsForRun :many
247 SELECT id, run_id, job_index, job_key, job_name, runs_on, status,
248 conclusion, started_at, completed_at, created_at
249 FROM workflow_jobs
250 WHERE run_id = $1
251 ORDER BY job_index ASC
252 `
253
254 type ListJobsForRunRow struct {
255 ID int64
256 RunID int64
257 JobIndex int32
258 JobKey string
259 JobName string
260 RunsOn string
261 Status WorkflowJobStatus
262 Conclusion NullCheckConclusion
263 StartedAt pgtype.Timestamptz
264 CompletedAt pgtype.Timestamptz
265 CreatedAt pgtype.Timestamptz
266 }
267
268 func (q *Queries) ListJobsForRun(ctx context.Context, db DBTX, runID int64) ([]ListJobsForRunRow, error) {
269 rows, err := db.Query(ctx, listJobsForRun, runID)
270 if err != nil {
271 return nil, err
272 }
273 defer rows.Close()
274 items := []ListJobsForRunRow{}
275 for rows.Next() {
276 var i ListJobsForRunRow
277 if err := rows.Scan(
278 &i.ID,
279 &i.RunID,
280 &i.JobIndex,
281 &i.JobKey,
282 &i.JobName,
283 &i.RunsOn,
284 &i.Status,
285 &i.Conclusion,
286 &i.StartedAt,
287 &i.CompletedAt,
288 &i.CreatedAt,
289 ); err != nil {
290 return nil, err
291 }
292 items = append(items, i)
293 }
294 if err := rows.Err(); err != nil {
295 return nil, err
296 }
297 return items, nil
298 }
299