(ctx context.Context, workspaceID string)
| 245 | } |
| 246 | |
| 247 | func (h *BaseHandlers) stoppedWorkspaceSessionIDs(ctx context.Context, workspaceID string) ([]string, error) { |
| 248 | if h.Sessions == nil { |
| 249 | return nil, errors.New("api: session manager is required") |
| 250 | } |
| 251 | |
| 252 | infos, err := h.Sessions.ListAll(ctx) |
| 253 | if err != nil { |
| 254 | return nil, fmt.Errorf("api: list sessions before deleting workspace %q: %w", workspaceID, err) |
| 255 | } |
| 256 | |
| 257 | active := make([]string, 0) |
| 258 | stopped := make([]string, 0) |
| 259 | for _, info := range infos { |
| 260 | if info == nil || strings.TrimSpace(info.WorkspaceID) != workspaceID { |
| 261 | continue |
| 262 | } |
| 263 | sessionID := strings.TrimSpace(info.ID) |
| 264 | if sessionID == "" { |
| 265 | continue |
| 266 | } |
| 267 | if info.State == session.StateActive { |
| 268 | active = append(active, sessionID) |
| 269 | continue |
| 270 | } |
| 271 | stopped = append(stopped, sessionID) |
| 272 | } |
| 273 | if len(active) > 0 { |
| 274 | sort.Strings(active) |
| 275 | return nil, fmt.Errorf( |
| 276 | "api: delete workspace %q: %w: %s", |
| 277 | workspaceID, |
| 278 | workspacepkg.ErrWorkspaceHasActiveSessions, |
| 279 | strings.Join(active, ", "), |
| 280 | ) |
| 281 | } |
| 282 | |
| 283 | sort.Strings(stopped) |
| 284 | return stopped, nil |
| 285 | } |
| 286 | |
| 287 | func (h *BaseHandlers) deleteStoppedWorkspaceSessions( |
| 288 | ctx context.Context, |
no test coverage detected