fix: auto-stop bumper works and refreshes (#5162)

* Publish updates to workspace deadline

* Fix sync between machines
This commit is contained in:
Presley Pizzo 2022-11-28 10:59:43 -05:00 committed by GitHub
parent 898ba11ef0
commit d5ab4fdeb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 11 deletions

View File

@ -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)
}

View File

@ -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 (
<>
<Helmet>

View File

@ -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.