Skip to content
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

[bridge] Check workspace instance phase duration #12879

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
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
18 changes: 16 additions & 2 deletions components/ws-manager-bridge/src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ export class WorkspaceManagerBridge implements Disposable {
clientProvider: ClientProvider,
controllerIntervalSeconds: number,
controllerMaxDisconnectSeconds: number,
maxTimeToRunningPhaseSeconds = 60 * 60,
) {
let disconnectStarted = Number.MAX_SAFE_INTEGER;
this.disposables.push(
Expand All @@ -452,7 +453,12 @@ export class WorkspaceManagerBridge implements Disposable {

// Control running workspace instances against ws-manager
try {
await this.controlRunningInstances(ctx, runningInstances, clientProvider);
await this.controlRunningInstances(
ctx,
runningInstances,
clientProvider,
maxTimeToRunningPhaseSeconds,
);

disconnectStarted = Number.MAX_SAFE_INTEGER; // Reset disconnect period
} catch (err) {
Expand Down Expand Up @@ -489,6 +495,7 @@ export class WorkspaceManagerBridge implements Disposable {
parentCtx: TraceContext,
runningInstances: RunningWorkspaceInfo[],
clientProvider: ClientProvider,
maxTimeToRunningPhaseSeconds: number,
) {
const installation = this.config.installation;

Expand All @@ -506,7 +513,14 @@ export class WorkspaceManagerBridge implements Disposable {

for (const [instanceId, ri] of runningInstancesIdx.entries()) {
const instance = ri.latestInstance;
if (instance.status.phase !== "running") {
// This ensures that the workspace instance is not in a
// non-running phase for longer than the max time
if (
!(
instance.status.phase === "running" ||
durationLongerThanSeconds(Date.parse(instance.creationTime), maxTimeToRunningPhaseSeconds)
)
) {
log.debug({ instanceId }, "Skipping instance", {
phase: instance.status.phase,
creationTime: instance.creationTime,
Expand Down