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

Method scheduleStop

cli/schedule.go:220–271  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

218}
219
220func (r *RootCmd) scheduleStop() *serpent.Command {
221 return &serpent.Command{
222 Use: "stop <workspace-name> { <duration> | manual }",
223 Long: scheduleStopDescriptionLong + "\n" + FormatExamples(
224 Example{
225 Command: "coder schedule stop my-workspace 2h30m",
226 },
227 ),
228 Short: "Edit workspace stop schedule",
229 Middleware: serpent.Chain(
230 serpent.RequireNArgs(2),
231 ),
232 Handler: func(inv *serpent.Invocation) error {
233 client, err := r.InitClient(inv)
234 if err != nil {
235 return err
236 }
237 workspace, err := client.ResolveWorkspace(inv.Context(), inv.Args[0])
238 if err != nil {
239 return err
240 }
241
242 // Autostop configuration is not supported for prebuilt workspaces.
243 // Prebuild lifecycle is managed by the reconciliation loop, with scheduling behavior
244 // defined per preset at the template level, not per workspace.
245 if workspace.IsPrebuild {
246 return xerrors.Errorf("autostop configuration is not supported for prebuilt workspaces")
247 }
248
249 var durMillis *int64
250 if inv.Args[1] != "manual" {
251 dur, err := parseDuration(inv.Args[1])
252 if err != nil {
253 return err
254 }
255 durMillis = ptr.Ref(dur.Milliseconds())
256 }
257
258 if err := client.UpdateWorkspaceTTL(inv.Context(), workspace.ID, codersdk.UpdateWorkspaceTTLRequest{
259 TTLMillis: durMillis,
260 }); err != nil {
261 return err
262 }
263
264 updated, err := client.ResolveWorkspace(inv.Context(), inv.Args[0])
265 if err != nil {
266 return err
267 }
268 return displaySchedule(updated, inv.Stdout)
269 },
270 }
271}
272
273func (r *RootCmd) scheduleExtend() *serpent.Command {
274 extendCmd := &serpent.Command{

Callers 1

schedulesMethod · 0.95

Calls 9

InitClientMethod · 0.95
RefFunction · 0.92
FormatExamplesFunction · 0.85
parseDurationFunction · 0.85
displayScheduleFunction · 0.85
ResolveWorkspaceMethod · 0.80
ContextMethod · 0.65
UpdateWorkspaceTTLMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected