-
Notifications
You must be signed in to change notification settings - Fork 894
fix: allow setting workspace deadline as early as now plus 30 minutes #2328
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,22 +5,24 @@ import ( | |
"strings" | ||
"time" | ||
|
||
"github.com/coder/coder/coderd/util/tz" | ||
|
||
"github.com/spf13/cobra" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/coder/coder/codersdk" | ||
) | ||
|
||
const ( | ||
bumpDescriptionLong = `To extend the autostop deadline for a workspace.` | ||
bumpDescriptionLong = `Make your workspace stop at a certain point in the future.` | ||
) | ||
|
||
func bump() *cobra.Command { | ||
bumpCmd := &cobra.Command{ | ||
Args: cobra.RangeArgs(1, 2), | ||
Annotations: workspaceCommand, | ||
Use: "bump <workspace-name> <duration>", | ||
Short: "Extend the autostop deadline for a workspace.", | ||
Use: "bump <workspace-name> <duration from now>", | ||
Short: "Make your workspace stop at a certain point in the future.", | ||
Long: bumpDescriptionLong, | ||
Example: "coder bump my-workspace 90m", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
|
@@ -39,17 +41,20 @@ func bump() *cobra.Command { | |
return xerrors.Errorf("get workspace: %w", err) | ||
} | ||
|
||
newDeadline := time.Now().Add(bumpDuration) | ||
loc, err := tz.TimezoneIANA() | ||
if err != nil { | ||
loc = time.UTC // best guess | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if newDeadline.Before(workspace.LatestBuild.Deadline) { | ||
if bumpDuration < 29*time.Minute { | ||
_, _ = fmt.Fprintf( | ||
cmd.OutOrStdout(), | ||
"The proposed deadline is %s before the current deadline.\n", | ||
workspace.LatestBuild.Deadline.Sub(newDeadline).Round(time.Minute), | ||
"Please specify a duration of at least 30 minutes.\n", | ||
) | ||
return nil | ||
} | ||
|
||
newDeadline := time.Now().In(loc).Add(bumpDuration) | ||
if err := client.PutExtendWorkspace(cmd.Context(), workspace.ID, codersdk.PutExtendWorkspaceRequest{ | ||
Deadline: newDeadline, | ||
}); err != nil { | ||
|
@@ -62,7 +67,6 @@ func bump() *cobra.Command { | |
newDeadline.Format(timeFormat), | ||
newDeadline.Format(dateFormat), | ||
) | ||
|
||
return nil | ||
}, | ||
} | ||
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. Also: this won't be called |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -883,18 +883,9 @@ func validWorkspaceDeadline(old, new time.Time) error { | |
return xerrors.New("nothing to do: no existing deadline set") | ||
} | ||
|
||
now := time.Now() | ||
if new.Before(now) { | ||
return xerrors.New("new deadline must be in the future") | ||
} | ||
|
||
delta := new.Sub(old) | ||
if delta < time.Minute { | ||
return xerrors.New("minimum extension is one minute") | ||
} | ||
|
||
if delta > 24*time.Hour { | ||
return xerrors.New("maximum extension is 24 hours") | ||
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: Dropping these validations for the moment till we have more information from #2318 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. Actually, there's one very important validation involving templates that I may have overlooked! Adding this in now. |
||
soon := time.Now().Add(29 * time.Minute) | ||
if new.Before(soon) { | ||
return xerrors.New("new deadline must be at least 30 minutes in the future") | ||
} | ||
|
||
return nil | ||
|
Uh oh!
There was an error while loading. Please reload this page.