- Notifications
You must be signed in to change notification settings - Fork1k
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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
Makefile Outdated
-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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
header:= table.Row{"workspace","template","status","last built","outdated","autostart","ttl"} | ||
header:= table.Row{"workspace","template","status","last built","outdated","starts at","stops after"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Clearer language
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()) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
// 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) | ||
} |
There was a problem hiding this comment.
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.
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)) |
There was a problem hiding this comment.
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
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 | ||
} |
There was a problem hiding this comment.
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. | ||
` | ||
) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
all great help 👍
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
* 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. | ||
` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Lovely changes!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
loc,err:=tz.TimezoneIANA() | ||
iferr!=nil { | ||
loc=time.UTC// best effort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yeah, we tried... ❤️
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
This commit makes the following changes:
Sample output: