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
fmt
  • Loading branch information
mtojek committed Jul 3, 2023
commit 51734f68ffa4c27d6542ff53d01dd80716ace7bd
39 changes: 24 additions & 15 deletions site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,37 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
transitionStats = ActiveTransition(template, workspace)
}

const [showAlertPendingInQueue, setShowAlertPendingInQueue] = useState(false);
const [showAlertPendingInQueue, setShowAlertPendingInQueue] = useState(false)
const now = dayjs()
useEffect(() => {
if (workspace.latest_build.status === "pending" &&
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);
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);
if (
workspace.latest_build.status === "pending" &&
workspace.latest_build.job.queue_size > 0
Copy link
Member

Choose a reason for hiding this comment

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

I noticed we're not setting setShowAlertPendingInQueue(false) anywhere? Perhaps this condition could be inverted and placed at the top with an false + early return. Should simplify the other checks as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

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

Choose a reason for hiding this comment

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

How about using the difference here (now.subtract 5 sec) so that loading a new workspace doesn't reset the timer to 5 seconds?

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'm not sure that I understand what you mean. Could you please elaborate a bit more about the case you have in mind?

Copy link
Member

Choose a reason for hiding this comment

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

So let's say you:

  1. Start a workspace build
  2. Wait 3 seconds
  3. Reload the workspace page
  4. Build still pending, we start the timer with hard-coded 5 second wait
  5. Queue banner is shown (time since build started 8 seconds vs 5 seconds)

Does this make sense?

Copy link
Member Author

Choose a reason for hiding this comment

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

Make sense now, thanks.

I used the diff, feel free to review that part.


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