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

Method getWorkspaceStatus

src/node/services/coderService.ts:1143–1189  ·  view source on GitHub ↗

* Get workspace status using control-plane query. * * Note: `coder list --search 'name:X'` is prefix-based on the server, * so we must exact-match the workspace name client-side.

(
    workspaceName: string,
    options?: { timeoutMs?: number; signal?: AbortSignal }
  )

Source from the content-addressed store, hash-verified

1141 * so we must exact-match the workspace name client-side.
1142 */
1143 async getWorkspaceStatus(
1144 workspaceName: string,
1145 options?: { timeoutMs?: number; signal?: AbortSignal }
1146 ): Promise<WorkspaceStatusResult> {
1147 const timeoutMs = options?.timeoutMs ?? 10_000;
1148
1149 try {
1150 const result = await this.runCoderCommand(
1151 ["list", "--search", `name:${workspaceName}`, "--output", "json"],
1152 { timeoutMs, signal: options?.signal }
1153 );
1154
1155 const interpreted = interpretCoderResult(result);
1156 if (!interpreted.ok) {
1157 return { kind: "error", error: interpreted.error };
1158 }
1159
1160 if (!interpreted.stdout.trim()) {
1161 return { kind: "not_found" };
1162 }
1163
1164 const workspaces = JSON.parse(interpreted.stdout) as Array<{
1165 name: string;
1166 latest_build: { status: string };
1167 }>;
1168
1169 // Exact match required (search is prefix-based)
1170 const match = workspaces.find((w) => w.name === workspaceName);
1171 if (!match) {
1172 return { kind: "not_found" };
1173 }
1174
1175 // Validate status against known schema values
1176 const status = match.latest_build.status;
1177 const parsed = CoderWorkspaceStatusSchema.safeParse(status);
1178 if (!parsed.success) {
1179 log.warn("Unknown Coder workspace status", { workspaceName, status });
1180 return { kind: "error", error: `Unknown status: ${status}` };
1181 }
1182
1183 return { kind: "ok", status: parsed.data };
1184 } catch (error) {
1185 const message = getErrorMessage(error);
1186 log.debug("Failed to get Coder workspace status", { workspaceName, error: message });
1187 return { kind: "error", error: message };
1188 }
1189 }
1190
1191 /**
1192 * Start a Coder workspace.

Callers 8

createCoderArchiveHookFunction · 0.80
createCoderUnarchiveHookFunction · 0.80
doEnsureReadyMethod · 0.80
deleteWorkspaceMethod · 0.80
postCreateSetupMethod · 0.80

Calls 5

runCoderCommandMethod · 0.95
getErrorMessageFunction · 0.90
interpretCoderResultFunction · 0.85
debugMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected