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

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Oct 3, 2023

What this does

I am working on pruning some template_versions, and currently provisioner job status is computed in Go. This makes it hard to make status decisions in SQL if I wrote a prune query.

We also duplicate this status logic in the workspaces.sql file for search strings.

To keep status on the job, I added a postgres computed column to keep the status logic in 1 place and attached to the job.

Comment on lines 136 to 153
WHEN @status = 'starting' THEN
latest_build.started_at IS NOT NULL AND
latest_build.canceled_at IS NULL AND
latest_build.completed_at IS NULL AND
latest_build.job_status = 'running' AND
-- TODO: Should we drop the interval? Hung workspaces
-- should still be their last state?
latest_build.updated_at - INTERVAL '30 seconds' < NOW() AND
latest_build.transition = 'start'::workspace_transition

WHEN @status = 'running' THEN
latest_build.completed_at IS NOT NULL AND
latest_build.canceled_at IS NULL AND
latest_build.error IS NULL AND
latest_build.transition = 'start'::workspace_transition

WHEN @status = 'stopping' THEN
latest_build.started_at IS NOT NULL AND
latest_build.canceled_at IS NULL AND
latest_build.completed_at IS NULL AND
latest_build.job_status = 'running' AND
-- TODO: Should we drop the interval? Hung workspaces
-- should still be their last state?
latest_build.updated_at - INTERVAL '30 seconds' < NOW() AND
latest_build.transition = 'stop'::workspace_transition
WHEN @status = 'deleting' THEN
latest_build.job_status = 'running' AND
-- TODO: Should we drop the interval? Hung workspaces
-- should still be their last state?
latest_build.updated_at - INTERVAL '30 seconds' < NOW() AND
latest_build.transition = 'delete'::workspace_transition
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these intervals are to ignore "hung jobs", but it feels odd to include that in some of the statuses, and not others.

I am going to drop the intervals, and defer to somewhere else to detect "hung" state. Like the UI or something. The updated_at timestamp is returned to the caller to decide.

@Emyrk Emyrk changed the title chore: computed job status as column chore: compute job status as column Oct 3, 2023
@Emyrk Emyrk marked this pull request as ready for review October 3, 2023 22:01
@Emyrk Emyrk requested a review from coadler October 3, 2023 22:23
Copy link
Contributor

@coadler coadler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty cool, didn't know about this!

@Emyrk Emyrk merged commit 5021e23 into main Oct 5, 2023
@Emyrk Emyrk deleted the stevenmasley/computed_job_status branch October 5, 2023 01:57
@github-actions github-actions bot locked and limited conversation to collaborators Oct 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants