Skip to content

Commit 7da0e3e

Browse files
committed
push so I can test locally rather than via workspace
1 parent c6e7f36 commit 7da0e3e

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/api.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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"
33
import fs from "fs/promises"
44
import { ProxyAgent } from "proxy-agent"
55
import * as vscode from "vscode"
@@ -103,13 +103,30 @@ export async function startWorkspace(restClient: Api, workspace: Workspace): Pro
103103
workspace.template_active_version_id
104104
: // Default to not updating the workspace if not required.
105105
workspace.latest_build.template_version_id
106+
106107
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+
107114
return {
108115
...workspace,
109116
latest_build: latestBuild,
110117
}
111118
}
112119

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+
113130
/**
114131
* Wait for the latest build to finish while streaming logs to the emitter.
115132
*

src/remote.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as path from "path"
1010
import prettyBytes from "pretty-bytes"
1111
import * as semver from "semver"
1212
import * as vscode from "vscode"
13-
import { makeCoderSdk, startWorkspace, waitForBuild } from "./api"
13+
import { getWorkspaceStatus, makeCoderSdk, startWorkspace, waitForBuild } from "./api"
1414
import { extractAgents } from "./api-helper"
1515
import * as cli from "./cliManager"
1616
import { Commands } from "./commands"
@@ -104,8 +104,10 @@ export class Remote {
104104
if (!(await this.confirmStart(workspaceName))) {
105105
return undefined
106106
}
107-
this.storage.writeToCoderOutputChannel(`Starting ${workspaceName}...`)
108-
workspace = await startWorkspace(restClient, workspace)
107+
if (!["running", "starting"].includes(await getWorkspaceStatus(restClient, workspace.id))) {
108+
this.storage.writeToCoderOutputChannel(`Starting ${workspaceName}...`)
109+
workspace = await startWorkspace(restClient, workspace)
110+
}
109111
break
110112
case "failed":
111113
// On a first attempt, we will try starting a failed workspace

0 commit comments

Comments
 (0)