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
Prev Previous commit
Next Next commit
Early return
  • Loading branch information
mtojek committed Jul 4, 2023
commit 962453d4fe86db5ff6360e874790c749643e4c54
31 changes: 13 additions & 18 deletions site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,14 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
const now = dayjs()
useEffect(() => {
if (
workspace.latest_build.status === "pending" &&
workspace.latest_build.job.queue_size > 0 &&
workspace.latest_build.status !== "pending" ||
workspace.latest_build.job.queue_size === 0
) {
setShowAlertPendingInQueue(false)
return
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we need to return a clearTimeout here too? Otherwise navigating away from this view could trigger the timer after-the-fact (is that a problem?). Then again, if the function is triggered every time useEffect has new values, we need to make sure we don't repeatedly set/clear the timeout when e.g. new workspace data comes in (let's say there are 10 updates <250ms apart each, then this would ultimately take ~2.5s to trigger).

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 played a bit, and didn't observe any unexpected side effects of having clearTimeout, so added it 👍

}

if (
dayjs(workspace.latest_build.created_at).isBefore(
now.subtract(5, "seconds"),
)
Expand All @@ -147,23 +153,12 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
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)
const timer = setTimeout(() => {
setShowAlertPendingInQueue(true)
}, 5000)

return () => {
clearTimeout(timer)
}
return () => {
clearTimeout(timer)
}
}, [workspace, now])
return (
Expand Down