Skip to content

Commit b513e54

Browse files
authored
Merge pull request #2 from gitpod-io/pd/custom-timeout
allow user customize workspace timeout
2 parents 57f10d5 + 4cee7ef commit b513e54

File tree

7 files changed

+58
-20
lines changed

7 files changed

+58
-20
lines changed

gitpod-remote/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@
9393
"title": "%extendTimeout%",
9494
"enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true"
9595
},
96+
{
97+
"command": "gitpod.setWorkspaceTimeout",
98+
"title": "%customizeTimeout%",
99+
"enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true"
100+
},
96101
{
97102
"command": "gitpod.takeSnapshot",
98103
"title": "%takeSnapshot%",

gitpod-remote/package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"reportIssue": "Gitpod: Report Issue",
1212
"stopWorkspace": "Gitpod: Stop Workspace",
1313
"upgradeSubscription": "Gitpod: Upgrade Subscription",
14-
"extendTimeout": "Gitpod: Extend Workspace Timeout",
14+
"extendTimeout": "Gitpod: Extend Workspace Timeout (180m)",
15+
"configureTimeout": "Gitpod: Configure Workspace Timeout",
1516
"takeSnapshot": "Gitpod: Share Workspace Snapshot",
1617
"shareWorkspace": "Gitpod: Share Running Workspace",
1718
"stopSharingWorkspace": "Gitpod: Stop Sharing Running Workspace",

gitpod-shared/src/analytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type GitpodAnalyticsEvent =
3535
targetQualifier?: 'stable' | 'insiders';
3636
}> |
3737
GAET<'vscode_execute_command_gitpod_workspace', {
38-
action: 'share' | 'stop-sharing' | 'stop' | 'snapshot' | 'extend-timeout';
38+
action: 'share' | 'stop-sharing' | 'stop' | 'snapshot' | 'extend-timeout'| 'configure-timeout';
3939
}> |
4040
GAET<'vscode_execute_command_gitpod_ports', {
4141
action: 'private' | 'public' | 'preview' | 'openBrowser' | 'urlCopy';

gitpod-shared/src/features.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export async function registerWorkspaceCommands(context: GitpodExtensionContext)
239239
return context.gitpod.server.stopWorkspace(context.info.workspaceId);
240240
}));
241241
context.subscriptions.push(vscode.commands.registerCommand('gitpod.upgradeSubscription', () => {
242-
const url = new GitpodHostUrl(context.info.gitpodHost).asUpgradeSubscription().toString();
242+
const url = new GitpodHostUrl(context.info.gitpodHost).asBilling().toString();
243243
context.fireAnalyticsEvent({
244244
eventName: 'vscode_execute_command_gitpod_open_link',
245245
properties: { url }
@@ -387,36 +387,57 @@ export async function registerWorkspaceTimeout(context: GitpodExtensionContext):
387387
}
388388
});
389389
try {
390-
const result = await context.gitpod.server.setWorkspaceTimeout(context.info.workspaceId, '180m');
391-
if (result.resetTimeoutOnWorkspaces?.length > 0) {
392-
vscode.window.showWarningMessage('Workspace timeout has been extended to three hours. This reset the workspace timeout for other workspaces.');
393-
} else {
394-
vscode.window.showInformationMessage('Workspace timeout has been extended to three hours.');
395-
}
390+
await context.gitpod.server.setWorkspaceTimeout(context.info.workspaceId, '180m');
391+
vscode.window.showWarningMessage(`Workspace timeout has been extended to 180m.`);
396392
} catch (err) {
397393
vscode.window.showErrorMessage(`Cannot extend workspace timeout: ${err.toString()}`);
398394
}
399395
}));
400396

397+
398+
context.subscriptions.push(vscode.commands.registerCommand('gitpod.setWorkspaceTimeout', async () => {
399+
const timeout = await vscode.window.showInputBox({
400+
value: '180m',
401+
prompt: 'Please input the timeout time, such as 30m, 1h, 2h, 3h',
402+
});
403+
if (!timeout) {
404+
return;
405+
}
406+
context.fireAnalyticsEvent({
407+
eventName: 'vscode_execute_command_gitpod_workspace',
408+
properties: {
409+
action: 'configure-timeout'
410+
}
411+
});
412+
try {
413+
const { humanReadableDuration } = await context.gitpod.server.setWorkspaceTimeout(context.info.workspaceId, timeout);
414+
vscode.window.showWarningMessage(`Workspace timeout has been changed to ${humanReadableDuration ?? timeout}.`);
415+
} catch (err) {
416+
vscode.window.showErrorMessage(`Cannot configure workspace timeout: ${err.toString()}`);
417+
}
418+
}));
419+
401420
const workspaceTimeout = await context.gitpod.server.getWorkspaceTimeout(context.info.workspaceId);
402421
if (!workspaceTimeout.canChange) {
403422
return;
404423
}
405424

406425
const listener = await context.instanceListener;
407426
const extendTimeoutStatusBarItem = vscode.window.createStatusBarItem('gitpod.extendTimeout', vscode.StatusBarAlignment.Right, -100);
408-
extendTimeoutStatusBarItem.name = 'Click to extend the workspace timeout.';
427+
extendTimeoutStatusBarItem.name = 'Extend the workspace timeout.';
409428
context.subscriptions.push(extendTimeoutStatusBarItem);
410429
extendTimeoutStatusBarItem.text = '$(watch)';
411-
extendTimeoutStatusBarItem.command = 'gitpod.ExtendTimeout';
430+
extendTimeoutStatusBarItem.command = 'gitpod.setWorkspaceTimeout';
412431
const update = () => {
413432
const instance = listener.info.latestInstance;
414433
if (!instance) {
415434
extendTimeoutStatusBarItem.hide();
416435
return;
417436
}
418437
extendTimeoutStatusBarItem.tooltip = `Workspace Timeout: ${instance.status.timeout}. Click to extend.`;
419-
extendTimeoutStatusBarItem.color = instance.status.timeout === '180m' ? new vscode.ThemeColor('notificationsWarningIcon.foreground') : undefined;
438+
439+
// TODO: query default timeout, currently all paid plan default timeout is 60m.
440+
extendTimeoutStatusBarItem.color = instance.status.timeout !== '60m' ? new vscode.ThemeColor('notificationsWarningIcon.foreground') : undefined;
420441
extendTimeoutStatusBarItem.show();
421442
};
422443
update();

gitpod-shared/yarn.lock

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44

55
"@gitpod/gitpod-protocol@main":
6-
version "0.1.5-main.6379"
7-
resolved "https://registry.yarnpkg.com/@gitpod/gitpod-protocol/-/gitpod-protocol-0.1.5-main.6379.tgz#8c654e9d1658a62648ec4a1bc837f3d5756f8a14"
8-
integrity sha512-QLScSNODhMle/w23HSr3RihIh7S+ZE46JRbOqbFgR9+a0FBoxPtHi6kqUmeNgqvt+hfyjgdPG5/yddU7j0uznA==
6+
version "0.1.5-main.6559"
7+
resolved "https://registry.yarnpkg.com/@gitpod/gitpod-protocol/-/gitpod-protocol-0.1.5-main.6559.tgz#e771beee25447b12dce79fea4abad4caed8db9fc"
8+
integrity sha512-v6E5AnpiTkWEBhyuBT8/gXVYzSKHUK1IUoa9CCr3q5jsdgG0egGzotcsu1OTmDZ68R1UKCvu4RddQZgU5ZGTjg==
99
dependencies:
1010
"@types/react" "17.0.32"
1111
abort-controller-x "^0.4.0"
@@ -589,9 +589,9 @@ [email protected]:
589589
safe-buffer "5.2.1"
590590

591591
content-type@~1.0.4:
592-
version "1.0.4"
593-
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b"
594-
integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==
592+
version "1.0.5"
593+
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.5.tgz#8b773162656d1d1086784c8f23a54ce6d73d7918"
594+
integrity sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==
595595

596596
597597
version "1.0.6"
@@ -1222,7 +1222,12 @@ minimatch@^3.0.4, minimatch@^3.1.1:
12221222
dependencies:
12231223
brace-expansion "^1.1.7"
12241224

1225-
minimist@^1.1.0, minimist@^1.2.0, minimist@^1.2.6:
1225+
minimist@^1.1.0:
1226+
version "1.2.8"
1227+
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
1228+
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==
1229+
1230+
minimist@^1.2.0, minimist@^1.2.6:
12261231
version "1.2.7"
12271232
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.7.tgz#daa1c4d91f507390437c6a8bc01078e7000c4d18"
12281233
integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==

gitpod-web/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@
9797
"title": "%extendTimeout%",
9898
"enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true"
9999
},
100+
{
101+
"command": "gitpod.setWorkspaceTimeout",
102+
"title": "%configureTimeout%",
103+
"enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true"
104+
},
100105
{
101106
"command": "gitpod.takeSnapshot",
102107
"title": "%takeSnapshot%",

gitpod-web/package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"stopWorkspace": "Gitpod: Stop Workspace",
2323
"showReleaseNotes": "Gitpod: Show Release Notes",
2424
"upgradeSubscription": "Gitpod: Upgrade Subscription",
25-
"extendTimeout": "Gitpod: Extend Workspace Timeout",
25+
"extendTimeout": "Gitpod: Extend Workspace Timeout (180m)",
26+
"configureTimeout": "Gitpod: Configure Workspace Timeout",
2627
"takeSnapshot": "Gitpod: Share Workspace Snapshot",
2728
"shareWorkspace": "Gitpod: Share Running Workspace",
2829
"stopSharingWorkspace": "Gitpod: Stop Sharing Running Workspace",

0 commit comments

Comments
 (0)