Skip to content

Updated dialog warning handling for getExpiryTime #31

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
30 changes: 16 additions & 14 deletions patched-vscode/extensions/sagemaker-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function showWarningDialog() {
}
});

} else {
} else if (getExpiryTime(sagemakerCookie) == -1 || remainingTime <=0) {
// this means expiryTime cookie is either invalid or <0
signInError(sagemakerCookie);
}
Expand All @@ -71,19 +71,21 @@ function initialize(sagemakerCookie: SagemakerCookie) {
const currentTime = Date.now();
const timeToExpiry = getExpiryTime(sagemakerCookie) - currentTime;

if (timeToExpiry <= 0) {
signInError(sagemakerCookie);
} else if (timeToExpiry >= FIFTEEN_MINUTES_INTERVAL_MILLIS) {
const warningTime = timeToExpiry - FIFTEEN_MINUTES_INTERVAL_MILLIS;
setTimeout(() => {
showWarningDialog();
}, warningTime);
} else {
// If less than or equal to 15 minutes left, set a timer for the remaining time
const warningTime = timeToExpiry % FIVE_MINUTES_INTERVAL_MILLIS;
setTimeout(() => {
showWarningDialog();
}, warningTime);
if (getExpiryTime(sagemakerCookie) !== -1) {
if (timeToExpiry <= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious, why do you use getExpiryTime() in 74 and timeToExpiry in 75, 77, 84, etc? is there a difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getExpiryTime and timeToExpiry refer to different values

  • getExpiryTime - is the value of the local expiryTime set by Code Editor. When the cookie is present, it gives the UNIX time of the expiry time (8 hours ahead of app start up). When no cookie is present, it returns -1
  • timeToExpiry - is the UNIX expiry time - the current time (8 hours). We use this to compare against 15 min to provide the warning

signInError(sagemakerCookie);
} else if (timeToExpiry >= FIFTEEN_MINUTES_INTERVAL_MILLIS) {
const warningTime = timeToExpiry - FIFTEEN_MINUTES_INTERVAL_MILLIS;
setTimeout(() => {
showWarningDialog();
}, warningTime);
} else {
// If less than or equal to 15 minutes left, set a timer for the remaining time
const warningTime = timeToExpiry % FIVE_MINUTES_INTERVAL_MILLIS;
setTimeout(() => {
showWarningDialog();
}, warningTime);
}
}
}

Expand Down
32 changes: 17 additions & 15 deletions patches/sagemaker-extension.diff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension
===================================================================
--- /dev/null
+++ sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension.ts
@@ -0,0 +1,137 @@
@@ -0,0 +1,139 @@
+import * as vscode from 'vscode';
+import * as fs from 'fs';
+import { SessionWarning } from "./sessionWarning";
Expand Down Expand Up @@ -50,7 +50,7 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension
+ }
+ });
+
+ } else {
+ } else if (getExpiryTime(sagemakerCookie) == -1 || remainingTime <=0) {
+ // this means expiryTime cookie is either invalid or <0
+ signInError(sagemakerCookie);
+ }
Expand All @@ -76,19 +76,21 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension
+ const currentTime = Date.now();
+ const timeToExpiry = getExpiryTime(sagemakerCookie) - currentTime;
+
+ if (timeToExpiry <= 0) {
+ signInError(sagemakerCookie);
+ } else if (timeToExpiry >= FIFTEEN_MINUTES_INTERVAL_MILLIS) {
+ const warningTime = timeToExpiry - FIFTEEN_MINUTES_INTERVAL_MILLIS;
+ setTimeout(() => {
+ showWarningDialog();
+ }, warningTime);
+ } else {
+ // If less than or equal to 15 minutes left, set a timer for the remaining time
+ const warningTime = timeToExpiry % FIVE_MINUTES_INTERVAL_MILLIS;
+ setTimeout(() => {
+ showWarningDialog();
+ }, warningTime);
+ if (getExpiryTime(sagemakerCookie) !== -1) {
+ if (timeToExpiry <= 0) {
+ signInError(sagemakerCookie);
+ } else if (timeToExpiry >= FIFTEEN_MINUTES_INTERVAL_MILLIS) {
+ const warningTime = timeToExpiry - FIFTEEN_MINUTES_INTERVAL_MILLIS;
+ setTimeout(() => {
+ showWarningDialog();
+ }, warningTime);
+ } else {
+ // If less than or equal to 15 minutes left, set a timer for the remaining time
+ const warningTime = timeToExpiry % FIVE_MINUTES_INTERVAL_MILLIS;
+ setTimeout(() => {
+ showWarningDialog();
+ }, warningTime);
+ }
+ }
+}
+
Expand Down