Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: delay pending-in-queue banner #8309

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 5 commits into from
Jul 6, 2023
Merged
Changes from 1 commit
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
Next Next commit
feat: delay build in queue banner
  • Loading branch information
mtojek committed Jul 3, 2023
commit 036301dca98a2d972272bfbcddb8d93d85db74ee
35 changes: 28 additions & 7 deletions site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ActiveTransition,
WorkspaceBuildProgress,
} from "components/WorkspaceBuildProgress/WorkspaceBuildProgress"
import { FC } from "react"
import { FC, useEffect, useState } from "react"
import { useTranslation } from "react-i18next"
import { useNavigate } from "react-router-dom"
import * as TypesGen from "../../api/typesGenerated"
Expand All @@ -32,6 +32,7 @@ import { useLocalStorage } from "hooks"
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne"
import AlertTitle from "@mui/material/AlertTitle"
import { Maybe } from "components/Conditionals/Maybe"
import dayjs from "dayjs"

export enum WorkspaceErrors {
GET_BUILDS_ERROR = "getBuildsError",
Expand Down Expand Up @@ -131,6 +132,31 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
if (template !== undefined) {
transitionStats = ActiveTransition(template, workspace)
}

const [showAlertPendingInQueue, setShowAlertPendingInQueue] = useState(false);
const now = dayjs()
useEffect(() => {
if (workspace.latest_build.status === "pending" &&
workspace.latest_build.job.queue_size > 0 &&
dayjs(workspace.latest_build.created_at).isBefore(now.subtract(5, 'seconds'))) {
setShowAlertPendingInQueue(true);
return
}

if (workspace.latest_build.status === "pending" &&
workspace.latest_build.job.queue_size > 0) {
const timer = setTimeout(() => {
if (workspace.latest_build.status !== "pending" || workspace.latest_build.job.queue_size === 0) {
return
}
setShowAlertPendingInQueue(true);
}, 5000)

return () => {
clearTimeout(timer);
}
}
}, [workspace, now])
return (
<>
<FullWidthPageHeader>
Expand Down Expand Up @@ -208,12 +234,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({

<TemplateVersionWarnings warnings={templateWarnings} />

<Maybe
condition={
workspace.latest_build.status === "pending" &&
workspace.latest_build.job.queue_size > 0
}
>
<Maybe condition={showAlertPendingInQueue}>
<Alert severity="info">
<AlertTitle>Workspace build is pending</AlertTitle>
<AlertDetail>
Expand Down