8000 fix: branch cancelation strategy by grutt · Pull Request #467 · hatchet-dev/hatchet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: branch cancelation strategy #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions frontend/app/src/pages/main/workflow-runs/$run/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ export default function ExpandedWorkflowRun() {
...queries.workflowRuns.get(tenant.metadata.id, params.run),
refetchInterval: (query) => {
const data = query.state.data;

if (
data?.status != 'SUCCEEDED' &&
data?.status != 'FAILED' &&
data?.status != 'CANCELLED'
data &&
data.jobRuns &&
data.jobRuns.some((x) => x.status === 'RUNNING')
) {
return 1000;
}
Expand Down
5 changes: 3 additions & 2 deletions internal/repository/prisma/dbsqlc/job_runs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ UPDATE "JobRun"
SET "status" = CASE
-- Final states are final, cannot be updated
WHEN "status" IN ('SUCCEEDED', 'FAILED', 'CANCELLED') THEN "status"
-- NOTE: Order of the following conditions is important
-- When one step run is running, then the job is running
WHEN (s.runningRuns > 0 OR s.pendingRuns > 0) THEN 'RUNNING'
-- When one step run has failed, then the job is failed
WHEN s.failedRuns > 0 THEN 'FAILED'
-- When one step run is running, then the job is running
WHEN s.runningRuns > 0 THEN 'RUNNING'
-- When one step run has been cancelled, then the job is cancelled
WHEN s.cancelledRuns > 0 THEN 'CANCELLED'
-- When no step runs exist that are not succeeded, then the job is succeeded
Expand Down
5 changes: 3 additions & 2 deletions internal/repository/prisma/dbsqlc/job_runs.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 21 additions & 17 deletions internal/repository/prisma/dbsqlc/step_runs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -175,43 +175,47 @@ WHERE
RETURNING *;

-- name: ResolveLaterStepRuns :many
WITH currStepRun AS (
WITH RECURSIVE currStepRun AS (
SELECT *
FROM "StepRun"
WHERE
"id" = @stepRunId::uuid AND
"tenantId" = @tenantId::uuid
), childStepRuns AS (
SELECT sr."id", sr."status"
FROM "StepRun" sr
JOIN "_StepRunOrder" sro ON sr."id" = sro."B"
WHERE sro."A" = (SELECT "id" FROM currStepRun)

UNION ALL

SELECT sr."id", sr."status"
FROM "StepRun" sr
JOIN "_StepRunOrder" sro ON sr."id" = sro."B"
JOIN childStepRuns csr ON sro."A" = csr."id"
)
UPDATE
"StepRun" as sr
SET "status" = CASE
SET "status" = CASE
-- When the step is in a final state, it cannot be updated
WHEN sr."status" IN ('SUCCEEDED', 'FAILED', 'CANCELLED') THEN sr."status"
-- 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'
-- When the given step run has failed or been cancelled, then all child step runs are cancelled
WHEN (SELECT "status" FROM currStepRun) IN ('FAILED', 'CANCELLED') THEN 'CANCELLED'
ELSE sr."status"
END,
-- When the previous step run timed out, the cancelled reason is set
"cancelledReason" = CASE
-- When the step is in a final state, it cannot be updated
WHEN sr."status" IN ('SUCCEEDED', 'FAILED', 'CANCELLED') THEN sr."cancelledReason"
WHEN (cs."status" = 'CANCELLED' AND cs."cancelledReason" = 'TIMED_OUT'::text) THEN 'PREVIOUS_STEP_TIMED_OUT'
WHEN (cs."status" = 'CANCELLED') THEN 'PREVIOUS_STEP_CANCELLED'
WHEN (SELECT "status" FROM currStepRun) = 'CANCELLED' AND (SELECT "cancelledReason" FROM currStepRun) = 'TIMED_OUT'::text THEN 'PREVIOUS_STEP_TIMED_OUT'
WHEN (SELECT "status" FROM currStepRun) = 'FAILED' THEN 'PREVIOUS_STEP_FAILED'
WHEN (SELECT "status" FROM currStepRun) = 'CANCELLED' THEN 'PREVIOUS_STEP_CANCELLED'
ELSE NULL
END
FROM
currStepRun cs
childStepRuns csr
WHERE
sr."jobRunId" = (
SELECT "jobRunId"
FROM "StepRun"
WHERE "id" = @stepRunId::uuid
) AND
sr."order" > (
SELECT "order"
FROM "StepRun"
WHERE "id" = @stepRunId::uuid
) AND
sr."id" = csr."id" AND
sr."tenantId" = @tenantId::uuid
RETURNING sr.*;

Expand Down
48 changes: 26 additions & 22 deletions internal/repository/prisma/dbsqlc/step_runs.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
0