Skip to content

fix: cli: prettify schedule when printing output #1440

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 5 commits into from
May 16, 2022

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented May 13, 2022

Ref: #1431 (comment)

This PR does the following:

  • Adds methods to schedule.Schedule to show the raw cron string and timezone
  • Uses these methods to clean up output of auto(start|stop) show or ls
  • (From PR comment) Defaults CRON_TZ=UTC if not provided

@johnstcn johnstcn requested a review from a team May 13, 2022 20:53
@johnstcn johnstcn self-assigned this May 13, 2022
@codecov
Copy link

codecov bot commented May 13, 2022

Codecov Report

Merging #1440 (037b348) into main (50ad2f8) will increase coverage by 0.01%.
The diff coverage is 86.04%.

@@            Coverage Diff             @@
##             main    #1440      +/-   ##
==========================================
+ Coverage   67.10%   67.12%   +0.01%     
==========================================
  Files         291      291              
  Lines       19527    19557      +30     
  Branches      258      258              
==========================================
+ Hits        13104    13127      +23     
- Misses       5073     5081       +8     
+ Partials     1350     1349       -1     
Flag Coverage Δ
unittest-go-macos-latest 54.36% <86.04%> (+0.06%) ⬆️
unittest-go-postgres- 65.61% <86.04%> (+0.10%) ⬆️
unittest-go-ubuntu-latest 56.63% <86.04%> (+0.08%) ⬆️
unittest-go-windows-2022 52.74% <86.04%> (+0.08%) ⬆️
unittest-js 74.73% <ø> (ø)
Impacted Files Coverage Δ
cli/list.go 45.61% <25.00%> (-0.82%) ⬇️
cli/autostart.go 68.54% <100.00%> (+2.16%) ⬆️
cli/autostop.go 68.54% <100.00%> (+2.16%) ⬆️
coderd/autobuild/schedule/schedule.go 93.33% <100.00%> (+2.42%) ⬆️
cli/cliui/provisionerjob.go 76.42% <0.00%> (-2.15%) ⬇️
provisionerd/provisionerd.go 76.43% <0.00%> (-1.08%) ⬇️
peer/conn.go 81.08% <0.00%> (-0.74%) ⬇️
agent/agent.go 65.90% <0.00%> (-0.62%) ⬇️
coderd/provisionerdaemons.go 64.32% <0.00%> (+1.00%) ⬆️
... and 2 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 50ad2f8...037b348. Read the comment docs.

@@ -49,9 +49,18 @@ func Weekly(spec string) (*Schedule, error) {
return nil, xerrors.Errorf("expected *cron.SpecSchedule but got %T", specSched)
}

tz := "UTC"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a bit brittle. The CLI will always pass a schedule string that starts with CRON_TZ=, but if someone sets a schedule through the API, it could be any valid string that the parser will accept. And if the schedule doesn't include a timezone, it will be interpreted using the server's timezone, which could be different from UTC.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Defaulting CRON_TZ=UTC is probably the simplest way here.

Comment on lines 54 to 57
if strings.HasPrefix(raw, "CRON_TZ=") {
tz = strings.TrimPrefix(strings.Fields(raw)[0], "CRON_TZ=")
cron = strings.Join(strings.Fields(raw)[1:], " ")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It really bothers me that we have to do this using direct string manipulation instead of just looking at the parsed schedule, but it doesn't seem like this cron library provides a better way 😞

Copy link
Member Author

Choose a reason for hiding this comment

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

:'(

@misskniss misskniss added this to the V2 Beta milestone May 15, 2022
@johnstcn johnstcn requested review from dwahler and greyscaled May 16, 2022 10:45
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.

Seems reasonable to me!

@johnstcn johnstcn merged commit b704903 into main May 16, 2022
@johnstcn johnstcn deleted the cj/gh-1431/cli-sched-output branch May 16, 2022 16:02
kylecarbs pushed a commit that referenced this pull request Jun 10, 2022
* Adds methods to schedule.Schedule to show the raw cron string and timezone
* Uses these methods to clean up output of auto(start|stop) show or ls
* Defaults CRON_TZ=UTC if not provided
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.

4 participants