-
Notifications
You must be signed in to change notification settings - Fork 887
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
Conversation
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
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.