Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: cli: consolidate schedule-related commands#2402

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

Merged
johnstcn merged 12 commits intomainfromcj/2258/cli-schedule-command
Jun 16, 2022

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedJun 16, 2022
edited
Loading

This commit makes the following changes:

  • cil: rename autostart -> schedule start
  • cli: rename ttl -> schedule stop
  • cli: rename bump -> schedule override
  • cli: add schedule show command
  • cli: move some cli-related stuff to util.go
  • cli: modify list command output slightly to show time remaining

Sample output:

$ coderv2 listWORKSPACE                       TEMPLATE      STATUS   LAST BUILT  OUTDATED  STARTS AT                         STOPS AFTER  johnstcn/cian                   coder         Running   6h23m       false     9:00AM Mon-Fri (Europe/Dublin)    12h (in 5h3m)    johnstcn/cian-test              coder         Stopped   1h33m       false     -                                 -                johnstcn/cian-test-linux        gcp-linux     Failed    17h17m      false     -                                 12h     $ coderv2 schedule show cianStarts at    9:00AM Mon-Fri (Europe/Dublin)        Starts next  9:00AM IST on Jun 17, 2022            Stops at     12h after start                       Stops next   7:27PM UTC on Jun 16, 2022 (in 5h3m)  $ coderv2 schedule stop cian-test manualStarts at    manual  Starts next  -       Stops at     manual  Stops next   -       $ coderv2 schedule override-stop cian 4hStarts at    9:00AM Mon-Fri (Europe/Dublin)         Starts next  9:00AM IST on Jun 17, 2022             Stops at     12h after start                        Stops next   6:24PM UTC on Jun 16, 2022 (in 3h59m)

This commit makes the following changes:- renames autostart -> schedule starat- renames ttl -> schedule stop- renames bump -> schedule override- adds schedule show command- moves some cli-related stuff to util.go
@johnstcnjohnstcn self-assigned thisJun 16, 2022
@johnstcnjohnstcn marked this pull request as ready for reviewJune 16, 2022 14:36
@johnstcnjohnstcn requested a review froma teamJune 16, 2022 14:36
Makefile Outdated
Comment on lines 118 to 120
-covermode=atomic -coverprofile="gotests.coverage" -timeout=5m\
-covermode=atomic -coverprofile="gotests.coverage" -timeout=10m\
-coverpkg=./...,github.com/coder/coder/codersdk\
-count=1 -parallel=1 -race -failfast
-count=1 -parallel=2 -race -failfast
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

👀 bumping these here because we are absolutely hitting the five-minute mark

mafredri reacted with heart emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Spike's PR (#2413) actually addresses this better so I'm going to revert these changes.


const (
timeFormat="3:04:05 PM MST"
timeFormat="3:04PM MST"
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I don't think seconds are useful to users here.

ammario reacted with thumbs up emojimafredri reacted with heart emoji
Comment on lines -53 to +52
header:= table.Row{"workspace","template","status","last built","outdated","autostart","ttl"}
header:= table.Row{"workspace","template","status","last built","outdated","starts at","stops after"}
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Clearer language

ammario and Emyrk reacted with thumbs up emoji
if!ptr.NilOrEmpty(workspace.AutostartSchedule) {
ifsched,err:=schedule.Weekly(*workspace.AutostartSchedule);err==nil {
autostartDisplay=sched.Cron()
autostartDisplay=fmt.Sprintf("%s %s (%s)",sched.Time(),sched.DaysOfWeek(),sched.Location())
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Consistent schedule format

@@ -0,0 +1,207 @@
package cli
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

There were some helper methods about the place that I decided to pull into here.

Comment on lines +142 to +153
// Time returns a humanized form of the minute and hour fields.
func (sSchedule)Time()string {
minute:=strings.Fields(s.cronStr)[0]
hour:=strings.Fields(s.cronStr)[1]
maybeTime:=fmt.Sprintf("%s:%s",hour,minute)
t,err:=time.ParseInLocation("3:4",maybeTime,s.sched.Location)
iferr!=nil {
// return the original cronspec for minute and hour, who knows what's in there!
returnfmt.Sprintf("cron(%s %s)",minute,hour)
}
returnt.Format(time.Kitchen)
}
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This is a best-effort of showing the scheduled time of a schedule. If we can't display it as a simple time, we just return the cron for it.

Comment on lines -101 to +103
ifhas,ext:=hasExtension(workspace);has {
autostopDisplay+=fmt.Sprintf(" (+%s)",durationDisplay(ext.Round(time.Minute)))
if!workspace.LatestBuild.Deadline.IsZero()&&workspace.LatestBuild.Deadline.After(now)&&status=="Running" {
remaining:=time.Until(workspace.LatestBuild.Deadline)
autostopDisplay=fmt.Sprintf("%s (%s)",autostopDisplay,relative(remaining))
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Felt it's more useful to show the time remaining here

Comment on lines 26 to 60
funcdurationDisplay(d time.Duration)string {
duration:=d
sign:=""
ifduration==0 {
return"0s"
}
ifduration<0 {
duration*=-1
}
// duration > 0 now
ifduration<time.Minute {
returnsign+"<1m"
}
ifduration>24*time.Hour {
duration=duration.Truncate(time.Hour)
}
ifduration>time.Minute {
duration=duration.Truncate(time.Minute)
}
days:=0
forduration.Hours()>=24 {
days++
duration-=24*time.Hour
}
durationDisplay:=duration.String()
ifdays>0 {
durationDisplay=fmt.Sprintf("%dd%s",days,durationDisplay)
}
for_,suffix:=range []string{"m0s","h0m","d0s"} {
ifstrings.HasSuffix(durationDisplay,suffix) {
durationDisplay=durationDisplay[:len(durationDisplay)-2]
}
}
returnsign+durationDisplay
}
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

review: smaller durations are always <1m now, it can also handle negative durations

* The new stop time must be at least 30 minutes in the future.
* The workspace template may restrict the maximum workspace runtime.
`
)
Copy link
Member

Choose a reason for hiding this comment

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

👍 Solid descriptions

Use:"stop <workspace_name> { <duration> | manual }",
Example:`stop my-workspace 2h30m`,
Short:"Edit workspace stop schedule",
Long:scheduleStopDescriptionLong,
Copy link
Member

Choose a reason for hiding this comment

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

all great help 👍

* The new stop time is calculated from *now*.
* The new stop time must be at least 30 minutes in the future.
* The workspace template may restrict the maximum workspace runtime.
`
Copy link
Member

Choose a reason for hiding this comment

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

All these newlines at the beginning of the help should be removed.
image

Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

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

Lovely changes!


loc,err:=tz.TimezoneIANA()
iferr!=nil {
loc=time.UTC// best effort
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we tried... ❤️

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mafredrimafredrimafredri approved these changes

@ammarioammarioammario approved these changes

Assignees

@johnstcnjohnstcn

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@johnstcn@mafredri@ammario

[8]ページ先頭

©2009-2025 Movatter.jp