()
| 218 | } |
| 219 | |
| 220 | func (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 | |
| 273 | func (r *RootCmd) scheduleExtend() *serpent.Command { |
| 274 | extendCmd := &serpent.Command{ |
no test coverage detected