Revert "Make coder bump idempotent (#2225)"

This reverts commit 0df75f9176.

I merged on accident.
This commit is contained in:
ammario
2022-06-10 03:31:13 +00:00
parent 0df75f9176
commit 6ea86c831b
2 changed files with 104 additions and 23 deletions

View File

@ -12,55 +12,55 @@ import (
)
const (
bumpDescriptionLong = `To extend the autostop deadline for a workspace.`
bumpDescriptionLong = `To extend the autostop deadline for a workspace.
If no unit is specified in the duration, we assume minutes.`
defaultBumpDuration = 90 * time.Minute
)
func bump() *cobra.Command {
bumpCmd := &cobra.Command{
Args: cobra.RangeArgs(1, 2),
Annotations: workspaceCommand,
Use: "bump <workspace-name> <duration>",
Use: "bump <workspace-name> [duration]",
Short: "Extend the autostop deadline for a workspace.",
Long: bumpDescriptionLong,
Example: "coder bump my-workspace 90m",
RunE: func(cmd *cobra.Command, args []string) error {
bumpDuration, err := tryParseDuration(args[1])
if err != nil {
return err
bumpDuration := defaultBumpDuration
if len(args) > 1 {
d, err := tryParseDuration(args[1])
if err != nil {
return err
}
bumpDuration = d
}
if bumpDuration < time.Minute {
return xerrors.New("minimum bump duration is 1 minute")
}
client, err := createClient(cmd)
if err != nil {
return xerrors.Errorf("create client: %w", err)
}
workspace, err := namedWorkspace(cmd, client, args[0])
if err != nil {
return xerrors.Errorf("get workspace: %w", err)
}
newDeadline := time.Now().Add(bumpDuration)
if newDeadline.Before(workspace.LatestBuild.Deadline) {
_, _ = fmt.Fprintf(
cmd.OutOrStdout(),
"The proposed deadline is %s before the current deadline.\n",
workspace.LatestBuild.Deadline.Sub(newDeadline).Round(time.Minute),
)
if workspace.LatestBuild.Deadline.IsZero() {
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "no deadline set\n")
return nil
}
newDeadline := workspace.LatestBuild.Deadline.Add(bumpDuration)
if err := client.PutExtendWorkspace(cmd.Context(), workspace.ID, codersdk.PutExtendWorkspaceRequest{
Deadline: newDeadline,
}); err != nil {
return err
}
_, _ = fmt.Fprintf(
cmd.OutOrStdout(),
"Workspace %q will now stop at %s\n", workspace.Name,
newDeadline.Format(time.RFC822),
)
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Workspace %q will now stop at %s\n", workspace.Name, newDeadline.Format(time.RFC3339))
return nil
},