Skip to content

Commit

Permalink
[server] allow user custom global timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
iQQBot committed Feb 24, 2023
1 parent 6ab9dc4 commit c6b20e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 15 additions & 1 deletion components/server/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 || [];

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c6b20e1

Please sign in to comment.