| 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, r.event_payload |
| 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 | EventPayload []byte |
| 92 | } |
| 93 | |
| 94 | func (q *Queries) ClaimQueuedWorkflowJob(ctx context.Context, db DBTX, arg ClaimQueuedWorkflowJobParams) (ClaimQueuedWorkflowJobRow, error) { |
| 95 | row := db.QueryRow(ctx, claimQueuedWorkflowJob, arg.Labels, arg.RunnerID) |
| 96 | var i ClaimQueuedWorkflowJobRow |
| 97 | err := row.Scan( |
| 98 | &i.ID, |
| 99 | &i.RunID, |
| 100 | &i.JobIndex, |
| 101 | &i.JobKey, |
| 102 | &i.JobName, |
| 103 | &i.RunsOn, |
| 104 | &i.RunnerID, |
| 105 | &i.NeedsJobs, |
| 106 | &i.IfExpr, |
| 107 | &i.TimeoutMinutes, |
| 108 | &i.Permissions, |
| 109 | &i.JobEnv, |
| 110 | &i.Status, |
| 111 | &i.Conclusion, |
| 112 | &i.CancelRequested, |
| 113 | &i.StartedAt, |
| 114 | &i.CompletedAt, |
| 115 | &i.Version, |
| 116 | &i.CreatedAt, |
| 117 | &i.UpdatedAt, |
| 118 | &i.RepoID, |
| 119 | &i.RunIndex, |
| 120 | &i.WorkflowFile, |
| 121 | &i.WorkflowName, |
| 122 | &i.HeadSha, |
| 123 | &i.HeadRef, |
| 124 | &i.Event, |
| 125 | &i.EventPayload, |
| 126 | ) |
| 127 | return i, err |
| 128 | } |
| 129 | |
| 130 | const countRunningJobsForRunner = `-- name: CountRunningJobsForRunner :one |
| 131 | SELECT COUNT(*)::integer |
| 132 | FROM workflow_jobs |
| 133 | WHERE runner_id = $1::bigint AND status = 'running' |
| 134 | ` |
| 135 | |
| 136 | func (q *Queries) CountRunningJobsForRunner(ctx context.Context, db DBTX, runnerID int64) (int32, error) { |
| 137 | row := db.QueryRow(ctx, countRunningJobsForRunner, runnerID) |
| 138 | var column_1 int32 |
| 139 | err := row.Scan(&column_1) |
| 140 | return column_1, err |
| 141 | } |
| 142 | |
| 143 | const getWorkflowJobByID = `-- name: GetWorkflowJobByID :one |
| 144 | SELECT id, run_id, job_index, job_key, job_name, runs_on, |
| 145 | runner_id, needs_jobs, if_expr, timeout_minutes, permissions, |
| 146 | job_env, status, conclusion, cancel_requested, |
| 147 | started_at, completed_at, version, created_at, updated_at |
| 148 | FROM workflow_jobs |
| 149 | WHERE id = $1 |
| 150 | ` |
| 151 | |
| 152 | func (q *Queries) GetWorkflowJobByID(ctx context.Context, db DBTX, id int64) (WorkflowJob, error) { |
| 153 | row := db.QueryRow(ctx, getWorkflowJobByID, id) |
| 154 | var i WorkflowJob |
| 155 | err := row.Scan( |
| 156 | &i.ID, |
| 157 | &i.RunID, |
| 158 | &i.JobIndex, |
| 159 | &i.JobKey, |
| 160 | &i.JobName, |
| 161 | &i.RunsOn, |
| 162 | &i.RunnerID, |
| 163 | &i.NeedsJobs, |
| 164 | &i.IfExpr, |
| 165 | &i.TimeoutMinutes, |
| 166 | &i.Permissions, |
| 167 | &i.JobEnv, |
| 168 | &i.Status, |
| 169 | &i.Conclusion, |
| 170 | &i.CancelRequested, |
| 171 | &i.StartedAt, |
| 172 | &i.CompletedAt, |
| 173 | &i.Version, |
| 174 | &i.CreatedAt, |
| 175 | &i.UpdatedAt, |
| 176 | ) |
| 177 | return i, err |
| 178 | } |
| 179 | |
| 180 | const insertWorkflowJob = `-- name: InsertWorkflowJob :one |
| 181 | |
| 182 | INSERT INTO workflow_jobs ( |
| 183 | run_id, job_index, job_key, job_name, |
| 184 | runs_on, needs_jobs, if_expr, timeout_minutes, |
| 185 | permissions, job_env |
| 186 | ) VALUES ( |
| 187 | $1, $2, $3, $4, $5, $6, $7, $8, $9, $10 |
| 188 | ) |
| 189 | RETURNING id, run_id, job_index, job_key, job_name, runs_on, |
| 190 | runner_id, needs_jobs, if_expr, timeout_minutes, permissions, |
| 191 | job_env, status, conclusion, cancel_requested, |
| 192 | started_at, completed_at, version, created_at, updated_at |
| 193 | ` |
| 194 | |
| 195 | type InsertWorkflowJobParams struct { |
| 196 | RunID int64 |
| 197 | JobIndex int32 |
| 198 | JobKey string |
| 199 | JobName string |
| 200 | RunsOn string |
| 201 | NeedsJobs []string |
| 202 | IfExpr string |
| 203 | TimeoutMinutes int32 |
| 204 | Permissions []byte |
| 205 | JobEnv []byte |
| 206 | } |
| 207 | |
| 208 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 209 | func (q *Queries) InsertWorkflowJob(ctx context.Context, db DBTX, arg InsertWorkflowJobParams) (WorkflowJob, error) { |
| 210 | row := db.QueryRow(ctx, insertWorkflowJob, |
| 211 | arg.RunID, |
| 212 | arg.JobIndex, |
| 213 | arg.JobKey, |
| 214 | arg.JobName, |
| 215 | arg.RunsOn, |
| 216 | arg.NeedsJobs, |
| 217 | arg.IfExpr, |
| 218 | arg.TimeoutMinutes, |
| 219 | arg.Permissions, |
| 220 | arg.JobEnv, |
| 221 | ) |
| 222 | var i WorkflowJob |
| 223 | err := row.Scan( |
| 224 | &i.ID, |
| 225 | &i.RunID, |
| 226 | &i.JobIndex, |
| 227 | &i.JobKey, |
| 228 | &i.JobName, |
| 229 | &i.RunsOn, |
| 230 | &i.RunnerID, |
| 231 | &i.NeedsJobs, |
| 232 | &i.IfExpr, |
| 233 | &i.TimeoutMinutes, |
| 234 | &i.Permissions, |
| 235 | &i.JobEnv, |
| 236 | &i.Status, |
| 237 | &i.Conclusion, |
| 238 | &i.CancelRequested, |
| 239 | &i.StartedAt, |
| 240 | &i.CompletedAt, |
| 241 | &i.Version, |
| 242 | &i.CreatedAt, |
| 243 | &i.UpdatedAt, |
| 244 | ) |
| 245 | return i, err |
| 246 | } |
| 247 | |
| 248 | const listJobsForRun = `-- name: ListJobsForRun :many |
| 249 | SELECT id, run_id, job_index, job_key, job_name, runs_on, status, |
| 250 | conclusion, started_at, completed_at, created_at |
| 251 | FROM workflow_jobs |
| 252 | WHERE run_id = $1 |
| 253 | ORDER BY job_index ASC |
| 254 | ` |
| 255 | |
| 256 | type ListJobsForRunRow struct { |
| 257 | ID int64 |
| 258 | RunID int64 |
| 259 | JobIndex int32 |
| 260 | JobKey string |
| 261 | JobName string |
| 262 | RunsOn string |
| 263 | Status WorkflowJobStatus |
| 264 | Conclusion NullCheckConclusion |
| 265 | StartedAt pgtype.Timestamptz |
| 266 | CompletedAt pgtype.Timestamptz |
| 267 | CreatedAt pgtype.Timestamptz |
| 268 | } |
| 269 | |
| 270 | func (q *Queries) ListJobsForRun(ctx context.Context, db DBTX, runID int64) ([]ListJobsForRunRow, error) { |
| 271 | rows, err := db.Query(ctx, listJobsForRun, runID) |
| 272 | if err != nil { |
| 273 | return nil, err |
| 274 | } |
| 275 | defer rows.Close() |
| 276 | items := []ListJobsForRunRow{} |
| 277 | for rows.Next() { |
| 278 | var i ListJobsForRunRow |
| 279 | if err := rows.Scan( |
| 280 | &i.ID, |
| 281 | &i.RunID, |
| 282 | &i.JobIndex, |
| 283 | &i.JobKey, |
| 284 | &i.JobName, |
| 285 | &i.RunsOn, |
| 286 | &i.Status, |
| 287 | &i.Conclusion, |
| 288 | &i.StartedAt, |
| 289 | &i.CompletedAt, |
| 290 | &i.CreatedAt, |
| 291 | ); err != nil { |
| 292 | return nil, err |
| 293 | } |
| 294 | items = append(items, i) |
| 295 | } |
| 296 | if err := rows.Err(); err != nil { |
| 297 | return nil, err |
| 298 | } |
| 299 | return items, nil |
| 300 | } |
| 301 | |
| 302 | const updateWorkflowJobStatus = `-- name: UpdateWorkflowJobStatus :one |
| 303 | UPDATE workflow_jobs |
| 304 | SET status = $2, |
| 305 | conclusion = $3::check_conclusion, |
| 306 | started_at = $4::timestamptz, |
| 307 | completed_at = $5::timestamptz, |
| 308 | version = version + 1, |
| 309 | updated_at = now() |
| 310 | WHERE id = $1 |
| 311 | RETURNING id, run_id, job_index, job_key, job_name, runs_on, |
| 312 | runner_id, needs_jobs, if_expr, timeout_minutes, permissions, |
| 313 | job_env, status, conclusion, cancel_requested, |
| 314 | started_at, completed_at, version, created_at, updated_at |
| 315 | ` |
| 316 | |
| 317 | type UpdateWorkflowJobStatusParams struct { |
| 318 | ID int64 |
| 319 | Status WorkflowJobStatus |
| 320 | Conclusion NullCheckConclusion |
| 321 | StartedAt pgtype.Timestamptz |
| 322 | CompletedAt pgtype.Timestamptz |
| 323 | } |
| 324 | |
| 325 | func (q *Queries) UpdateWorkflowJobStatus(ctx context.Context, db DBTX, arg UpdateWorkflowJobStatusParams) (WorkflowJob, error) { |
| 326 | row := db.QueryRow(ctx, updateWorkflowJobStatus, |
| 327 | arg.ID, |
| 328 | arg.Status, |
| 329 | arg.Conclusion, |
| 330 | arg.StartedAt, |
| 331 | arg.CompletedAt, |
| 332 | ) |
| 333 | var i WorkflowJob |
| 334 | err := row.Scan( |
| 335 | &i.ID, |
| 336 | &i.RunID, |
| 337 | &i.JobIndex, |
| 338 | &i.JobKey, |
| 339 | &i.JobName, |
| 340 | &i.RunsOn, |
| 341 | &i.RunnerID, |
| 342 | &i.NeedsJobs, |
| 343 | &i.IfExpr, |
| 344 | &i.TimeoutMinutes, |
| 345 | &i.Permissions, |
| 346 | &i.JobEnv, |
| 347 | &i.Status, |
| 348 | &i.Conclusion, |
| 349 | &i.CancelRequested, |
| 350 | &i.StartedAt, |
| 351 | &i.CompletedAt, |
| 352 | &i.Version, |
| 353 | &i.CreatedAt, |
| 354 | &i.UpdatedAt, |
| 355 | ) |
| 356 | return i, err |
| 357 | } |
| 358 |