-
Notifications
You must be signed in to change notification settings - Fork 886
feat: increase autostop deadline if it passes autostart #10035
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
If the autostop deadline passes the next autostart deadline, increase the autostop deadline to be `next_autostart + ttl` instead of `now + ttl`. This applies both on workspace build and periodically via the lifecycle executor system. It cannot happen immediately on activity bump as there's no way to execute cron statements in the database.
( | ||
CASE | ||
WHEN templates.allow_user_autostop | ||
THEN workspaces.ttl | ||
ELSE templates.default_ttl | ||
END | ||
) AS raw_ttl_interval, | ||
(raw_ttl_interval / 1000 / 1000 / 1000 || ' seconds')::interval AS ttl_interval |
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.
🙏
-- - an autostop if it's past the deadline | ||
-- - a deadline bump if it's currently running and has a deadline | ||
-- The deadline is computed at build time upon success and is bumped | ||
-- based on activity (up the max deadline if set). We don't need to |
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.
-- based on activity (up the max deadline if set). We don't need to | |
-- based on activity (up to the max deadline if set). We don't need to |
case !shouldBump(ws, latestBuild, latestJob, templateSchedule, currentTick).IsZero(): | ||
return "", database.BuildReasonBump, nil |
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.
Currently we only bump a workspace build if there are a non-zero number of connections. Will this end up bumping workspace deadlines regardless of connection count?
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.
Also, add a test to make sure it doesn't double bump
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.
Yes this will bump regardless of connection count. We want to bump if the build lasts until the next autostart time.
|
||
// shouldBump returns a non-zero time if the workspace deadline should | ||
// should be bumped. | ||
func shouldBump(ws database.Workspace, build database.WorkspaceBuild, job database.ProvisionerJob, templateSchedule schedule.TemplateScheduleOptions, currentTick time.Time) time.Time { |
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.
nit: suggest renaming this to nextBumpDeadline
or something for clarity
return ttl | ||
} | ||
|
||
// MaybeBumpDeadline may bump the deadline of the workspace if the deadline |
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.
// MaybeBumpDeadline may bump the deadline of the workspace if the deadline | |
// MaybeBumpDeadline returns the next allowed deadline of the workspace if the deadline |
// be used as the new deadline. | ||
// | ||
// The MaxDeadline is not taken into account. | ||
func MaybeBumpDeadline(autostartSchedule *cron.Schedule, deadline time.Time, ttl time.Duration) time.Time { |
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.
nit: suggest renaming this to CalculateNextBumpDeadline
@deansheather I broke out the changes related to You should be able to apply this commit to remove the changes from this PR. I also rebased your existing changes on current main here: https://github.com/coder/coder/commits/cj/rebase/dean/bump-autostop-if-exceeds-autostart |
If the autostop deadline passes the next autostart deadline, increase the autostop deadline to be
next_autostart + ttl
instead ofnow + ttl
.This applies both on workspace build and periodically via the lifecycle executor system. It cannot happen immediately on activity bump as there's no way to execute cron statements in the database.
Also fixes a bug where activity bump would always use the workspace's configured TTL even if the template forbade it.
Closes #2028