- Notifications
You must be signed in to change notification settings - Fork928
fix: coderd: decouple ttl and deadline#2282
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
a19a0e9
3999661
f5ce8a3
987f785
cd4dce3
91e3171
00ac2a2
3faf3c8
a763d2f
bbd8288
feef823
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package cli | ||
const ( | ||
timeFormat = "3:04:05 PM MST" | ||
dateFormat = "Jan 2, 2006" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -127,14 +127,17 @@ func hasExtension(ws codersdk.Workspace) (bool, time.Duration) { | ||
if ws.LatestBuild.Transition != codersdk.WorkspaceTransitionStart { | ||
return false, 0 | ||
} | ||
if ws.LatestBuild.Job.CompletedAt == nil { | ||
return false, 0 | ||
} | ||
if ws.LatestBuild.Deadline.IsZero() { | ||
return false, 0 | ||
} | ||
if ws.TTLMillis == nil { | ||
return false, 0 | ||
} | ||
ttl := time.Duration(*ws.TTLMillis) * time.Millisecond | ||
delta := ws.LatestBuild.Deadline.Add(-ttl).Sub(*ws.LatestBuild.Job.CompletedAt) | ||
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. review: this was causing us to measure deadline extensions incorrectly, resulting in things like | ||
if delta < time.Minute { | ||
return false, 0 | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package cli | ||
import ( | ||
"fmt" | ||
"time" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/xerrors" | ||
"github.com/coder/coder/coderd/autobuild/schedule" | ||
"github.com/coder/coder/coderd/util/ptr" | ||
"github.com/coder/coder/codersdk" | ||
) | ||
@@ -91,37 +91,32 @@ func ttlset() *cobra.Command { | ||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "warning: ttl rounded down to %s\n", truncated) | ||
} | ||
millis := truncated.Milliseconds() | ||
if err = client.UpdateWorkspaceTTL(cmd.Context(), workspace.ID, codersdk.UpdateWorkspaceTTLRequest{ | ||
TTLMillis: &millis, | ||
}); err != nil { | ||
return xerrors.Errorf("update workspace ttl: %w", err) | ||
} | ||
if ptr.NilOrEmpty(workspace.AutostartSchedule) { | ||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%q will shut down %s after start.\n", workspace.Name, truncated) | ||
return nil | ||
} | ||
sched, err := schedule.Weekly(*workspace.AutostartSchedule) | ||
if err != nil { | ||
return xerrors.Errorf("parse workspace schedule: %w", err) | ||
} | ||
nextShutdown := sched.Next(time.Now()).Add(truncated).In(sched.Location()) | ||
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%q will shut down at %s on %s (%s after start).\n", | ||
workspace.Name, | ||
nextShutdown.Format(timeFormat), | ||
nextShutdown.Format(dateFormat), | ||
truncated, | ||
) | ||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "NOTE: this will only take effect the next time the workspace is started.\n") | ||
return nil | ||
}, | ||
} | ||
@@ -157,18 +152,3 @@ func ttlunset() *cobra.Command { | ||
}, | ||
} | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -85,11 +85,9 @@ func (e *Executor) runOnce(t time.Time) Stats { | ||
// is what we compare against when performing autostop operations, rounded down | ||
// to the minute. | ||
// | ||
// NOTE: If a workspace build is created with a given TTL and then the user either | ||
// changes or unsets the TTL, the deadline for the workspace build will not | ||
// have changed. This behavior is as expected per #2229. | ||
Comment on lines +88 to +90 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. review: this is now the expected behaviour until we're told otherwise! | ||
eligibleWorkspaces, err := db.GetWorkspacesAutostart(e.ctx) | ||
if err != nil { | ||
return xerrors.Errorf("get eligible workspaces for autostart or autostop: %w", err) | ||
Uh oh!
There was an error while loading.Please reload this page.