Skip to content

Commit 3dbc96d

Browse files
authored
feat: show queue position of pending workspace build (coder#8244)
1 parent d3c39b6 commit 3dbc96d

File tree

7 files changed

+56
-2
lines changed

7 files changed

+56
-2
lines changed

site/src/components/Workspace/Workspace.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ export const WithoutUpdateAccess: Story = {
9898
},
9999
}
100100

101+
export const PendingInQueue: Story = {
102+
args: {
103+
...Running.args,
104+
workspace: Mocks.MockPendingWorkspace,
105+
},
106+
}
107+
101108
export const Starting: Story = {
102109
args: {
103110
...Running.args,

site/src/components/Workspace/Workspace.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { ImpendingDeletionBanner } from "components/WorkspaceDeletion"
3131
import { useLocalStorage } from "hooks"
3232
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne"
3333
import AlertTitle from "@mui/material/AlertTitle"
34+
import { Maybe } from "components/Conditionals/Maybe"
3435

3536
export enum WorkspaceErrors {
3637
GET_BUILDS_ERROR = "getBuildsError",
@@ -207,6 +208,29 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
207208

208209
<TemplateVersionWarnings warnings={templateWarnings} />
209210

211+
<Maybe
212+
condition={
213+
workspace.latest_build.status === "pending" &&
214+
workspace.latest_build.job.queue_size > 0
215+
}
216+
>
217+
<Alert severity="info">
218+
<AlertTitle>Workspace build is pending</AlertTitle>
219+
<AlertDetail>
220+
<div className={styles.alertPendingInQueue}>
221+
This workspace build job is waiting for a provisioner to
222+
become available. If you have been waiting for an extended
223+
period of time, please contact your administrator for
224+
assistance.
225+
</div>
226+
<div>
227+
Position in queue:{" "}
228+
<strong>{workspace.latest_build.job.queue_position}</strong>
229+
</div>
230+
</AlertDetail>
231+
</Alert>
232+
</Maybe>
233+
210234
{failedBuildLogs && (
211235
<Stack>
212236
<Alert
@@ -319,5 +343,9 @@ export const useStyles = makeStyles((theme) => {
319343
fullWidth: {
320344
width: "100%",
321345
},
346+
347+
alertPendingInQueue: {
348+
marginBottom: 12,
349+
},
322350
}
323351
})

site/src/components/WorkspaceStatusBadge/WorkspaceStatusBadge.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const WorkspaceStatusBadge: FC<
2020
> = ({ workspace, className }) => {
2121
const { text, icon, type } = getDisplayWorkspaceStatus(
2222
workspace.latest_build.status,
23+
workspace.latest_build.job,
2324
)
2425
return (
2526
<ChooseOne>

site/src/components/WorkspacesTable/WorkspacesTable.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const Language = {
1313
template: "Template",
1414
lastUsed: "Last Used",
1515
status: "Status",
16-
lastBuiltBy: "Last Built By",
1716
}
1817

1918
export interface WorkspacesTableProps {

site/src/pages/WorkspacesPage/WorkspacesPageView.stories.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
MockExperiments,
1616
mockApiError,
1717
MockUser,
18+
MockPendingProvisionerJob,
1819
} from "testHelpers/entities"
1920
import { WorkspacesPageView } from "./WorkspacesPageView"
2021
import { DashboardProviderContext } from "components/Dashboard/DashboardProvider"
@@ -33,6 +34,10 @@ const createWorkspace = (
3334
latest_build: {
3435
...MockWorkspace.latest_build,
3536
status,
37+
job:
38+
status === "pending"
39+
? MockPendingProvisionerJob
40+
: MockWorkspace.latest_build.job,
3641
},
3742
last_used_at: lastUsedAt,
3843
}

site/src/testHelpers/entities.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ export const MockRunningProvisionerJob: TypesGen.ProvisionerJob = {
310310
export const MockPendingProvisionerJob: TypesGen.ProvisionerJob = {
311311
...MockProvisionerJob,
312312
status: "pending",
313+
queue_position: 2,
314+
queue_size: 4,
313315
}
314316
export const MockTemplateVersion: TypesGen.TemplateVersion = {
315317
id: "test-template-version",

site/src/utils/workspace.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ export const getDisplayWorkspaceTemplateName = (
194194

195195
export const getDisplayWorkspaceStatus = (
196196
workspaceStatus: TypesGen.WorkspaceStatus,
197+
provisionerJob?: TypesGen.ProvisionerJob,
197198
) => {
198199
const { t } = i18next
199200

@@ -260,12 +261,23 @@ export const getDisplayWorkspaceStatus = (
260261
case "pending":
261262
return {
262263
type: "info",
263-
text: t("workspaceStatus.pending", { ns: "common" }),
264+
text: getPendingWorkspaceStatusText(provisionerJob),
264265
icon: <QueuedIcon />,
265266
} as const
266267
}
267268
}
268269

270+
const getPendingWorkspaceStatusText = (
271+
provisionerJob?: TypesGen.ProvisionerJob,
272+
): string => {
273+
const { t } = i18next
274+
275+
if (!provisionerJob || provisionerJob.queue_size === 0) {
276+
return t("workspaceStatus.pending", { ns: "common" })
277+
}
278+
return "Position in queue: " + provisionerJob.queue_position
279+
}
280+
269281
const LoadingIcon = () => {
270282
return <CircularProgress size={10} style={{ color: "#FFF" }} />
271283
}

0 commit comments

Comments
 (0)