MCPcopy
hub / github.com/coder/mux / removeOwnedWorkspaceTurnWorkspace

Method removeOwnedWorkspaceTurnWorkspace

src/node/services/taskService.ts:5964–6014  ·  view source on GitHub ↗
(
    ownerWorkspaceId: string,
    target: WorkspaceLifecycleTarget,
    options: WorkspaceLifecycleOptions = {}
  )

Source from the content-addressed store, hash-verified

5962 }
5963
5964 async removeOwnedWorkspaceTurnWorkspace(
5965 ownerWorkspaceId: string,
5966 target: WorkspaceLifecycleTarget,
5967 options: WorkspaceLifecycleOptions = {}
5968 ): Promise<Result<WorkspaceLifecycleResult, string>> {
5969 assert(ownerWorkspaceId.trim().length > 0, "remove lifecycle requires ownerWorkspaceId");
5970 const resolved = await this.resolveOwnedWorkspaceLifecycleTarget(
5971 ownerWorkspaceId,
5972 "remove",
5973 target
5974 );
5975 if ("status" in resolved) return Ok(resolved);
5976
5977 return await this.withWorkspaceLifecycleLock(resolved, async (resolved) => {
5978 if (resolved.metadata == null) {
5979 return Ok({
5980 status: "already_removed",
5981 action: "remove",
5982 ...this.lifecycleTargetFields(resolved),
5983 });
5984 }
5985 if (!isWorkspaceArchived(resolved.metadata.archivedAt, resolved.metadata.unarchivedAt)) {
5986 return Ok({
5987 status: "requires_archive",
5988 action: "remove",
5989 ...this.lifecycleTargetFields(resolved),
5990 });
5991 }
5992
5993 const active = await this.handleActiveWorkspaceLifecycleTurns(
5994 ownerWorkspaceId,
5995 resolved,
5996 options.interruptActive === true
5997 );
5998 if (active != null) return Ok(active);
5999
6000 const result = await this.workspaceService.remove(
6001 resolved.workspaceId,
6002 options.force === true
6003 );
6004 if (!result.success) {
6005 return Ok({
6006 status: "error",
6007 action: "remove",
6008 ...this.lifecycleTargetFields(resolved),
6009 error: result.error,
6010 });
6011 }
6012 return Ok({ status: "removed", action: "remove", ...this.lifecycleTargetFields(resolved) });
6013 });
6014 }
6015
6016 private async withWorkspaceLifecycleLock<T>(
6017 resolved: ResolvedWorkspaceLifecycleTarget,

Callers 2

Calls 8

lifecycleTargetFieldsMethod · 0.95
OkFunction · 0.90
isWorkspaceArchivedFunction · 0.90
removeMethod · 0.65
assertFunction · 0.50

Tested by

no test coverage detected