Skip to content
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

autostart/autostop: move to traditional 5-valued cron string for compatibility #1049

Merged
merged 6 commits into from
Apr 18, 2022

Conversation

johnstcn
Copy link
Member

This PR modfies the original 3-valued cron strings used in package schedule to be traditional 5-valued cron strings.

  • schedule.Weekly will validate that the month and dom fields are equal to *
  • cli autostart/autostop will attempt to detect local timezone using TZ env var, defaulting to UTC
  • cli autostart/autostop no longer accepts a raw schedule -- instead use the --minute, --hour, --dow, and --tz arguments. Default schedules are provided that should suffice for most users.

Fixes #993

@johnstcn johnstcn self-assigned this Apr 16, 2022
@johnstcn johnstcn requested a review from a team as a code owner April 16, 2022 17:48
@codecov
Copy link

codecov bot commented Apr 16, 2022

Codecov Report

Merging #1049 (be426af) into main (cf8a20d) will increase coverage by 0.13%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1049      +/-   ##
==========================================
+ Coverage   67.31%   67.45%   +0.13%     
==========================================
  Files         259      259              
  Lines       15061    15100      +39     
  Branches      152      152              
==========================================
+ Hits        10139    10185      +46     
+ Misses       3899     3896       -3     
+ Partials     1023     1019       -4     
Flag Coverage Δ
unittest-go-macos-latest 53.76% <100.00%> (+0.13%) ⬆️
unittest-go-postgres- 66.69% <100.00%> (+0.07%) ⬆️
unittest-go-ubuntu-latest 56.26% <100.00%> (+0.15%) ⬆️
unittest-go-windows-2022 53.16% <100.00%> (+0.14%) ⬆️
unittest-js 67.96% <100.00%> (-0.14%) ⬇️
Impacted Files Coverage Δ
site/src/test_helpers/entities.ts 100.00% <ø> (ø)
site/src/util/schedule.ts 100.00% <ø> (ø)
cli/workspaceautostart.go 80.76% <100.00%> (-0.19%) ⬇️
cli/workspaceautostop.go 80.76% <100.00%> (-0.19%) ⬇️
coderd/autostart/schedule/schedule.go 90.90% <100.00%> (+7.57%) ⬆️
...ite/src/components/Workspace/WorkspaceSchedule.tsx 75.00% <100.00%> (ø)
provisionersdk/serve.go 35.13% <0.00%> (-8.11%) ⬇️
codersdk/provisionerdaemons.go 59.70% <0.00%> (-5.98%) ⬇️
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf8a20d...be426af. Read the comment docs.

@johnstcn johnstcn requested a review from kylecarbs April 16, 2022 17:51
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nits. LGTM

cli/workspaceautostart.go Outdated Show resolved Hide resolved
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
if err != nil {
return err
}

workspace, err := client.WorkspaceByName(cmd.Context(), codersdk.Me, args[0])
spec := fmt.Sprintf("CRON_TZ=%s %s %s * * %s", autostartTimezone, autostartMinute, autostartHour, autostartDayOfWeek)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: nice!

cli/workspaceautostart.go Outdated Show resolved Hide resolved
Comment on lines +77 to +80
tzEnv := os.Getenv("TZ")
if tzEnv == "" {
tzEnv = "UTC"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: nice 😎

cli/workspaceautostop.go Outdated Show resolved Hide resolved
cli/workspaceautostart.go Outdated Show resolved Hide resolved

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmd.Flags().StringVar(&autostopDayOfWeek, "dow", "1-5", "autostop hour")
cmd.Flags().StringVar(&autostopDayOfWeek, "dow", "1-5", "autostop day(s) of week")

at: time.Time{},
expectedNext: time.Time{},
expectedError: "validate weekly schedule: expected month and dom to be *",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Great tests

@greyscaled
Copy link
Contributor

greyscaled commented Apr 18, 2022

@johnstcn we're seeing a parse failure in our Storybook. I think we need to update these here to have * for month and day of month:

export const MockWorkspaceAutostartDisabled: WorkspaceAutostartRequest = {
schedule: "",
}
export const MockWorkspaceAutostartEnabled: WorkspaceAutostartRequest = {
// Runs at 9:30am Monday through Friday using Canada/Eastern
// (America/Toronto) time
schedule: "CRON_TZ=Canada/Eastern 30 9 1-5",
}
export const MockWorkspaceAutostopDisabled: WorkspaceAutostartRequest = {
schedule: "",
}
export const MockWorkspaceAutostopEnabled: WorkspaceAutostartRequest = {
// Runs at 9:30pm Monday through Friday using America/Toronto
schedule: "CRON_TZ=America/Toronto 30 21 1-5",
}

@johnstcn
Copy link
Member Author

@johnstcn we're seeing a parse failure in our Storybook. I think we need to update these here to have * for month and day of month:

export const MockWorkspaceAutostartDisabled: WorkspaceAutostartRequest = {
schedule: "",
}
export const MockWorkspaceAutostartEnabled: WorkspaceAutostartRequest = {
// Runs at 9:30am Monday through Friday using Canada/Eastern
// (America/Toronto) time
schedule: "CRON_TZ=Canada/Eastern 30 9 1-5",
}
export const MockWorkspaceAutostopDisabled: WorkspaceAutostartRequest = {
schedule: "",
}
export const MockWorkspaceAutostopEnabled: WorkspaceAutostartRequest = {
// Runs at 9:30pm Monday through Friday using America/Toronto
schedule: "CRON_TZ=America/Toronto 30 21 1-5",
}

ack

@johnstcn johnstcn merged commit af67280 into main Apr 18, 2022
@johnstcn johnstcn deleted the cj/schedule-compat branch April 18, 2022 16:04
@misskniss misskniss added this to the V2 Beta milestone May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

autostart: make schedule cron string a full 5-valued for compatibility
4 participants