From fabfbde79c4e60f09d6ac66da988ea6730c7d9dd Mon Sep 17 00:00:00 2001 From: Jan Keromnes Date: Wed, 14 Sep 2022 09:45:21 +0000 Subject: [PATCH] [ws-manager-bridge] Clean up instance tokens and track workspace stop even in irregular cases --- components/ws-manager-bridge/src/bridge.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/ws-manager-bridge/src/bridge.ts b/components/ws-manager-bridge/src/bridge.ts index 5546b2a1678f58..623f769e1618f9 100644 --- a/components/ws-manager-bridge/src/bridge.ts +++ b/components/ws-manager-bridge/src/bridge.ts @@ -618,12 +618,18 @@ export class WorkspaceManagerBridge implements Disposable { protected async markWorkspaceInstanceAsStopped(ctx: TraceContext, info: RunningWorkspaceInfo, now: Date) { const nowISO = now.toISOString(); - info.latestInstance.stoppingTime = nowISO; + if (!info.latestInstance.stoppingTime) { + info.latestInstance.stoppingTime = nowISO; + } info.latestInstance.stoppedTime = nowISO; info.latestInstance.status.message = `Stopped by ws-manager-bridge. Previously in phase ${info.latestInstance.status.phase}`; info.latestInstance.status.phase = "stopped"; await this.workspaceDB.trace(ctx).storeInstance(info.latestInstance); + // cleanup + // important: call this after the DB update + await this.onInstanceStopped(ctx, info.workspace.ownerId, info.latestInstance); + await this.messagebus.notifyOnInstanceUpdate(ctx, info.workspace.ownerId, info.latestInstance); await this.prebuildUpdater.stopPrebuildInstance(ctx, info.latestInstance); }