Skip to content

Commit bc9f989

Browse files
committed
Fixed Alerts using setTimeout instead of setInterval
1 parent 97dbfdf commit bc9f989

File tree

8 files changed

+30
-28
lines changed

8 files changed

+30
-28
lines changed

labextension/sagemaker_studio_docker_ui/package/lib/components/GetContainers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export async function getContainers(instance){
2121
instance.addAlert({
2222
type: "error",
2323
message: `Error checking containers list! "`,
24+
wait: 5000
2425
});
2526
contexts = []
2627
};

labextension/sagemaker_studio_docker_ui/package/lib/components/GetContexts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export async function getContexts(instance){
2525
instance.addAlert({
2626
type: "error",
2727
message: `Error checking contexts list! "`,
28+
wait: 5000
2829
});
2930
contexts = []
3031
};

labextension/sagemaker_studio_docker_ui/package/lib/components/GetImages.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export async function getImages(instance){
2121
instance.addAlert({
2222
type: "error",
2323
message: `Error checking images list! "`,
24+
wait: 5000
2425
});
2526
images = []
2627
};

labextension/sagemaker_studio_docker_ui/package/lib/components/SdockerPanel.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,22 @@ export class SdockerPanel extends React.Component {
4444
this.handleSubmit = async () => {
4545
console.log("Creating new docker host");
4646
const dataToSend = { instance_type: this.state.INSTANCE_TYPE };
47-
this.clearAlerts();
4847
try {
4948
const reply = await requestAPIServer("create_host", {
5049
body: JSON.stringify(dataToSend),
5150
method: "POST",
5251
});
5352
console.log(reply);
54-
this.addAlert({ message: `Creating new docker host - instance will appear once it is healthy, might take few minutes` });
53+
this.addAlert({ message: `Creating new docker host - instance will appear once it is healthy, might take few minutes`, wait 15000 });
5554
}
5655
catch (reason) {
5756
console.error(`Error on POST /docker-host/create_host ${dataToSend}.\n${reason}`);
5857
this.addAlert({
5958
type: "error",
6059
message: `Error creating new docker host! "`,
60+
wait: 5000
6161
});
6262
}
63-
setInterval(() => this.clearAlerts(), 5000);
6463
};
6564
this.alertKey = 0;
6665
this.state = {
@@ -197,9 +196,7 @@ export class SdockerPanel extends React.Component {
197196
const key = this.alertKey++;
198197
const keyedAlert = Object.assign(Object.assign({}, alert), { key: `alert-${key}` });
199198
this.setState({ alerts: [keyedAlert] });
200-
}
201-
clearAlerts() {
202-
this.setState({ alerts: [] });
199+
setTimeout(() => { this.setState({ alerts: [] }) }, alert.wait );
203200
}
204201
saveState() {
205202
const state = {

labextension/sagemaker_studio_docker_ui/package/lib/components/SwitchContext.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ async function switchContext(instance, instanceType, instanceId){
1111
method: 'POST',
1212
});
1313
console.log(reply);
14-
instance.addAlert({message: `Switching to host ${instanceId}`});
14+
instance.addAlert({message: `Switching to host ${instanceId}`, wait: 5000});
1515
}
1616
catch (reason) {
1717
console.error(`Error on POST /docker-host/switch_context ${JSON.stringify(dataToSend)}.\n${reason}`);
1818
instance.addAlert({
1919
type: "error",
2020
message: `Error checking switching context! "`,
21+
wait: 5000
2122
});
2223
};
2324
}

labextension/sagemaker_studio_docker_ui/package/lib/components/TerminateHost.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ async function terminateHost(instance, instanceId){
1111
method: 'POST',
1212
});
1313
console.log(reply);
14-
instance.addAlert({message: `Terminating host ${instanceId}`});
14+
instance.addAlert({message: `Terminating host ${instanceId}`, wait: 5000 });
1515
}
1616
catch (reason) {
1717
console.error(`Error on POST /docker-host/terminate_host ${JSON.stringify(dataToSend)}.\n${reason}`);
1818
instance.addAlert({
1919
type: "error",
2020
message: `Error terminating host! "`,
21+
wait: 5000
2122
});
2223
};
2324
}

labextension/sagemaker_studio_docker_ui/package/lib/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { ILayoutRestorer } from '@jupyterlab/application';
22
import { IStateDB } from '@jupyterlab/coreutils';
3-
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
4-
import { IIconRegistry } from '@jupyterlab/ui-components';
53
import { requestAPIServer } from './sagemaker-studio-docker-ui';
64
import { SdockerWidget } from './widgets/SdockerWidget';
75
/**
@@ -10,8 +8,8 @@ import { SdockerWidget } from './widgets/SdockerWidget';
108
const extension = {
119
id: 'sagemaker-studio-docker-ui',
1210
autoStart: true,
13-
requires: [ILayoutRestorer, IIconRegistry, IRenderMimeRegistry, IStateDB],
14-
activate: async (app, restorer, iconRegistry, rendermime, stateDB) => {
11+
requires: [ILayoutRestorer, IStateDB],
12+
activate: async (app, restorer, stateDB) => {
1513
console.log('JupyterLab extension sagemaker-studio-docker-ui is activated!');
1614
let INSTANCE_TYPE = 'm5.large';
1715
const KEY = 'sagemaker-studio-docker-ui:settings:data';

setup.sh

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22

33
set -eux
44

5-
cd ~/sagemaker-studio-docker-ui-extension/labextension/sagemaker_studio_docker_ui/
6-
7-
tar -czvf sagemaker_studio_docker_ui-0.1.0.tgz --exclude=.* --exclude=__py* package/
8-
9-
mkdir -p labextension
10-
11-
mv sagemaker_studio_docker_ui-0.1.0.tgz labextension/
12-
13-
cd
14-
15-
tar -czvf sagemaker_studio_docker_ui-0.1.0.tar.gz --exclude=.* sagemaker-studio-docker-ui-extension/
16-
17-
pip install sagemaker_studio_docker_ui-0.1.0.tar.gz
18-
5+
# Before installing extension
6+
export AWS_SAGEMAKER_JUPYTERSERVER_IMAGE="${AWS_SAGEMAKER_JUPYTERSERVER_IMAGE:-'jupyter-server'}"
7+
if [ "$AWS_SAGEMAKER_JUPYTERSERVER_IMAGE" = "jupyter-server-3" ]
8+
then
9+
eval "$(conda shell.bash hook)"
10+
conda activate studio
11+
cd ~/sagemaker-studio-docker-ui-extension/labextension/sagemaker_studio_docker_ui/
12+
tar -czvf sagemaker_studio_docker_ui_component.tgz --exclude=.* --exclude=__py* package/
13+
mkdir -p labextension
14+
mv sagemaker_studio_docker_ui_component.tgz labextension/
15+
cd
16+
tar -czvf sagemaker_studio_docker_ui_extension.tar.gz --exclude=.* sagemaker-studio-docker-ui-extension/
17+
PACKAGE=sagemaker_studio_docker_ui_extension.tar.gz
18+
else
19+
PACKAGE=https://github.com/aws-samples/sagemaker-studio-docker-ui-extension/releases/download/v0.1.0/sagemaker_studio_docker_ui_extension.tar.gz
20+
fi;
21+
22+
pip install $PACKAGE
1923
jlpm config set cache-folder /tmp/yarncache
20-
2124
jupyter lab build --debug --minimize=False
22-
2325
nohup supervisorctl -c /etc/supervisor/conf.d/supervisord.conf restart jupyterlabserver

0 commit comments

Comments
 (0)