-
Notifications
You must be signed in to change notification settings - Fork 943
refactor: workspace autostop_schedule -> ttl #1578
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3980007
refactor: workspace: autostop_schedule -> ttl
johnstcn 3ea3e90
fix: truncate ttl to time.Minute
johnstcn ea49127
noop: rename migration
johnstcn a06218f
cli: rename ttl enable/disable -> ttl set/unset
johnstcn 58d72c3
address PR comments
johnstcn 6f67b79
make gen
johnstcn f65e3de
fixup! make gen
johnstcn 77b8ad3
cli: ttl: xerrors.Errorf everywhere
johnstcn 80d7b1c
frontend
greyscaled 32c92f6
codersdk change
johnstcn b3168c1
fixup! frontend
johnstcn d00fefb
Update site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx
greyscaled d8ccd6c
unnecessary else
greyscaled 22f0222
fixup api param
greyscaled 50a5823
fix FE paths for ttl
greyscaled File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
refactor: workspace: autostop_schedule -> ttl
- Loading branch information
commit 3980007b48d2067cd01ba52652f63c93905689b4
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/coder/coder/codersdk" | ||
) | ||
|
||
const ttlDescriptionLong = `To have your workspace stop automatically after a configurable interval has passed.` | ||
|
||
func ttl() *cobra.Command { | ||
ttlCmd := &cobra.Command{ | ||
Annotations: workspaceCommand, | ||
Use: "ttl enable <workspace>", | ||
Short: "schedule a workspace to automatically stop after a configurable interval", | ||
Long: ttlDescriptionLong, | ||
Example: "coder ttl enable my-workspace 8h30m", | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
ttlCmd.AddCommand(ttlShow()) | ||
greyscaled marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ttlCmd.AddCommand(ttlEnable()) | ||
ttlCmd.AddCommand(ttlDisable()) | ||
|
||
return ttlCmd | ||
} | ||
|
||
func ttlShow() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "show <workspace_name>", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
client, err := createClient(cmd) | ||
if err != nil { | ||
return err | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
organization, err := currentOrganization(cmd, client) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if workspace.TTL == nil { | ||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "not enabled\n") | ||
return nil | ||
} | ||
|
||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%s\n", workspace.TTL) | ||
|
||
return nil | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func ttlEnable() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "enable <workspace_name> <ttl>", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
client, err := createClient(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
organization, err := currentOrganization(cmd, client) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ttl, err := time.ParseDuration(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = client.UpdateWorkspaceTTL(cmd.Context(), workspace.ID, codersdk.UpdateWorkspaceTTLRequest{ | ||
TTL: &ttl, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func ttlDisable() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "disable <workspace_name>", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
client, err := createClient(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
organization, err := currentOrganization(cmd, client) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = client.UpdateWorkspaceTTL(cmd.Context(), workspace.ID, codersdk.UpdateWorkspaceTTLRequest{ | ||
TTL: nil, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nThe %s workspace will no longer automatically stop.\n\n", workspace.Name) | ||
|
||
return nil | ||
}, | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.