|
1 | 1 | import { Api } from "coder/site/src/api/api"
|
2 |
| -import { ProvisionerJobLog, Workspace } from "coder/site/src/api/typesGenerated" |
| 2 | +import { ProvisionerJobLog, Workspace, WorkspaceStatus } from "coder/site/src/api/typesGenerated" |
3 | 3 | import fs from "fs/promises"
|
4 | 4 | import { ProxyAgent } from "proxy-agent"
|
5 | 5 | import * as vscode from "vscode"
|
@@ -103,13 +103,30 @@ export async function startWorkspace(restClient: Api, workspace: Workspace): Pro
|
103 | 103 | workspace.template_active_version_id
|
104 | 104 | : // Default to not updating the workspace if not required.
|
105 | 105 | workspace.latest_build.template_version_id
|
| 106 | + |
106 | 107 | const latestBuild = await restClient.startWorkspace(workspace.id, versionID)
|
| 108 | + // Before we start a workspace, we make an initial request to check it's not already started |
| 109 | + // let latestBuild = (await restClient.getWorkspace(workspace.id)).latest_build |
| 110 | + // if (!["starting", "running"].includes(latestBuild.status)) { |
| 111 | + |
| 112 | + // } |
| 113 | + |
107 | 114 | return {
|
108 | 115 | ...workspace,
|
109 | 116 | latest_build: latestBuild,
|
110 | 117 | }
|
111 | 118 | }
|
112 | 119 |
|
| 120 | +/** |
| 121 | + * Get the status of a workspace |
| 122 | + * @param restClient Api |
| 123 | + * @param workspaceId string |
| 124 | + * @returns WorkspaceStatus |
| 125 | + */ |
| 126 | +export async function getWorkspaceStatus(restClient: Api, workspaceId: string): Promise<WorkspaceStatus> { |
| 127 | + return (await restClient.getWorkspace(workspaceId)).latest_build.status |
| 128 | +} |
| 129 | + |
113 | 130 | /**
|
114 | 131 | * Wait for the latest build to finish while streaming logs to the emitter.
|
115 | 132 | *
|
|
0 commit comments