Files
hatchet/internal/repository/prisma/dbsqlc/step_runs.sql.go
T
abelanger5 092f54c64f refactor: separate api and engine repositories, change ticker logic (#281)
* refactor: separate api and engine repositories, change ticker logic

* fix: nil error blocks

* fix: run migration on load test

* fix: generate db package in load test

* fix: test.yml

* fix: add pnpm to load test

* fix: don't lock CTEs with columns that don't get updated

* fix: update heartbeat for worker every 4 seconds, not 5

* chore: remove dead code

* chore: update python sdk

* chore: add back telemetry attributes
2024-03-21 14:10:34 -04:00

897 lines
25 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.24.0
// source: step_runs.sql
package dbsqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const archiveStepRunResultFromStepRun = `-- name: ArchiveStepRunResultFromStepRun :one
WITH step_run_data AS (
SELECT
"id" AS step_run_id,
"createdAt",
"updatedAt",
"deletedAt",
"order",
"input",
"output",
"error",
"startedAt",
"finishedAt",
"timeoutAt",
"cancelledAt",
"cancelledReason",
"cancelledError"
FROM "StepRun"
WHERE "id" = $2::uuid AND "tenantId" = $3::uuid
)
INSERT INTO "StepRunResultArchive" (
"id",
"createdAt",
"updatedAt",
"deletedAt",
"stepRunId",
"input",
"output",
"error",
"startedAt",
"finishedAt",
"timeoutAt",
"cancelledAt",
"cancelledReason",
"cancelledError"
)
SELECT
COALESCE($1::uuid, gen_random_uuid()),
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
step_run_data."deletedAt",
step_run_data.step_run_id,
step_run_data."input",
step_run_data."output",
step_run_data."error",
step_run_data."startedAt",
step_run_data."finishedAt",
step_run_data."timeoutAt",
step_run_data."cancelledAt",
step_run_data."cancelledReason",
step_run_data."cancelledError"
FROM step_run_data
RETURNING id, "createdAt", "updatedAt", "deletedAt", "stepRunId", "order", input, output, error, "startedAt", "finishedAt", "timeoutAt", "cancelledAt", "cancelledReason", "cancelledError"
`
type ArchiveStepRunResultFromStepRunParams struct {
ID pgtype.UUID `json:"id"`
Steprunid pgtype.UUID `json:"steprunid"`
Tenantid pgtype.UUID `json:"tenantid"`
}
func (q *Queries) ArchiveStepRunResultFromStepRun(ctx context.Context, db DBTX, arg ArchiveStepRunResultFromStepRunParams) (*StepRunResultArchive, error) {
row := db.QueryRow(ctx, archiveStepRunResultFromStepRun, arg.ID, arg.Steprunid, arg.Tenantid)
var i StepRunResultArchive
err := row.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.DeletedAt,
&i.StepRunId,
&i.Order,
&i.Input,
&i.Output,
&i.Error,
&i.StartedAt,
&i.FinishedAt,
&i.TimeoutAt,
&i.CancelledAt,
&i.CancelledReason,
&i.CancelledError,
)
return &i, err
}
const assignStepRunToWorker = `-- name: AssignStepRunToWorker :one
WITH step_run AS (
SELECT
sr."id",
sr."status",
a."id" AS "actionId",
s."timeout" AS "stepTimeout"
FROM
"StepRun" sr
JOIN
"Step" s ON sr."stepId" = s."id"
JOIN
"Action" a ON s."actionId" = a."actionId" AND a."tenantId" = $2::uuid
WHERE
sr."id" = $1::uuid AND
sr."tenantId" = $2::uuid
),
valid_workers AS (
SELECT
w."id", w."dispatcherId"
FROM
"Worker" w, step_run
WHERE
w."tenantId" = $2::uuid
AND w."lastHeartbeatAt" > NOW() - INTERVAL '5 seconds'
AND w."id" IN (
SELECT "_ActionToWorker"."B"
FROM "_ActionToWorker"
INNER JOIN "Action" ON "Action"."id" = "_ActionToWorker"."A"
WHERE "Action"."tenantId" = $2 AND "Action"."id" = step_run."actionId"
)
AND (
w."maxRuns" IS NULL OR
w."maxRuns" > (
SELECT COUNT(*)
FROM "StepRun" srs
WHERE srs."workerId" = w."id" AND srs."status" = 'RUNNING'
)
)
ORDER BY random()
),
selected_worker AS (
SELECT "id", "dispatcherId"
FROM valid_workers
LIMIT 1
)
UPDATE
"StepRun"
SET
"status" = 'ASSIGNED',
"workerId" = (
SELECT "id"
FROM selected_worker
LIMIT 1
),
"updatedAt" = CURRENT_TIMESTAMP,
"timeoutAt" = CASE
WHEN (SELECT "stepTimeout" FROM step_run) IS NOT NULL THEN
CURRENT_TIMESTAMP + convert_duration_to_interval((SELECT "stepTimeout" FROM step_run))
ELSE CURRENT_TIMESTAMP + INTERVAL '5 minutes'
END
WHERE
"id" = $1::uuid AND
"tenantId" = $2::uuid AND
EXISTS (SELECT 1 FROM selected_worker)
RETURNING "StepRun"."id", "StepRun"."workerId", (SELECT "dispatcherId" FROM selected_worker) AS "dispatcherId"
`
type AssignStepRunToWorkerParams struct {
Steprunid pgtype.UUID `json:"steprunid"`
Tenantid pgtype.UUID `json:"tenantid"`
}
type AssignStepRunToWorkerRow struct {
ID pgtype.UUID `json:"id"`
WorkerId pgtype.UUID `json:"workerId"`
DispatcherId pgtype.UUID `json:"dispatcherId"`
}
func (q *Queries) AssignStepRunToWorker(ctx context.Context, db DBTX, arg AssignStepRunToWorkerParams) (*AssignStepRunToWorkerRow, error) {
row := db.QueryRow(ctx, assignStepRunToWorker, arg.Steprunid, arg.Tenantid)
var i AssignStepRunToWorkerRow
err := row.Scan(&i.ID, &i.WorkerId, &i.DispatcherId)
return &i, err
}
const getStepRun = `-- name: GetStepRun :one
SELECT
"StepRun".id, "StepRun"."createdAt", "StepRun"."updatedAt", "StepRun"."deletedAt", "StepRun"."tenantId", "StepRun"."jobRunId", "StepRun"."stepId", "StepRun"."order", "StepRun"."workerId", "StepRun"."tickerId", "StepRun".status, "StepRun".input, "StepRun".output, "StepRun"."requeueAfter", "StepRun"."scheduleTimeoutAt", "StepRun".error, "StepRun"."startedAt", "StepRun"."finishedAt", "StepRun"."timeoutAt", "StepRun"."cancelledAt", "StepRun"."cancelledReason", "StepRun"."cancelledError", "StepRun"."inputSchema", "StepRun"."callerFiles", "StepRun"."gitRepoBranch", "StepRun"."retryCount"
FROM
"StepRun"
WHERE
"id" = $1::uuid AND
"tenantId" = $2::uuid
`
type GetStepRunParams struct {
ID pgtype.UUID `json:"id"`
Tenantid pgtype.UUID `json:"tenantid"`
}
func (q *Queries) GetStepRun(ctx context.Context, db DBTX, arg GetStepRunParams) (*StepRun, error) {
row := db.QueryRow(ctx, getStepRun, arg.ID, arg.Tenantid)
var i StepRun
err := row.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.DeletedAt,
&i.TenantId,
&i.JobRunId,
&i.StepId,
&i.Order,
&i.WorkerId,
&i.TickerId,
&i.Status,
&i.Input,
&i.Output,
&i.RequeueAfter,
&i.ScheduleTimeoutAt,
&i.Error,
&i.StartedAt,
&i.FinishedAt,
&i.TimeoutAt,
&i.CancelledAt,
&i.CancelledReason,
&i.CancelledError,
&i.InputSchema,
&i.CallerFiles,
&i.GitRepoBranch,
&i.RetryCount,
)
return &i, err
}
const getStepRunForEngine = `-- name: GetStepRunForEngine :many
SELECT
sr.id, sr."createdAt", sr."updatedAt", sr."deletedAt", sr."tenantId", sr."jobRunId", sr."stepId", sr."order", sr."workerId", sr."tickerId", sr.status, sr.input, sr.output, sr."requeueAfter", sr."scheduleTimeoutAt", sr.error, sr."startedAt", sr."finishedAt", sr."timeoutAt", sr."cancelledAt", sr."cancelledReason", sr."cancelledError", sr."inputSchema", sr."callerFiles", sr."gitRepoBranch", sr."retryCount",
jrld."data" AS "jobRunLookupData",
-- TODO: everything below this line is cacheable and should be moved to a separate query
jr."id" AS "jobRunId",
wr."id" AS "workflowRunId",
s."id" AS "stepId",
s."retries" AS "stepRetries",
s."scheduleTimeout" AS "stepScheduleTimeout",
s."readableId" AS "stepReadableId",
s."customUserData" AS "stepCustomUserData",
j."name" AS "jobName",
j."id" AS "jobId",
wv."id" AS "workflowVersionId",
w."name" AS "workflowName",
w."id" AS "workflowId",
a."actionId" AS "actionId"
FROM
"StepRun" sr
JOIN
"Step" s ON sr."stepId" = s."id"
JOIN
"Action" a ON s."actionId" = a."actionId"
JOIN
"JobRun" jr ON sr."jobRunId" = jr."id"
JOIN
"JobRunLookupData" jrld ON jr."id" = jrld."jobRunId"
JOIN
"Job" j ON jr."jobId" = j."id"
JOIN
"WorkflowRun" wr ON jr."workflowRunId" = wr."id"
JOIN
"WorkflowVersion" wv ON wr."workflowVersionId" = wv."id"
JOIN
"Workflow" w ON wv."workflowId" = w."id"
WHERE
sr."id" = ANY($1::uuid[]) AND
(
$2::uuid IS NULL OR
sr."tenantId" = $2::uuid
)
`
type GetStepRunForEngineParams struct {
Ids []pgtype.UUID `json:"ids"`
TenantId pgtype.UUID `json:"tenantId"`
}
type GetStepRunForEngineRow struct {
StepRun StepRun `json:"step_run"`
JobRunLookupData []byte `json:"jobRunLookupData"`
JobRunId pgtype.UUID `json:"jobRunId"`
WorkflowRunId pgtype.UUID `json:"workflowRunId"`
StepId pgtype.UUID `json:"stepId"`
StepRetries int32 `json:"stepRetries"`
StepScheduleTimeout string `json:"stepScheduleTimeout"`
StepReadableId pgtype.Text `json:"stepReadableId"`
StepCustomUserData []byte `json:"stepCustomUserData"`
JobName string `json:"jobName"`
JobId pgtype.UUID `json:"jobId"`
WorkflowVersionId pgtype.UUID `json:"workflowVersionId"`
WorkflowName string `json:"workflowName"`
WorkflowId pgtype.UUID `json:"workflowId"`
ActionId string `json:"actionId"`
}
func (q *Queries) GetStepRunForEngine(ctx context.Context, db DBTX, arg GetStepRunForEngineParams) ([]*GetStepRunForEngineRow, error) {
rows, err := db.Query(ctx, getStepRunForEngine, arg.Ids, arg.TenantId)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*GetStepRunForEngineRow
for rows.Next() {
var i GetStepRunForEngineRow
if err := rows.Scan(
&i.StepRun.ID,
&i.StepRun.CreatedAt,
&i.StepRun.UpdatedAt,
&i.StepRun.DeletedAt,
&i.StepRun.TenantId,
&i.StepRun.JobRunId,
&i.StepRun.StepId,
&i.StepRun.Order,
&i.StepRun.WorkerId,
&i.StepRun.TickerId,
&i.StepRun.Status,
&i.StepRun.Input,
&i.StepRun.Output,
&i.StepRun.RequeueAfter,
&i.StepRun.ScheduleTimeoutAt,
&i.StepRun.Error,
&i.StepRun.StartedAt,
&i.StepRun.FinishedAt,
&i.StepRun.TimeoutAt,
&i.StepRun.CancelledAt,
&i.StepRun.CancelledReason,
&i.StepRun.CancelledError,
&i.StepRun.InputSchema,
&i.StepRun.CallerFiles,
&i.StepRun.GitRepoBranch,
&i.StepRun.RetryCount,
&i.JobRunLookupData,
&i.JobRunId,
&i.WorkflowRunId,
&i.StepId,
&i.StepRetries,
&i.StepScheduleTimeout,
&i.StepReadableId,
&i.StepCustomUserData,
&i.JobName,
&i.JobId,
&i.WorkflowVersionId,
&i.WorkflowName,
&i.WorkflowId,
&i.ActionId,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listStartableStepRuns = `-- name: ListStartableStepRuns :many
WITH job_run AS (
SELECT "status"
FROM "JobRun"
WHERE "id" = $1::uuid
)
SELECT
child_run."id" AS "id"
FROM
"StepRun" AS child_run
LEFT JOIN
"_StepRunOrder" AS step_run_order ON step_run_order."B" = child_run."id"
JOIN
job_run ON true
WHERE
child_run."jobRunId" = $1::uuid
AND child_run."status" = 'PENDING'
AND job_run."status" = 'RUNNING'
-- case on whether parentStepRunId is null
AND (
($2::uuid IS NULL AND step_run_order."A" IS NULL) OR
(
step_run_order."A" = $2::uuid
AND NOT EXISTS (
SELECT 1
FROM "_StepRunOrder" AS parent_order
JOIN "StepRun" AS parent_run ON parent_order."A" = parent_run."id"
WHERE
parent_order."B" = child_run."id"
AND parent_run."status" != 'SUCCEEDED'
)
)
)
`
type ListStartableStepRunsParams struct {
Jobrunid pgtype.UUID `json:"jobrunid"`
ParentStepRunId pgtype.UUID `json:"parentStepRunId"`
}
func (q *Queries) ListStartableStepRuns(ctx context.Context, db DBTX, arg ListStartableStepRunsParams) ([]pgtype.UUID, error) {
rows, err := db.Query(ctx, listStartableStepRuns, arg.Jobrunid, arg.ParentStepRunId)
if err != nil {
return nil, err
}
defer rows.Close()
var items []pgtype.UUID
for rows.Next() {
var id pgtype.UUID
if err := rows.Scan(&id); err != nil {
return nil, err
}
items = append(items, id)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listStepRuns = `-- name: ListStepRuns :many
SELECT
"StepRun"."id"
FROM
"StepRun"
JOIN
"JobRun" ON "StepRun"."jobRunId" = "JobRun"."id"
WHERE
"StepRun"."tenantId" = $1::uuid
AND (
$2::"StepRunStatus" IS NULL OR
"StepRun"."status" = $2::"StepRunStatus"
)
AND (
$3::uuid IS NULL OR
"JobRun"."workflowRunId" = $3::uuid
)
AND (
$4::uuid IS NULL OR
"StepRun"."jobRunId" = $4::uuid
)
AND (
$5::uuid IS NULL OR
"StepRun"."tickerId" = $5::uuid
)
`
type ListStepRunsParams struct {
Tenantid pgtype.UUID `json:"tenantid"`
Status NullStepRunStatus `json:"status"`
WorkflowRunId pgtype.UUID `json:"workflowRunId"`
JobRunId pgtype.UUID `json:"jobRunId"`
TickerId pgtype.UUID `json:"tickerId"`
}
func (q *Queries) ListStepRuns(ctx context.Context, db DBTX, arg ListStepRunsParams) ([]pgtype.UUID, error) {
rows, err := db.Query(ctx, listStepRuns,
arg.Tenantid,
arg.Status,
arg.WorkflowRunId,
arg.JobRunId,
arg.TickerId,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []pgtype.UUID
for rows.Next() {
var id pgtype.UUID
if err := rows.Scan(&id); err != nil {
return nil, err
}
items = append(items, id)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listStepRunsToReassign = `-- name: ListStepRunsToReassign :many
SELECT
sr.id, sr."createdAt", sr."updatedAt", sr."deletedAt", sr."tenantId", sr."jobRunId", sr."stepId", sr."order", sr."workerId", sr."tickerId", sr.status, sr.input, sr.output, sr."requeueAfter", sr."scheduleTimeoutAt", sr.error, sr."startedAt", sr."finishedAt", sr."timeoutAt", sr."cancelledAt", sr."cancelledReason", sr."cancelledError", sr."inputSchema", sr."callerFiles", sr."gitRepoBranch", sr."retryCount"
FROM
"StepRun" sr
LEFT JOIN
"Worker" w ON sr."workerId" = w."id"
JOIN
"Step" s ON sr."stepId" = s."id"
WHERE
sr."tenantId" = $1::uuid
AND ((
sr."status" = 'RUNNING'
AND w."lastHeartbeatAt" < NOW() - INTERVAL '60 seconds'
AND s."retries" > sr."retryCount"
) OR (
sr."status" = 'ASSIGNED'
AND w."lastHeartbeatAt" < NOW() - INTERVAL '5 seconds'
))
-- Step run cannot have a failed parent
AND NOT EXISTS (
SELECT 1
FROM "_StepRunOrder" AS order_table
JOIN "StepRun" AS prev_sr ON order_table."A" = prev_sr."id"
WHERE
order_table."B" = sr."id"
AND prev_sr."status" != 'SUCCEEDED'
)
ORDER BY
sr."createdAt" ASC
`
func (q *Queries) ListStepRunsToReassign(ctx context.Context, db DBTX, tenantid pgtype.UUID) ([]*StepRun, error) {
rows, err := db.Query(ctx, listStepRunsToReassign, tenantid)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*StepRun
for rows.Next() {
var i StepRun
if err := rows.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.DeletedAt,
&i.TenantId,
&i.JobRunId,
&i.StepId,
&i.Order,
&i.WorkerId,
&i.TickerId,
&i.Status,
&i.Input,
&i.Output,
&i.RequeueAfter,
&i.ScheduleTimeoutAt,
&i.Error,
&i.StartedAt,
&i.FinishedAt,
&i.TimeoutAt,
&i.CancelledAt,
&i.CancelledReason,
&i.CancelledError,
&i.InputSchema,
&i.CallerFiles,
&i.GitRepoBranch,
&i.RetryCount,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listStepRunsToRequeue = `-- name: ListStepRunsToRequeue :many
SELECT
sr.id, sr."createdAt", sr."updatedAt", sr."deletedAt", sr."tenantId", sr."jobRunId", sr."stepId", sr."order", sr."workerId", sr."tickerId", sr.status, sr.input, sr.output, sr."requeueAfter", sr."scheduleTimeoutAt", sr.error, sr."startedAt", sr."finishedAt", sr."timeoutAt", sr."cancelledAt", sr."cancelledReason", sr."cancelledError", sr."inputSchema", sr."callerFiles", sr."gitRepoBranch", sr."retryCount"
FROM
"StepRun" sr
LEFT JOIN
"Worker" w ON sr."workerId" = w."id"
JOIN
"JobRun" jr ON sr."jobRunId" = jr."id"
WHERE
sr."tenantId" = $1::uuid
AND sr."requeueAfter" < NOW()
AND (sr."status" = 'PENDING' OR sr."status" = 'PENDING_ASSIGNMENT')
AND jr."status" = 'RUNNING'
AND NOT EXISTS (
SELECT 1
FROM "_StepRunOrder" AS order_table
JOIN "StepRun" AS prev_sr ON order_table."A" = prev_sr."id"
WHERE
order_table."B" = sr."id"
AND prev_sr."status" != 'SUCCEEDED'
)
ORDER BY
sr."createdAt" ASC
`
func (q *Queries) ListStepRunsToRequeue(ctx context.Context, db DBTX, tenantid pgtype.UUID) ([]*StepRun, error) {
rows, err := db.Query(ctx, listStepRunsToRequeue, tenantid)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*StepRun
for rows.Next() {
var i StepRun
if err := rows.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.DeletedAt,
&i.TenantId,
&i.JobRunId,
&i.StepId,
&i.Order,
&i.WorkerId,
&i.TickerId,
&i.Status,
&i.Input,
&i.Output,
&i.RequeueAfter,
&i.ScheduleTimeoutAt,
&i.Error,
&i.StartedAt,
&i.FinishedAt,
&i.TimeoutAt,
&i.CancelledAt,
&i.CancelledReason,
&i.CancelledError,
&i.InputSchema,
&i.CallerFiles,
&i.GitRepoBranch,
&i.RetryCount,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const resolveLaterStepRuns = `-- name: ResolveLaterStepRuns :many
WITH currStepRun AS (
SELECT id, "createdAt", "updatedAt", "deletedAt", "tenantId", "jobRunId", "stepId", "order", "workerId", "tickerId", status, input, output, "requeueAfter", "scheduleTimeoutAt", error, "startedAt", "finishedAt", "timeoutAt", "cancelledAt", "cancelledReason", "cancelledError", "inputSchema", "callerFiles", "gitRepoBranch", "retryCount"
FROM "StepRun"
WHERE
"id" = $1::uuid AND
"tenantId" = $2::uuid
)
UPDATE
"StepRun" as sr
SET "status" = CASE
-- When the given step run has failed or been cancelled, then all later step runs are cancelled
WHEN (cs."status" = 'FAILED' OR cs."status" = 'CANCELLED') THEN 'CANCELLED'
ELSE sr."status"
END,
-- When the previous step run timed out, the cancelled reason is set
"cancelledReason" = CASE
WHEN (cs."status" = 'CANCELLED' AND cs."cancelledReason" = 'TIMED_OUT'::text) THEN 'PREVIOUS_STEP_TIMED_OUT'
WHEN (cs."status" = 'CANCELLED') THEN 'PREVIOUS_STEP_CANCELLED'
ELSE NULL
END
FROM
currStepRun cs
WHERE
sr."jobRunId" = (
SELECT "jobRunId"
FROM "StepRun"
WHERE "id" = $1::uuid
) AND
sr."order" > (
SELECT "order"
FROM "StepRun"
WHERE "id" = $1::uuid
) AND
sr."tenantId" = $2::uuid
RETURNING sr.id, sr."createdAt", sr."updatedAt", sr."deletedAt", sr."tenantId", sr."jobRunId", sr."stepId", sr."order", sr."workerId", sr."tickerId", sr.status, sr.input, sr.output, sr."requeueAfter", sr."scheduleTimeoutAt", sr.error, sr."startedAt", sr."finishedAt", sr."timeoutAt", sr."cancelledAt", sr."cancelledReason", sr."cancelledError", sr."inputSchema", sr."callerFiles", sr."gitRepoBranch", sr."retryCount"
`
type ResolveLaterStepRunsParams struct {
Steprunid pgtype.UUID `json:"steprunid"`
Tenantid pgtype.UUID `json:"tenantid"`
}
func (q *Queries) ResolveLaterStepRuns(ctx context.Context, db DBTX, arg ResolveLaterStepRunsParams) ([]*StepRun, error) {
rows, err := db.Query(ctx, resolveLaterStepRuns, arg.Steprunid, arg.Tenantid)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*StepRun
for rows.Next() {
var i StepRun
if err := rows.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.DeletedAt,
&i.TenantId,
&i.JobRunId,
&i.StepId,
&i.Order,
&i.WorkerId,
&i.TickerId,
&i.Status,
&i.Input,
&i.Output,
&i.RequeueAfter,
&i.ScheduleTimeoutAt,
&i.Error,
&i.StartedAt,
&i.FinishedAt,
&i.TimeoutAt,
&i.CancelledAt,
&i.CancelledReason,
&i.CancelledError,
&i.InputSchema,
&i.CallerFiles,
&i.GitRepoBranch,
&i.RetryCount,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateStepRun = `-- name: UpdateStepRun :one
UPDATE
"StepRun"
SET
"requeueAfter" = COALESCE($1::timestamp, "requeueAfter"),
"scheduleTimeoutAt" = COALESCE($2::timestamp, "scheduleTimeoutAt"),
"startedAt" = COALESCE($3::timestamp, "startedAt"),
"finishedAt" = CASE
-- if this is a rerun, we clear the finishedAt
WHEN $4::boolean THEN NULL
ELSE COALESCE($5::timestamp, "finishedAt")
END,
"status" = CASE
-- if this is a rerun, we permit status updates
WHEN $4::boolean THEN COALESCE($6, "status")
-- Final states are final, cannot be updated
WHEN "status" IN ('SUCCEEDED', 'FAILED', 'CANCELLED') THEN "status"
ELSE COALESCE($6, "status")
END,
"input" = COALESCE($7::jsonb, "input"),
"output" = CASE
-- if this is a rerun, we clear the output
WHEN $4::boolean THEN NULL
ELSE COALESCE($8::jsonb, "output")
END,
"error" = CASE
-- if this is a rerun, we clear the error
WHEN $4::boolean THEN NULL
ELSE COALESCE($9::text, "error")
END,
"cancelledAt" = CASE
-- if this is a rerun, we clear the cancelledAt
WHEN $4::boolean THEN NULL
ELSE COALESCE($10::timestamp, "cancelledAt")
END,
"cancelledReason" = CASE
-- if this is a rerun, we clear the cancelledReason
WHEN $4::boolean THEN NULL
ELSE COALESCE($11::text, "cancelledReason")
END,
"retryCount" = COALESCE($12::int, "retryCount")
WHERE
"id" = $13::uuid AND
"tenantId" = $14::uuid
RETURNING "StepRun".id, "StepRun"."createdAt", "StepRun"."updatedAt", "StepRun"."deletedAt", "StepRun"."tenantId", "StepRun"."jobRunId", "StepRun"."stepId", "StepRun"."order", "StepRun"."workerId", "StepRun"."tickerId", "StepRun".status, "StepRun".input, "StepRun".output, "StepRun"."requeueAfter", "StepRun"."scheduleTimeoutAt", "StepRun".error, "StepRun"."startedAt", "StepRun"."finishedAt", "StepRun"."timeoutAt", "StepRun"."cancelledAt", "StepRun"."cancelledReason", "StepRun"."cancelledError", "StepRun"."inputSchema", "StepRun"."callerFiles", "StepRun"."gitRepoBranch", "StepRun"."retryCount"
`
type UpdateStepRunParams struct {
RequeueAfter pgtype.Timestamp `json:"requeueAfter"`
ScheduleTimeoutAt pgtype.Timestamp `json:"scheduleTimeoutAt"`
StartedAt pgtype.Timestamp `json:"startedAt"`
Rerun pgtype.Bool `json:"rerun"`
FinishedAt pgtype.Timestamp `json:"finishedAt"`
Status NullStepRunStatus `json:"status"`
Input []byte `json:"input"`
Output []byte `json:"output"`
Error pgtype.Text `json:"error"`
CancelledAt pgtype.Timestamp `json:"cancelledAt"`
CancelledReason pgtype.Text `json:"cancelledReason"`
RetryCount pgtype.Int4 `json:"retryCount"`
ID pgtype.UUID `json:"id"`
Tenantid pgtype.UUID `json:"tenantid"`
}
func (q *Queries) UpdateStepRun(ctx context.Context, db DBTX, arg UpdateStepRunParams) (*StepRun, error) {
row := db.QueryRow(ctx, updateStepRun,
arg.RequeueAfter,
arg.ScheduleTimeoutAt,
arg.StartedAt,
arg.Rerun,
arg.FinishedAt,
arg.Status,
arg.Input,
arg.Output,
arg.Error,
arg.CancelledAt,
arg.CancelledReason,
arg.RetryCount,
arg.ID,
arg.Tenantid,
)
var i StepRun
err := row.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.DeletedAt,
&i.TenantId,
&i.JobRunId,
&i.StepId,
&i.Order,
&i.WorkerId,
&i.TickerId,
&i.Status,
&i.Input,
&i.Output,
&i.RequeueAfter,
&i.ScheduleTimeoutAt,
&i.Error,
&i.StartedAt,
&i.FinishedAt,
&i.TimeoutAt,
&i.CancelledAt,
&i.CancelledReason,
&i.CancelledError,
&i.InputSchema,
&i.CallerFiles,
&i.GitRepoBranch,
&i.RetryCount,
)
return &i, err
}
const updateStepRunInputSchema = `-- name: UpdateStepRunInputSchema :one
UPDATE
"StepRun" sr
SET
"inputSchema" = coalesce($1::jsonb, '{}'),
"updatedAt" = CURRENT_TIMESTAMP
WHERE
sr."tenantId" = $2::uuid AND
sr."id" = $3::uuid
RETURNING "inputSchema"
`
type UpdateStepRunInputSchemaParams struct {
InputSchema []byte `json:"inputSchema"`
Tenantid pgtype.UUID `json:"tenantid"`
Steprunid pgtype.UUID `json:"steprunid"`
}
func (q *Queries) UpdateStepRunInputSchema(ctx context.Context, db DBTX, arg UpdateStepRunInputSchemaParams) ([]byte, error) {
row := db.QueryRow(ctx, updateStepRunInputSchema, arg.InputSchema, arg.Tenantid, arg.Steprunid)
var inputSchema []byte
err := row.Scan(&inputSchema)
return inputSchema, err
}
const updateStepRunOverridesData = `-- name: UpdateStepRunOverridesData :one
UPDATE
"StepRun" AS sr
SET
"updatedAt" = CURRENT_TIMESTAMP,
"input" = jsonb_set("input", $1::text[], $2::jsonb, true),
"callerFiles" = jsonb_set("callerFiles", $3::text[], to_jsonb($4::text), true)
WHERE
sr."tenantId" = $5::uuid AND
sr."id" = $6::uuid
RETURNING "input"
`
type UpdateStepRunOverridesDataParams struct {
Fieldpath []string `json:"fieldpath"`
Jsondata []byte `json:"jsondata"`
Overrideskey []string `json:"overrideskey"`
Callerfile string `json:"callerfile"`
Tenantid pgtype.UUID `json:"tenantid"`
Steprunid pgtype.UUID `json:"steprunid"`
}
func (q *Queries) UpdateStepRunOverridesData(ctx context.Context, db DBTX, arg UpdateStepRunOverridesDataParams) ([]byte, error) {
row := db.QueryRow(ctx, updateStepRunOverridesData,
arg.Fieldpath,
arg.Jsondata,
arg.Overrideskey,
arg.Callerfile,
arg.Tenantid,
arg.Steprunid,
)
var input []byte
err := row.Scan(&input)
return input, err
}