- Notifications
You must be signed in to change notification settings - Fork928
autostart/autostop: move to traditional 5-valued cron string for compatibility#1049
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 from5 commits
967ead8
a827d5c
f65dbba
077284f
f2904f6
be426af
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 |
---|---|---|
@@ -2,6 +2,7 @@ package cli | ||
import ( | ||
"fmt" | ||
"os" | ||
"time" | ||
"github.com/spf13/cobra" | ||
@@ -11,20 +12,16 @@ import ( | ||
) | ||
const autostartDescriptionLong = `To have your workspace build automatically at a regular time you can enable autostart. | ||
When enabling autostart, provide the minute, hour, and day(s) of week. | ||
The default schedule is at 0900 in your local timezone (TZ env, UTC by default). | ||
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
` | ||
func workspaceAutostart() *cobra.Command { | ||
autostartCmd := &cobra.Command{ | ||
Use: "autostart enable <workspace>", | ||
Short: "schedule a workspace to automatically start at a regular time", | ||
Long: autostartDescriptionLong, | ||
Example: "coder workspaces autostart enable my-workspace--minute30--hour 9 --dow1-5 --tz Europe/Dublin", | ||
Hidden: true, // TODO(cian): un-hide when autostart scheduling implemented | ||
} | ||
@@ -35,22 +32,28 @@ func workspaceAutostart() *cobra.Command { | ||
} | ||
func workspaceAutostartEnable() *cobra.Command { | ||
// yes some of these are technically numbers but the cron library will do that work | ||
var autostartMinute string | ||
var autostartHour string | ||
var autostartDayOfWeek string | ||
var autostartTimezone string | ||
cmd := &cobra.Command{ | ||
Use: "enable <workspace_name> <schedule>", | ||
ValidArgsFunction: validArgsWorkspaceName, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
client, err := createClient(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
spec := fmt.Sprintf("CRON_TZ=%s %s %s * * %s", autostartTimezone, autostartMinute, autostartHour, autostartDayOfWeek) | ||
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. praise: nice! | ||
validSchedule, err := schedule.Weekly(spec) | ||
if err != nil { | ||
return err | ||
} | ||
workspace, err :=client.WorkspaceByName(cmd.Context(), codersdk.Me,args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
@@ -67,6 +70,16 @@ func workspaceAutostartEnable() *cobra.Command { | ||
return nil | ||
}, | ||
} | ||
cmd.Flags().StringVar(&autostartMinute, "minute", "0", "autostart minute") | ||
cmd.Flags().StringVar(&autostartHour, "hour", "9", "autostart hour") | ||
cmd.Flags().StringVar(&autostartDayOfWeek, "dow", "1-5", "autostart hour") | ||
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page.
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
tzEnv := os.Getenv("TZ") | ||
if tzEnv == "" { | ||
tzEnv = "UTC" | ||
} | ||
Comment on lines +77 to +80 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. praise: nice 😎 | ||
cmd.Flags().StringVar(&autostartTimezone, "tz", tzEnv, "autostart timezone") | ||
return cmd | ||
} | ||
func workspaceAutostartDisable() *cobra.Command { | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -2,6 +2,7 @@ package cli | ||||||
import ( | ||||||
"fmt" | ||||||
"os" | ||||||
"time" | ||||||
"github.com/spf13/cobra" | ||||||
@@ -11,20 +12,16 @@ import ( | ||||||
) | ||||||
const autostopDescriptionLong = `To have your workspace stop automatically at a regular time you can enable autostop. | ||||||
When enabling autostop, provide the minute, hour, and day(s) of week. | ||||||
The default autostop schedule is at 1800 in your local timezone (TZ env, UTC by default). | ||||||
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||||
` | ||||||
func workspaceAutostop() *cobra.Command { | ||||||
autostopCmd := &cobra.Command{ | ||||||
Use: "autostop enable <workspace>", | ||||||
Short: "schedule a workspace to automaticallystop at a regular time", | ||||||
Long: autostopDescriptionLong, | ||||||
Example: "coder workspaces autostop enable my-workspace-minute 0 -hour 18 -dow1-5 -tz Europe/Dublin", | ||||||
Hidden: true, // TODO(cian): un-hide when autostop scheduling implemented | ||||||
} | ||||||
@@ -35,22 +32,28 @@ func workspaceAutostop() *cobra.Command { | ||||||
} | ||||||
func workspaceAutostopEnable() *cobra.Command { | ||||||
// yes some of these are technically numbers but the cron library will do that work | ||||||
var autostopMinute string | ||||||
var autostopHour string | ||||||
var autostopDayOfWeek string | ||||||
var autostopTimezone string | ||||||
cmd := &cobra.Command{ | ||||||
Use: "enable <workspace_name> <schedule>", | ||||||
ValidArgsFunction: validArgsWorkspaceName, | ||||||
Args: cobra.ExactArgs(1), | ||||||
RunE: func(cmd *cobra.Command, args []string) error { | ||||||
client, err := createClient(cmd) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
spec := fmt.Sprintf("CRON_TZ=%s %s %s * * %s", autostopTimezone, autostopMinute, autostopHour, autostopDayOfWeek) | ||||||
validSchedule, err := schedule.Weekly(spec) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
workspace, err :=client.WorkspaceByName(cmd.Context(), codersdk.Me,args[0]) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
@@ -67,6 +70,16 @@ func workspaceAutostopEnable() *cobra.Command { | ||||||
return nil | ||||||
}, | ||||||
} | ||||||
cmd.Flags().StringVar(&autostopMinute, "minute", "0", "autostop minute") | ||||||
cmd.Flags().StringVar(&autostopHour, "hour", "18", "autostop hour") | ||||||
cmd.Flags().StringVar(&autostopDayOfWeek, "dow", "1-5", "autostop hour") | ||||||
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. Suggested change
| ||||||
tzEnv := os.Getenv("TZ") | ||||||
if tzEnv == "" { | ||||||
tzEnv = "UTC" | ||||||
} | ||||||
cmd.Flags().StringVar(&autostopTimezone, "tz", tzEnv, "autostop timezone") | ||||||
return cmd | ||||||
} | ||||||
func workspaceAutostopDisable() *cobra.Command { | ||||||
Uh oh!
There was an error while loading.Please reload this page.