Skip to content

feat: show queue position of pending workspace build #8244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions site/src/components/Workspace/Workspace.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export const WithoutUpdateAccess: Story = {
},
}

export const PendingInQueue: Story = {
args: {
...Running.args,
workspace: Mocks.MockPendingWorkspace,
},
}

export const Starting: Story = {
args: {
...Running.args,
Expand Down
28 changes: 28 additions & 0 deletions site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ImpendingDeletionBanner } from "components/WorkspaceDeletion"
import { useLocalStorage } from "hooks"
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne"
import AlertTitle from "@mui/material/AlertTitle"
import { Maybe } from "components/Conditionals/Maybe"

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

<TemplateVersionWarnings warnings={templateWarnings} />

<Maybe
condition={
workspace.latest_build.status === "pending" &&
workspace.latest_build.job.queue_size > 0
}
>
<Alert severity="info">
<AlertTitle>Workspace build is pending</AlertTitle>
<AlertDetail>
<div className={styles.alertPendingInQueue}>
This workspace build job is waiting for a provisioner to
become available. If you have been waiting for an extended
period of time, please contact your administrator for
assistance.
</div>
<div>
Position in queue:{" "}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the {" "} necessary here? I would imagine the newline becomes a space but maybe not in React-land.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be necessary. Otherwise, it's merged together: Position in queue:3 (no space).

<strong>{workspace.latest_build.job.queue_position}</strong>
</div>
</AlertDetail>
</Alert>
</Maybe>

{failedBuildLogs && (
<Stack>
<Alert
Expand Down Expand Up @@ -319,5 +343,9 @@ export const useStyles = makeStyles((theme) => {
fullWidth: {
width: "100%",
},

alertPendingInQueue: {
marginBottom: 12,
},
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const WorkspaceStatusBadge: FC<
> = ({ workspace, className }) => {
const { text, icon, type } = getDisplayWorkspaceStatus(
workspace.latest_build.status,
workspace.latest_build.job,
)
return (
<ChooseOne>
Expand Down
1 change: 0 additions & 1 deletion site/src/components/WorkspacesTable/WorkspacesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const Language = {
template: "Template",
lastUsed: "Last Used",
status: "Status",
lastBuiltBy: "Last Built By",
}

export interface WorkspacesTableProps {
Expand Down
5 changes: 5 additions & 0 deletions site/src/pages/WorkspacesPage/WorkspacesPageView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
MockExperiments,
mockApiError,
MockUser,
MockPendingProvisionerJob,
} from "testHelpers/entities"
import { WorkspacesPageView } from "./WorkspacesPageView"
import { DashboardProviderContext } from "components/Dashboard/DashboardProvider"
Expand All @@ -33,6 +34,10 @@ const createWorkspace = (
latest_build: {
...MockWorkspace.latest_build,
status,
job:
status === "pending"
? MockPendingProvisionerJob
: MockWorkspace.latest_build.job,
},
last_used_at: lastUsedAt,
}
Expand Down
2 changes: 2 additions & 0 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ export const MockRunningProvisionerJob: TypesGen.ProvisionerJob = {
export const MockPendingProvisionerJob: TypesGen.ProvisionerJob = {
...MockProvisionerJob,
status: "pending",
queue_position: 2,
queue_size: 4,
}
export const MockTemplateVersion: TypesGen.TemplateVersion = {
id: "test-template-version",
Expand Down
14 changes: 13 additions & 1 deletion site/src/utils/workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export const getDisplayWorkspaceTemplateName = (

export const getDisplayWorkspaceStatus = (
workspaceStatus: TypesGen.WorkspaceStatus,
provisionerJob?: TypesGen.ProvisionerJob,
) => {
const { t } = i18next

Expand Down Expand Up @@ -260,12 +261,23 @@ export const getDisplayWorkspaceStatus = (
case "pending":
return {
type: "info",
text: t("workspaceStatus.pending", { ns: "common" }),
text: getPendingWorkspaceStatusText(provisionerJob),
icon: <QueuedIcon />,
} as const
}
}

const getPendingWorkspaceStatusText = (
provisionerJob?: TypesGen.ProvisionerJob,
): string => {
const { t } = i18next

if (!provisionerJob || provisionerJob.queue_size === 0) {
return t("workspaceStatus.pending", { ns: "common" })
}
return "Position in queue: " + provisionerJob.queue_position
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use t here too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I skipped this on purpose, as we are not going to implement translations. I learnt some time ago

}

const LoadingIcon = () => {
return <CircularProgress size={10} style={{ color: "#FFF" }} />
}