-
Notifications
You must be signed in to change notification settings - Fork 894
refactor(coderd): collapse activityBumpWorkspace into a single query #9652
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
Changes from 1 commit
e25d8ab
1ee5403
a71a809
3e583d9
1829a25
cf5e55b
5bf3f51
9ac9424
0e8675c
a4a6355
0209449
d05d1f1
b75ff56
9272f4b
49dbc55
50f7578
dc37bf9
5dcb743
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
-- We bump by the original TTL to prevent counter-intuitive behavior | ||
-- as the TTL wraps. For example, if I set the TTL to 12 hours, sign off | ||
-- work at midnight, come back at 10am, I would want another full day | ||
-- of uptime. In the prior implementation, the workspace would enter | ||
-- a state of always expiring 1 hour in the future. | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-- name: ActivityBumpWorkspace :exec | ||
WITH latest AS ( | ||
SELECT | ||
|
@@ -13,7 +18,7 @@ WITH latest AS ( | |
ON provisioner_jobs.id = workspace_builds.job_id | ||
JOIN workspaces | ||
ON workspaces.id = workspace_builds.workspace_id | ||
WHERE workspace_builds.workspace_id = $1::uuid | ||
WHERE workspace_builds.workspace_id = @workspace_id::uuid | ||
ORDER BY workspace_builds.build_number DESC | ||
LIMIT 1 | ||
) | ||
|
@@ -23,19 +28,14 @@ SET | |
updated_at = NOW(), | ||
deadline = CASE | ||
WHEN l.build_max_deadline = '0001-01-01 00:00:00' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, maybe, this actually should be in +00 format (UTC), but it depends on what our default value is and DB being in non-UTC config. I imagine this is something we may be doing (potentially) incorrectly elsewhere too so maybe doesn't need fixing in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, max deadline is |
||
-- We bump by the original TTL to prevent counter-intuitive behavior | ||
-- as the TTL wraps. For example, if I set the TTL to 12 hours, sign off | ||
-- work at midnight, come back at 10am, I would want another full day | ||
-- of uptime. In the prior implementation, the workspace would enter | ||
-- a state of always expiring 1 hour in the future. | ||
THEN l.now_utc + l.ttl_interval | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ELSE LEAST(l.now_utc + l.ttl_interval, l.build_max_deadline) | ||
END | ||
FROM latest l | ||
WHERE wb.id = l.build_id | ||
AND l.job_completed_at IS NOT NULL | ||
AND l.build_transition = 'start' | ||
-- Workspace shutdown is manual. | ||
-- We only bump if workspace shutdown is manual. | ||
AND l.build_deadline != '0001-01-01 00:00:00' | ||
-- We only bump when 5% of the deadline has elapsed. | ||
AND l.build_deadline - (l.ttl_interval * 0.95) < NOW() | ||
|
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.
self-review: I can inline this CTE if required, but I think the readability is important here. I'm preserving the comments from the original pure-Go implementation for reference.