From c6b20e1c8089d6907692c7f43993fcadbfeedef1 Mon Sep 17 00:00:00 2001 From: Pudong Zheng Date: Fri, 24 Feb 2023 16:15:25 +0000 Subject: [PATCH] [server] allow user custom global timeout --- components/gitpod-protocol/src/protocol.ts | 1 + .../server/src/workspace/workspace-starter.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/components/gitpod-protocol/src/protocol.ts b/components/gitpod-protocol/src/protocol.ts index 417ec12adfc485..3256a3e1d18fd0 100644 --- a/components/gitpod-protocol/src/protocol.ts +++ b/components/gitpod-protocol/src/protocol.ts @@ -256,6 +256,7 @@ export interface AdditionalUserData { isMigratedToTeamOnlyAttribution?: boolean; // user globol workspace timeout workspaceTimeout?: string; + // control whether to enable the closed timeout of a workspace, i.e. close web ide, disconnect ssh connection disabledClosedTimeout?: boolean; } export namespace AdditionalUserData { diff --git a/components/server/src/workspace/workspace-starter.ts b/components/server/src/workspace/workspace-starter.ts index e993746e78b42b..aa4d7c1ad5f5f4 100644 --- a/components/server/src/workspace/workspace-starter.ts +++ b/components/server/src/workspace/workspace-starter.ts @@ -57,6 +57,7 @@ import { Project, GitpodServer, IDESettings, + WorkspaceTimeoutDuration, } from "@gitpod/gitpod-protocol"; import { IAnalyticsWriter } from "@gitpod/gitpod-protocol/lib/analytics"; import { log } from "@gitpod/gitpod-protocol/lib/util/logging"; @@ -1437,6 +1438,7 @@ export class WorkspaceStarter { lastValidWorkspaceInstanceId, ); const userTimeoutPromise = this.entitlementService.getDefaultWorkspaceTimeout(user, new Date()); + const allowSetTimeoutPromise = this.entitlementService.maySetTimeout(user, new Date()); let featureFlags = instance.configuration!.featureFlags || []; @@ -1467,7 +1469,19 @@ export class WorkspaceStarter { spec.setClass(instance.workspaceClass!); if (workspace.type === "regular") { - spec.setTimeout(await userTimeoutPromise); + const [defaultTimeout, allowSetTimeout] = await Promise.all([userTimeoutPromise, allowSetTimeoutPromise]); + spec.setTimeout(defaultTimeout); + if (allowSetTimeout) { + if (user.additionalData?.workspaceTimeout) { + try { + let timeout = WorkspaceTimeoutDuration.validate(user.additionalData?.workspaceTimeout); + spec.setTimeout(timeout); + } catch (err) {} + } + if (user.additionalData?.disabledClosedTimeout === true) { + spec.setClosedTimeout("0"); + } + } } spec.setAdmission(admissionLevel); const sshKeys = await this.userDB.trace(traceCtx).getSSHPublicKeys(user.id);