From d5ab4fdeb8a725f98bd11fe9d1a6d59d3f31de80 Mon Sep 17 00:00:00 2001 From: Presley Pizzo <1290996+presleyp@users.noreply.github.com> Date: Mon, 28 Nov 2022 10:59:43 -0500 Subject: [PATCH] fix: auto-stop bumper works and refreshes (#5162) * Publish updates to workspace deadline * Fix sync between machines --- coderd/workspaces.go | 1 + site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx | 7 ++++++- site/src/xServices/workspace/workspaceXService.ts | 10 ---------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/coderd/workspaces.go b/coderd/workspaces.go index ed6698c431..fe796f370c 100644 --- a/coderd/workspaces.go +++ b/coderd/workspaces.go @@ -784,6 +784,7 @@ func (api *API) putExtendWorkspace(rw http.ResponseWriter, r *http.Request) { if err != nil { api.Logger.Info(ctx, "extending workspace", slog.Error(err)) } + api.publishWorkspaceUpdate(ctx, workspace.ID) httpapi.Write(ctx, rw, code, resp) } diff --git a/site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx b/site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx index ea87ad679a..ab293db819 100644 --- a/site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx +++ b/site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx @@ -1,7 +1,7 @@ import { useActor, useSelector } from "@xstate/react" import { FeatureNames } from "api/types" import dayjs from "dayjs" -import { useContext } from "react" +import { useContext, useEffect } from "react" import { Helmet } from "react-helmet-async" import { useTranslation } from "react-i18next" import { useNavigate } from "react-router-dom" @@ -66,6 +66,11 @@ export const WorkspaceReadyPage = ({ const favicon = getFaviconByStatus(workspace.latest_build) const navigate = useNavigate() + // keep banner machine in sync with workspace + useEffect(() => { + bannerSend({ type: "REFRESH_WORKSPACE", workspace }) + }, [bannerSend, workspace]) + return ( <> diff --git a/site/src/xServices/workspace/workspaceXService.ts b/site/src/xServices/workspace/workspaceXService.ts index 13b8afa1b8..18480de9cc 100644 --- a/site/src/xServices/workspace/workspaceXService.ts +++ b/site/src/xServices/workspace/workspaceXService.ts @@ -473,9 +473,6 @@ export const workspaceMachine = createMachine( template: (context: WorkspaceContext) => context.template, }, }, - on: { - REFRESH_WORKSPACE: { actions: "sendWorkspaceToSchedule" }, - }, }, }, }, @@ -594,13 +591,6 @@ export const workspaceMachine = createMachine( ) displayError(message) }, - sendWorkspaceToSchedule: send( - (context) => ({ - type: "REFRESH_WORKSPACE", - workspace: context.workspace, - }), - { to: "scheduleBannerMachine" }, - ), // Optimistically update. So when the user clicks on stop, we can show // the "pending" state right away without having to wait 0.5s ~ 2s to // display the visual feedback to the user.