-
Notifications
You must be signed in to change notification settings - Fork 889
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,8 +1,7 @@ | ||
-- 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. | ||
-- of uptime. | ||
-- name: ActivityBumpWorkspace :exec | ||
WITH latest AS ( | ||
SELECT | ||
|
@@ -11,8 +10,7 @@ WITH latest AS ( | |
workspace_builds.max_deadline::timestamp AS build_max_deadline, | ||
workspace_builds.transition AS build_transition, | ||
provisioner_jobs.completed_at::timestamp AS job_completed_at, | ||
(workspaces.ttl / 1000 / 1000 / 1000 || ' seconds')::interval AS ttl_interval, | ||
(NOW() AT TIME ZONE 'UTC')::timestamp as now_utc | ||
(workspaces.ttl / 1000 / 1000 / 1000 || ' seconds')::interval AS ttl_interval | ||
FROM workspace_builds | ||
JOIN provisioner_jobs | ||
ON provisioner_jobs.id = workspace_builds.job_id | ||
|
@@ -28,8 +26,8 @@ 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 |
||
THEN l.now_utc + l.ttl_interval | ||
ELSE LEAST(l.now_utc + l.ttl_interval, l.build_max_deadline) | ||
THEN NOW() + l.ttl_interval | ||
ELSE LEAST(NOW() + l.ttl_interval, l.build_max_deadline) | ||
END | ||
FROM latest l | ||
WHERE wb.id = l.build_id | ||
|
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.