MCPcopy Index your code
hub / github.com/coder/coder / scheduleStart

Method scheduleStart

cli/schedule.go:146–218  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

144}
145
146func (r *RootCmd) scheduleStart() *serpent.Command {
147 cmd := &serpent.Command{
148 Use: "start <workspace-name> { <start-time> [day-of-week] [location] | manual }",
149 Long: scheduleStartDescriptionLong + "\n" + FormatExamples(
150 Example{
151 Description: "Set the workspace to start at 9:30am (in Dublin) from Monday to Friday",
152 Command: "coder schedule start my-workspace 9:30AM Mon-Fri Europe/Dublin",
153 },
154 ),
155 Short: "Edit workspace start schedule",
156 Middleware: serpent.Chain(
157 serpent.RequireRangeArgs(2, 4),
158 ),
159 Handler: func(inv *serpent.Invocation) error {
160 client, err := r.InitClient(inv)
161 if err != nil {
162 return err
163 }
164 workspace, err := client.ResolveWorkspace(inv.Context(), inv.Args[0])
165 if err != nil {
166 return err
167 }
168
169 // Autostart configuration is not supported for prebuilt workspaces.
170 // Prebuild lifecycle is managed by the reconciliation loop, with scheduling behavior
171 // defined per preset at the template level, not per workspace.
172 if workspace.IsPrebuild {
173 return xerrors.Errorf("autostart configuration is not supported for prebuilt workspaces")
174 }
175
176 var schedStr *string
177 if inv.Args[1] != "manual" {
178 sched, err := parseCLISchedule(inv.Args[1:]...)
179 if err != nil {
180 return err
181 }
182
183 schedStr = ptr.Ref(sched.String())
184
185 // Check if the template has autostart requirements that may conflict
186 // with the user's schedule.
187 template, err := client.Template(inv.Context(), workspace.TemplateID)
188 if err != nil {
189 return xerrors.Errorf("get template: %w", err)
190 }
191
192 if len(template.AutostartRequirement.DaysOfWeek) > 0 {
193 _, _ = fmt.Fprintf(
194 inv.Stderr,
195 "Warning: your workspace template restricts autostart to the following days: %s.\n"+
196 "Your workspace may only autostart on these days.\n",
197 strings.Join(template.AutostartRequirement.DaysOfWeek, ", "),
198 )
199 }
200 }
201
202 err = client.UpdateWorkspaceAutostart(inv.Context(), workspace.ID, codersdk.UpdateWorkspaceAutostartRequest{
203 Schedule: schedStr,

Callers 1

schedulesMethod · 0.95

Calls 11

InitClientMethod · 0.95
RefFunction · 0.92
FormatExamplesFunction · 0.85
parseCLIScheduleFunction · 0.85
displayScheduleFunction · 0.85
ResolveWorkspaceMethod · 0.80
TemplateMethod · 0.80
ContextMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected