Skip to content

Commit 52444b6

Browse files
Use configurable refreshInterval for polling
Use lumino polling class for polling server proxy apps Add schema to be able to configure refreshInterval
1 parent 7071318 commit 52444b6

File tree

4 files changed

+136
-58
lines changed

4 files changed

+136
-58
lines changed

labextension/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
},
5858
"jupyterlab": {
5959
"extension": true,
60+
"schemaDir": "schema",
6061
"outputDir": "../jupyter_server_proxy/labextension"
6162
}
6263
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"title": "Jupyter Server Proxy",
3+
"description": "Jupyter Server Proxy Manager settings",
4+
"properties": {
5+
"refreshInterval": {
6+
"type": "number",
7+
"title": "Auto-refresh rate",
8+
"description": "Time to wait (in ms) in between auto refreshes of server proxy applications",
9+
"default": 10000
10+
}
11+
},
12+
"additionalProperties": false,
13+
"type": "object"
14+
}

labextension/src/manager.ts

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
11
import { Signal, ISignal } from "@lumino/signaling";
2+
import { Poll } from '@lumino/polling';
3+
import { ISettingRegistry } from '@jupyterlab/settingregistry';
24
import { ServerConnection } from "@jupyterlab/services";
5+
import { TranslationBundle } from '@jupyterlab/translation';
36
import { listRunning, shutdown } from "./restapi";
47
import * as ServerProxyApp from "./serverproxy";
58

9+
// Default refresh interval (in milliseconds) for polling
10+
const DEFAULT_REFRESH_INTERVAL = 10000; // ms
11+
612
/**
713
* A server proxy manager.
814
*/
915
export class ServerProxyManager implements ServerProxyApp.IManager {
1016
/**
1117
* Construct a new server proxy manager.
1218
*/
13-
constructor(options: ServerProxyManager.IOptions = {}) {
14-
this.serverSettings =
15-
options.serverSettings || ServerConnection.makeSettings();
16-
this._refreshTimer = (setInterval as any)(() => {
17-
if (typeof document !== "undefined" && document.hidden) {
18-
return;
19+
constructor(trans: TranslationBundle, settings?: ISettingRegistry.ISettings) {
20+
this._trans = trans;
21+
this._settings = settings || null;
22+
this.serverSettings = ServerConnection.makeSettings();
23+
24+
const interval = settings?.get('refreshInterval').composite as number || DEFAULT_REFRESH_INTERVAL;
25+
26+
// Start polling with exponential backoff.
27+
this._proxyPoll = new Poll({
28+
factory: () => this._refreshRunning(),
29+
frequency: {
30+
interval: interval,
31+
backoff: true,
32+
max: 300 * 1000
1933
}
20-
this._refreshRunning();
21-
}, 10000);
34+
});
35+
36+
// Fire callback when settings are changed
37+
if (settings) {
38+
settings.changed.connect(this._onSettingsChange, this);
39+
this._onSettingsChange(settings);
40+
}
2241
}
2342

2443
/**
@@ -55,7 +74,8 @@ export class ServerProxyManager implements ServerProxyApp.IManager {
5574
return;
5675
}
5776
this._isDisposed = true;
58-
clearInterval(this._refreshTimer);
77+
this._proxyPoll.dispose();
78+
this._settings?.changed.disconnect(this._onSettingsChange, this);
5979
Signal.clearData(this);
6080
}
6181

@@ -72,7 +92,7 @@ export class ServerProxyManager implements ServerProxyApp.IManager {
7292
* Shut down a server proxy app by name.
7393
*/
7494
async shutdown(name: string): Promise<void> {
75-
await shutdown(name, this.serverSettings);
95+
await shutdown(name, this._trans, this.serverSettings);
7696
await this.refreshRunning();
7797
}
7898

@@ -87,7 +107,7 @@ export class ServerProxyManager implements ServerProxyApp.IManager {
87107

88108
// Shut down all models.
89109
await Promise.all(
90-
this._names.map((name) => shutdown(name, this.serverSettings)),
110+
this._names.map((name) => shutdown(name, this._trans, this.serverSettings)),
91111
);
92112

93113
// Update the list of models to clear out our state.
@@ -100,7 +120,8 @@ export class ServerProxyManager implements ServerProxyApp.IManager {
100120
* @returns A promise that with the list of running proxy apps.
101121
*/
102122
async refreshRunning(): Promise<void> {
103-
return this._refreshRunning();
123+
await this._proxyPoll.refresh();
124+
await this._proxyPoll.tick;
104125
}
105126

106127
/**
@@ -139,26 +160,45 @@ export class ServerProxyManager implements ServerProxyApp.IManager {
139160
this._runningChanged.emit(this._models);
140161
}
141162

163+
/**
164+
* Callback invoked upon a change to plugin settings.
165+
*
166+
* @private
167+
* @param settings - plugin settings
168+
*/
169+
private _onSettingsChange(settings: ISettingRegistry.ISettings) {
170+
this._proxyPoll.frequency = {
171+
...this._proxyPoll.frequency,
172+
interval: settings.composite.refreshInterval as number
173+
};
174+
}
175+
142176
private _names: string[] = [];
143177
private _models: ServerProxyApp.IModel[] = [];
144-
178+
private _proxyPoll: Poll;
179+
private _trans: TranslationBundle;
180+
private _settings: ISettingRegistry.ISettings | null;
145181
private _isDisposed = false;
146-
private _refreshTimer = -1;
147182
private _runningChanged = new Signal<this, ServerProxyApp.IModel[]>(this);
148183
private _connectionFailure = new Signal<this, Error>(this);
149184
}
150185

151-
/**
152-
* The namespace for `BaseManager` class statics.
153-
*/
154-
export namespace ServerProxyManager {
155-
/**
156-
* The options used to initialize a SessionManager.
157-
*/
158-
export interface IOptions {
159-
/**
160-
* The server settings for the manager.
161-
*/
162-
serverSettings?: ServerConnection.ISettings;
163-
}
164-
}
186+
// /**
187+
// * The namespace for `ServerProxyManager` class statics.
188+
// */
189+
// export namespace ServerProxyManager {
190+
// /**
191+
// * The options used to initialize a ServerProxyManager.
192+
// */
193+
// export interface IOptions {
194+
// /**
195+
// * The server settings for the manager.
196+
// */
197+
// serverSettings?: ServerConnection.ISettings;
198+
199+
// /**
200+
// * When the manager stops polling the API. Defaults to `when-hidden`.
201+
// */
202+
// standby?: Poll.Standby;
203+
// }
204+
// }

labextension/yarn.lock

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -696,10 +696,10 @@
696696
resolved "https://registry.npmjs.org/@types/estree/-/estree-1.0.0.tgz#5fb2e536c1ae9bf35366eed879e827fa59ca41c2"
697697
integrity sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==
698698

699-
"@types/estree@^0.0.51":
700-
version "0.0.51"
701-
resolved "https://registry.npmjs.org/@types/estree/-/estree-0.0.51.tgz#cfd70924a25a3fd32b218e5e420e6897e1ac4f40"
702-
integrity sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ==
699+
"@types/estree@^1.0.0":
700+
version "1.0.1"
701+
resolved "https://registry.npmjs.org/@types/estree/-/estree-1.0.1.tgz#aa22750962f3bf0e79d753d3cc067f010c95f194"
702+
integrity sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==
703703

704704
"@types/json-schema@*", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.7", "@types/json-schema@^7.0.8":
705705
version "7.0.11"
@@ -744,10 +744,33 @@
744744
"@types/source-list-map" "*"
745745
source-map "^0.6.1"
746746

747-
"@webassemblyjs/[email protected]":
748-
version "1.11.1"
749-
resolved "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7"
750-
integrity sha512-ukBh14qFLjxTQNTXocdyksN5QdM28S1CxHt2rdskFyL+xFV7VremuBLVbmCePj+URalXBENx/9Lm7lnhihtCSw==
747+
"@webassemblyjs/[email protected]", "@webassemblyjs/ast@^1.11.5":
748+
version "1.11.5"
749+
resolved "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.5.tgz#6e818036b94548c1fb53b754b5cae3c9b208281c"
750+
integrity sha512-LHY/GSAZZRpsNQH+/oHqhRQ5FT7eoULcBqgfyTB5nQHogFnK3/7QoN7dLnwSE/JkUAF0SrRuclT7ODqMFtWxxQ==
751+
dependencies:
752+
"@webassemblyjs/helper-numbers" "1.11.5"
753+
"@webassemblyjs/helper-wasm-bytecode" "1.11.5"
754+
755+
"@webassemblyjs/[email protected]":
756+
version "1.11.5"
757+
resolved "https://registry.npmjs.org/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.5.tgz#e85dfdb01cad16b812ff166b96806c050555f1b4"
758+
integrity sha512-1j1zTIC5EZOtCplMBG/IEwLtUojtwFVwdyVMbL/hwWqbzlQoJsWCOavrdnLkemwNoC/EOwtUFch3fuo+cbcXYQ==
759+
760+
"@webassemblyjs/[email protected]":
761+
version "1.11.5"
762+
resolved "https://registry.npmjs.org/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.5.tgz#1e82fa7958c681ddcf4eabef756ce09d49d442d1"
763+
integrity sha512-L65bDPmfpY0+yFrsgz8b6LhXmbbs38OnwDCf6NpnMUYqa+ENfE5Dq9E42ny0qz/PdR0LJyq/T5YijPnU8AXEpA==
764+
765+
"@webassemblyjs/[email protected]":
766+
version "1.11.5"
767+
resolved "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.5.tgz#91381652ea95bb38bbfd270702351c0c89d69fba"
768+
integrity sha512-fDKo1gstwFFSfacIeH5KfwzjykIE6ldh1iH9Y/8YkAZrhmu4TctqYjSh7t0K2VyDSXOZJ1MLhht/k9IvYGcIxg==
769+
770+
"@webassemblyjs/[email protected]":
771+
version "1.11.5"
772+
resolved "https://registry.npmjs.org/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.5.tgz#23380c910d56764957292839006fecbe05e135a9"
773+
integrity sha512-DhykHXM0ZABqfIGYNv93A5KKDw/+ywBFnuWybZZWcuzWHfbp21wUfRkbtz7dMGwGgT4iXjWuhRMA2Mzod6W4WA==
751774
dependencies:
752775
"@webassemblyjs/floating-point-hex-parser" "1.11.5"
753776
"@webassemblyjs/helper-api-error" "1.11.5"
@@ -1331,10 +1354,10 @@ encoding-down@^6.3.0:
13311354
level-codec "^9.0.0"
13321355
level-errors "^2.0.0"
13331356

1334-
enhanced-resolve@^5.10.0:
1335-
version "5.12.0"
1336-
resolved "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.12.0.tgz#300e1c90228f5b570c4d35babf263f6da7155634"
1337-
integrity sha512-QHTXI/sZQmko1cbDoNAa3mJ5qhWUUNAq3vR0/YiD379fWQrcfuoX1+HW2S0MTt7XmoPLapdaDKUtelUSPic7hQ==
1357+
enhanced-resolve@^5.13.0:
1358+
version "5.13.0"
1359+
resolved "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.13.0.tgz#26d1ecc448c02de997133217b5c1053f34a0a275"
1360+
integrity sha512-eyV8f0y1+bzyfh8xAwW/WTSZpLbjhqc4ne9eGSH4Zo2ejdyiNG9pU6mf9DG8a7+Auk6MFTlNOT4Y2y/9k8GKVg==
13381361
dependencies:
13391362
graceful-fs "^4.2.4"
13401363
tapable "^2.2.0"
@@ -1403,10 +1426,10 @@ es-abstract@^1.19.0, es-abstract@^1.20.4:
14031426
unbox-primitive "^1.0.2"
14041427
which-typed-array "^1.1.9"
14051428

1406-
es-module-lexer@^0.9.0:
1407-
version "0.9.3"
1408-
resolved "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-0.9.3.tgz#6f13db00cc38417137daf74366f535c8eb438f19"
1409-
integrity sha512-1HQ2M2sPtxwnvOvT1ZClHyQDiggdNjURWpY2we6aMKCQiUVxTmVs2UYPLIrD84sS+kMdUwfBSylbJPwNnBrnHQ==
1429+
es-module-lexer@^1.2.1:
1430+
version "1.2.1"
1431+
resolved "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.2.1.tgz#ba303831f63e6a394983fde2f97ad77b22324527"
1432+
integrity sha512-9978wrXM50Y4rTMmW5kXIC09ZdXQZqkE4mxhwkd8VbzsGkXGPgV4zWuqQJgCEzYngdo2dYDa0l8xhX4fkSwJSg==
14101433

14111434
es-set-tostringtag@^2.0.1:
14121435
version "2.0.1"
@@ -1565,7 +1588,7 @@ function.prototype.name@^1.1.5:
15651588
es-abstract "^1.19.0"
15661589
functions-have-names "^1.2.2"
15671590

1568-
functions-have-names@^1.2.2, functions-have-names@^1.2.3:
1591+
functions-have-names@^1.2.2:
15691592
version "1.2.3"
15701593
resolved "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834"
15711594
integrity sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==
@@ -2277,7 +2300,7 @@ moment@^2.24.0:
22772300
resolved "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108"
22782301
integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==
22792302

2280-
nanoid@^3.1.23, nanoid@^3.3.4:
2303+
nanoid@^3.1.23, nanoid@^3.3.6:
22812304
version "3.3.6"
22822305
resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c"
22832306
integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==
@@ -2540,7 +2563,7 @@ postcss@^8.2.15, postcss@^8.3.11:
25402563
resolved "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz#c639b719a57efc3187b13a1d765675485f4134f4"
25412564
integrity sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==
25422565
dependencies:
2543-
nanoid "^3.3.6"
2566+
nanoid "^3.3.4"
25442567
picocolors "^1.0.0"
25452568
source-map-js "^1.0.2"
25462569

@@ -2689,8 +2712,8 @@ regexp.prototype.flags@^1.2.0, regexp.prototype.flags@^1.4.3:
26892712
integrity sha512-0SutC3pNudRKgquxGoRGIz946MZVHqbNfPjBdxeOhBrdgDKlRoXmYLQN9xRbrR09ZXWeGAdPuif7egofn6v5LA==
26902713
dependencies:
26912714
call-bind "^1.0.2"
2692-
define-properties "^1.1.3"
2693-
functions-have-names "^1.2.2"
2715+
define-properties "^1.2.0"
2716+
functions-have-names "^1.2.3"
26942717

26952718
requires-port@^1.0.0:
26962719
version "1.0.0"
@@ -3047,7 +3070,7 @@ terser-webpack-plugin@^4.1.0:
30473070
terser "^5.3.4"
30483071
webpack-sources "^1.4.3"
30493072

3050-
terser-webpack-plugin@^5.1.3:
3073+
terser-webpack-plugin@^5.3.7:
30513074
version "5.3.7"
30523075
resolved "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.3.7.tgz#ef760632d24991760f339fe9290deb936ad1ffc7"
30533076
integrity sha512-AfKwIktyP7Cu50xNjXF/6Qb5lBNzYaWpU6YfoX3uZicTx0zTy0stDDCsvjDapKsSDvOeWo5MEq4TmdBy2cNoHw==
@@ -3306,16 +3329,16 @@ webpack@^5.41.1:
33063329
integrity sha512-gT5DP72KInmE/3azEaQrISjTvLYlSM0j1Ezhht/KLVkrqtv10JoP/RXhwmX/frrutOPuSq3o5Vq0ehR/4Vmd1g==
33073330
dependencies:
33083331
"@types/eslint-scope" "^3.7.3"
3309-
"@types/estree" "^1.0.0"
3310-
"@webassemblyjs/ast" "^1.11.5"
3311-
"@webassemblyjs/wasm-edit" "^1.11.5"
3312-
"@webassemblyjs/wasm-parser" "^1.11.5"
3332+
"@types/estree" "^0.0.51"
3333+
"@webassemblyjs/ast" "1.11.1"
3334+
"@webassemblyjs/wasm-edit" "1.11.1"
3335+
"@webassemblyjs/wasm-parser" "1.11.1"
33133336
acorn "^8.7.1"
33143337
acorn-import-assertions "^1.7.6"
33153338
browserslist "^4.14.5"
33163339
chrome-trace-event "^1.0.2"
3317-
enhanced-resolve "^5.13.0"
3318-
es-module-lexer "^1.2.1"
3340+
enhanced-resolve "^5.10.0"
3341+
es-module-lexer "^0.9.0"
33193342
eslint-scope "5.1.1"
33203343
events "^3.2.0"
33213344
glob-to-regexp "^0.4.1"
@@ -3324,9 +3347,9 @@ webpack@^5.41.1:
33243347
loader-runner "^4.2.0"
33253348
mime-types "^2.1.27"
33263349
neo-async "^2.6.2"
3327-
schema-utils "^3.1.2"
3350+
schema-utils "^3.1.0"
33283351
tapable "^2.1.1"
3329-
terser-webpack-plugin "^5.3.7"
3352+
terser-webpack-plugin "^5.1.3"
33303353
watchpack "^2.4.0"
33313354
webpack-sources "^3.2.3"
33323355

0 commit comments

Comments
 (0)