Skip to content

chore: compute job status as column #10024

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 23 commits into from
Oct 5, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
sql spacing
  • Loading branch information
Emyrk committed Oct 3, 2023
commit d028ed1f5206eac8cccbed86f32c9ea014c711e4
46 changes: 23 additions & 23 deletions coderd/database/migrations/000160_provisioner_job_status.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ COMMENT ON TYPE provisioner_job_status IS 'Computed status of a provisioner job.
ALTER TABLE provisioner_jobs ADD COLUMN
job_status provisioner_job_status NOT NULL GENERATED ALWAYS AS (
CASE
-- Completed means it is not in an "-ing" state
WHEN completed_at IS NOT NULL THEN
CASE
-- The order of these checks are important.
-- Check the error first, then cancelled, then completed.
WHEN error != '' THEN 'failed'::provisioner_job_status
WHEN canceled_at IS NOT NULL THEN 'canceled'::provisioner_job_status
ELSE 'succeeded'::provisioner_job_status
END
-- Completed means it is not in an "-ing" state
WHEN completed_at IS NOT NULL THEN
CASE
-- The order of these checks are important.
-- Check the error first, then cancelled, then completed.
WHEN error != '' THEN 'failed'::provisioner_job_status
WHEN canceled_at IS NOT NULL THEN 'canceled'::provisioner_job_status
ELSE 'succeeded'::provisioner_job_status
END
-- Not completed means it is in some "-ing" state
ELSE
CASE
-- This should never happen because all errors set
-- should also set a completed_at timestamp.
-- But if there is an error, we should always return
-- a failed state.
WHEN error != '' THEN 'failed'::provisioner_job_status
WHEN canceled_at IS NOT NULL THEN 'canceling'::provisioner_job_status
-- Not done and not started means it is pending
WHEN started_at IS NULL THEN 'pending'::provisioner_job_status
ELSE 'running'::provisioner_job_status
END
END
ELSE
CASE
-- This should never happen because all errors set
-- should also set a completed_at timestamp.
-- But if there is an error, we should always return
-- a failed state.
WHEN error != '' THEN 'failed'::provisioner_job_status
WHEN canceled_at IS NOT NULL THEN 'canceling'::provisioner_job_status
-- Not done and not started means it is pending
WHEN started_at IS NULL THEN 'pending'::provisioner_job_status
ELSE 'running'::provisioner_job_status
END
END
-- Stored so we do not have to recompute it every time.
) STORED;
) STORED;


COMMENT ON COLUMN provisioner_jobs.job_status IS 'Computed column to track the status of the job.';
Expand Down