Skip to content

Commit 060011b

Browse files
andrii-idlqqq
andauthored
Make server extension verification call during extension startup non-blocking (#480)
* remove async call, make call sync, refactor into a separate function * don't use abbreviations in the verifyServerExtension function or type naming * Update src/index.tsx Co-authored-by: david qiu <[email protected]> * remove unused type * add @jupyterlab/rendermime-interfaces as a dependency * Remove async from activatePlugin function declaration (makes it not async) * set @jupyterlab/rendermime-interfaces version to ^3.8.0 to support all JLab >= 4 --------- Co-authored-by: david qiu <[email protected]>
1 parent 1b50f81 commit 060011b

File tree

3 files changed

+167
-20
lines changed

3 files changed

+167
-20
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"@jupyterlab/coreutils": "^6",
6363
"@jupyterlab/filebrowser": "^4",
6464
"@jupyterlab/launcher": "^4",
65+
"@jupyterlab/rendermime-interfaces": "^3.8.0",
6566
"@jupyterlab/services": "^7",
6667
"@jupyterlab/translation": "^4",
6768
"@jupyterlab/ui-components": "^4",

src/index.tsx

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { FileBrowser, IFileBrowserFactory } from '@jupyterlab/filebrowser';
1313
import { ILauncher } from '@jupyterlab/launcher';
1414
import { INotebookTracker } from '@jupyterlab/notebook';
15+
import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
1516
import { Contents, ServerConnection } from '@jupyterlab/services';
1617
import { ITranslator } from '@jupyterlab/translation';
1718

@@ -46,6 +47,31 @@ type EventLog = {
4647
timestamp: Date;
4748
};
4849

50+
/**
51+
* Call API to verify that the server extension is actually installed.
52+
*/
53+
async function verifyServerExtension(props: {
54+
api: SchedulerService;
55+
trans: IRenderMime.TranslationBundle;
56+
}) {
57+
try {
58+
await props.api.getJobs({ max_items: 0 });
59+
} catch (e: unknown) {
60+
// in case of 404, show missing server extension dialog and return
61+
if (
62+
e instanceof ServerConnection.ResponseError &&
63+
e.response.status === 404
64+
) {
65+
showDialog({
66+
title: props.trans.__('Jupyter Scheduler server extension not found'),
67+
body: SERVER_EXTENSION_404_JSX,
68+
buttons: [Dialog.okButton()]
69+
}).catch(console.warn);
70+
return;
71+
}
72+
}
73+
}
74+
4975
/**
5076
* Initialization data for the jupyterlab-scheduler extension.
5177
*/
@@ -138,7 +164,7 @@ function getDirectoryFromPath(path: string | null): string | null {
138164
return directories.join('/') + (directories.length > 0 ? '/' : '');
139165
}
140166

141-
async function activatePlugin(
167+
function activatePlugin(
142168
app: JupyterFrontEnd,
143169
browserFactory: IFileBrowserFactory,
144170
notebookTracker: INotebookTracker,
@@ -147,27 +173,10 @@ async function activatePlugin(
147173
advancedOptions: Scheduler.IAdvancedOptions,
148174
telemetryHandler: Scheduler.TelemetryHandler,
149175
launcher: ILauncher | null
150-
): Promise<void> {
176+
): void {
151177
const trans = translator.load('jupyterlab');
152178
const api = new SchedulerService({});
153-
154-
// Call API to verify that the server extension is actually installed
155-
try {
156-
await api.getJobs({ max_items: 0 });
157-
} catch (e: unknown) {
158-
// in case of 404, show missing server extension dialog and return
159-
if (
160-
e instanceof ServerConnection.ResponseError &&
161-
e.response.status === 404
162-
) {
163-
showDialog({
164-
title: trans.__('Jupyter Scheduler server extension not found'),
165-
body: SERVER_EXTENSION_404_JSX,
166-
buttons: [Dialog.okButton()]
167-
}).catch(console.warn);
168-
return;
169-
}
170-
}
179+
verifyServerExtension({ api, trans });
171180

172181
const { commands } = app;
173182
const fileBrowserTracker = browserFactory.tracker;

yarn.lock

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3775,6 +3775,16 @@ __metadata:
37753775
languageName: node
37763776
linkType: hard
37773777

3778+
"@jupyterlab/rendermime-interfaces@npm:^3.8.0":
3779+
version: 3.9.0
3780+
resolution: "@jupyterlab/rendermime-interfaces@npm:3.9.0"
3781+
dependencies:
3782+
"@lumino/coreutils": ^1.11.0 || ^2.1.2
3783+
"@lumino/widgets": ^1.37.2 || ^2.3.1
3784+
checksum: 462f5d034cd636caf9322245a50045ddaac55e05e056e7c6579e2db55088e724c8054a51a959aa284c44b108a9e0f0053707b50d6d8a9caed5825eeaf715b245
3785+
languageName: node
3786+
linkType: hard
3787+
37783788
"@jupyterlab/rendermime-interfaces@npm:^3.8.3":
37793789
version: 3.8.3
37803790
resolution: "@jupyterlab/rendermime-interfaces@npm:3.8.3"
@@ -3819,6 +3829,7 @@ __metadata:
38193829
"@jupyterlab/coreutils": ^6
38203830
"@jupyterlab/filebrowser": ^4
38213831
"@jupyterlab/launcher": ^4
3832+
"@jupyterlab/rendermime-interfaces": ^3.8.0
38223833
"@jupyterlab/services": ^7
38233834
"@jupyterlab/testutils": ^4
38243835
"@jupyterlab/translation": ^4
@@ -4179,6 +4190,13 @@ __metadata:
41794190
languageName: node
41804191
linkType: hard
41814192

4193+
"@lumino/algorithm@npm:^2.0.1":
4194+
version: 2.0.1
4195+
resolution: "@lumino/algorithm@npm:2.0.1"
4196+
checksum: cbf7fcf6ee6b785ea502cdfddc53d61f9d353dcb9659343511d5cd4b4030be2ff2ca4c08daec42f84417ab0318a3d9972a17319fa5231693e109ab112dcf8000
4197+
languageName: node
4198+
linkType: hard
4199+
41824200
"@lumino/application@npm:^2.1.1":
41834201
version: 2.2.0
41844202
resolution: "@lumino/application@npm:2.2.0"
@@ -4199,6 +4217,15 @@ __metadata:
41994217
languageName: node
42004218
linkType: hard
42014219

4220+
"@lumino/collections@npm:^2.0.1":
4221+
version: 2.0.1
4222+
resolution: "@lumino/collections@npm:2.0.1"
4223+
dependencies:
4224+
"@lumino/algorithm": ^2.0.1
4225+
checksum: 8a29b7973a388a33c5beda0819dcd2dc2aad51a8406dcfd4581b055a9f77a39dc5800f7a8b4ae3c0bb97ae7b56a7a869e2560ffb7a920a28e93b477ba05907d6
4226+
languageName: node
4227+
linkType: hard
4228+
42024229
"@lumino/commands@npm:^2.1.1, @lumino/commands@npm:^2.1.2":
42034230
version: 2.1.2
42044231
resolution: "@lumino/commands@npm:2.1.2"
@@ -4214,13 +4241,35 @@ __metadata:
42144241
languageName: node
42154242
linkType: hard
42164243

4244+
"@lumino/commands@npm:^2.2.0":
4245+
version: 2.2.0
4246+
resolution: "@lumino/commands@npm:2.2.0"
4247+
dependencies:
4248+
"@lumino/algorithm": ^2.0.1
4249+
"@lumino/coreutils": ^2.1.2
4250+
"@lumino/disposable": ^2.1.2
4251+
"@lumino/domutils": ^2.0.1
4252+
"@lumino/keyboard": ^2.0.1
4253+
"@lumino/signaling": ^2.1.2
4254+
"@lumino/virtualdom": ^2.0.1
4255+
checksum: 093e9715491e5cef24bc80665d64841417b400f2fa595f9b60832a3b6340c405c94a6aa276911944a2c46d79a6229f3cc087b73f50852bba25ece805abd0fae9
4256+
languageName: node
4257+
linkType: hard
4258+
42174259
"@lumino/coreutils@npm:^1.11.0 || ^2.0.0, @lumino/coreutils@npm:^1.11.0 || ^2.1.1, @lumino/coreutils@npm:^2, @lumino/coreutils@npm:^2.1.1":
42184260
version: 2.1.1
42194261
resolution: "@lumino/coreutils@npm:2.1.1"
42204262
checksum: dfdeb2b0282caae17b6c3edfebadf4ce7c75fc879fa60cacfef9b154412f4b35e4ffd95b1833b99d8dacb99aaaa04513570129ae2024c3f33e2677a01f0576ce
42214263
languageName: node
42224264
linkType: hard
42234265

4266+
"@lumino/coreutils@npm:^1.11.0 || ^2.1.2, @lumino/coreutils@npm:^2.1.2":
4267+
version: 2.1.2
4268+
resolution: "@lumino/coreutils@npm:2.1.2"
4269+
checksum: 7865317ac0676b448d108eb57ab5d8b2a17c101995c0f7a7106662d9fe6c859570104525f83ee3cda12ae2e326803372206d6f4c1f415a5b59e4158a7b81066f
4270+
languageName: node
4271+
linkType: hard
4272+
42244273
"@lumino/disposable@npm:^1.10.0 || ^2.0.0, @lumino/disposable@npm:^2.1.1":
42254274
version: 2.1.1
42264275
resolution: "@lumino/disposable@npm:2.1.1"
@@ -4230,13 +4279,29 @@ __metadata:
42304279
languageName: node
42314280
linkType: hard
42324281

4282+
"@lumino/disposable@npm:^2.1.2":
4283+
version: 2.1.2
4284+
resolution: "@lumino/disposable@npm:2.1.2"
4285+
dependencies:
4286+
"@lumino/signaling": ^2.1.2
4287+
checksum: ac2fb2bf18d0b2939fda454f3db248a0ff6e8a77b401e586d1caa9293b3318f808b93a117c9c3ac27cd17aab545aea83b49108d099b9b2f5503ae2a012fbc6e2
4288+
languageName: node
4289+
linkType: hard
4290+
42334291
"@lumino/domutils@npm:^2.0.0":
42344292
version: 2.0.0
42354293
resolution: "@lumino/domutils@npm:2.0.0"
42364294
checksum: 4a146bfc1006d5fd00ccecc61d9803965d269c15c48c892fd87216336ce967f0db91f31203c5616c83d260224cddf25af4abb6704a6770757d19e44068f690bf
42374295
languageName: node
42384296
linkType: hard
42394297

4298+
"@lumino/domutils@npm:^2.0.1":
4299+
version: 2.0.1
4300+
resolution: "@lumino/domutils@npm:2.0.1"
4301+
checksum: 61fa0ab226869dfbb763fc426790cf5a43b7d6f4cea1364c6dd56d61c44bff05eea188d33ff847449608ef58ed343161bee15c19b96f35410e4ee35815dc611a
4302+
languageName: node
4303+
linkType: hard
4304+
42404305
"@lumino/dragdrop@npm:^2.1.1, @lumino/dragdrop@npm:^2.1.2":
42414306
version: 2.1.2
42424307
resolution: "@lumino/dragdrop@npm:2.1.2"
@@ -4247,13 +4312,30 @@ __metadata:
42474312
languageName: node
42484313
linkType: hard
42494314

4315+
"@lumino/dragdrop@npm:^2.1.4":
4316+
version: 2.1.4
4317+
resolution: "@lumino/dragdrop@npm:2.1.4"
4318+
dependencies:
4319+
"@lumino/coreutils": ^2.1.2
4320+
"@lumino/disposable": ^2.1.2
4321+
checksum: 43d82484b13b38b612e7dfb424a840ed6a38d0db778af10655c4ba235c67b5b12db1683929b35a36ab2845f77466066dfd1ee25c1c273e8e175677eba9dc560d
4322+
languageName: node
4323+
linkType: hard
4324+
42504325
"@lumino/keyboard@npm:^2.0.0":
42514326
version: 2.0.0
42524327
resolution: "@lumino/keyboard@npm:2.0.0"
42534328
checksum: 3852ba51f437b1c1d7e552a0f844592a05e04dd5012070dc6e4384c58965d1ebf536c6875c1b7bae03cde3c715ddc36cd290992fcefc1a8c39094194f4689fdd
42544329
languageName: node
42554330
linkType: hard
42564331

4332+
"@lumino/keyboard@npm:^2.0.1":
4333+
version: 2.0.1
4334+
resolution: "@lumino/keyboard@npm:2.0.1"
4335+
checksum: cf33f13427a418efd7cc91061233321e860d5404f3d86397781028309bef86c8ad2d88276ffe335c1db0fe619bd9d1e60641c81f881696957a58703ee4652c3e
4336+
languageName: node
4337+
linkType: hard
4338+
42574339
"@lumino/messaging@npm:^2.0.0":
42584340
version: 2.0.0
42594341
resolution: "@lumino/messaging@npm:2.0.0"
@@ -4264,6 +4346,16 @@ __metadata:
42644346
languageName: node
42654347
linkType: hard
42664348

4349+
"@lumino/messaging@npm:^2.0.1":
4350+
version: 2.0.1
4351+
resolution: "@lumino/messaging@npm:2.0.1"
4352+
dependencies:
4353+
"@lumino/algorithm": ^2.0.1
4354+
"@lumino/collections": ^2.0.1
4355+
checksum: 964c4651c374b17452b4252b7d71500b32d2ecd87c192fc5bcf5d3bd1070661d78d07edcac8eca7d1d6fd50aa25992505485e1296d6dd995691b8e349b652045
4356+
languageName: node
4357+
linkType: hard
4358+
42674359
"@lumino/polling@npm:^2, @lumino/polling@npm:^2.1.1":
42684360
version: 2.1.1
42694361
resolution: "@lumino/polling@npm:2.1.1"
@@ -4282,6 +4374,13 @@ __metadata:
42824374
languageName: node
42834375
linkType: hard
42844376

4377+
"@lumino/properties@npm:^2.0.1":
4378+
version: 2.0.1
4379+
resolution: "@lumino/properties@npm:2.0.1"
4380+
checksum: c50173a935148cc4148fdaea119df1d323ee004ae16ab666800388d27e9730345629662d85f25591683329b39f0cdae60ee8c94e8943b4d0ef7d7370a38128d6
4381+
languageName: node
4382+
linkType: hard
4383+
42854384
"@lumino/signaling@npm:^1.10.0 || ^2.0.0, @lumino/signaling@npm:^2, @lumino/signaling@npm:^2.1.1":
42864385
version: 2.1.1
42874386
resolution: "@lumino/signaling@npm:2.1.1"
@@ -4292,6 +4391,16 @@ __metadata:
42924391
languageName: node
42934392
linkType: hard
42944393

4394+
"@lumino/signaling@npm:^2.1.2":
4395+
version: 2.1.2
4396+
resolution: "@lumino/signaling@npm:2.1.2"
4397+
dependencies:
4398+
"@lumino/algorithm": ^2.0.1
4399+
"@lumino/coreutils": ^2.1.2
4400+
checksum: ad7d7153db57980da899c43e412e6130316ef30b231a70250e7af49058db16cadb018c1417a2ea8083d83c48623cfe6b705fa82bf10216b1a8949aed9f4aca4e
4401+
languageName: node
4402+
linkType: hard
4403+
42954404
"@lumino/virtualdom@npm:^2.0.0":
42964405
version: 2.0.0
42974406
resolution: "@lumino/virtualdom@npm:2.0.0"
@@ -4301,6 +4410,15 @@ __metadata:
43014410
languageName: node
43024411
linkType: hard
43034412

4413+
"@lumino/virtualdom@npm:^2.0.1":
4414+
version: 2.0.1
4415+
resolution: "@lumino/virtualdom@npm:2.0.1"
4416+
dependencies:
4417+
"@lumino/algorithm": ^2.0.1
4418+
checksum: cf59b6f15b430e13e9e657b7a0619b9056cd9ea7b2a87f407391d071c501b77403c302b6a66dca510382045e75b2e3fe551630bb391f1c6b33678057d4bec164
4419+
languageName: node
4420+
linkType: hard
4421+
43044422
"@lumino/widgets@npm:^1.37.2 || ^2.1.1, @lumino/widgets@npm:^2, @lumino/widgets@npm:^2.1.1, @lumino/widgets@npm:^2.2.0":
43054423
version: 2.2.0
43064424
resolution: "@lumino/widgets@npm:2.2.0"
@@ -4320,6 +4438,25 @@ __metadata:
43204438
languageName: node
43214439
linkType: hard
43224440

4441+
"@lumino/widgets@npm:^1.37.2 || ^2.3.1":
4442+
version: 2.3.1
4443+
resolution: "@lumino/widgets@npm:2.3.1"
4444+
dependencies:
4445+
"@lumino/algorithm": ^2.0.1
4446+
"@lumino/commands": ^2.2.0
4447+
"@lumino/coreutils": ^2.1.2
4448+
"@lumino/disposable": ^2.1.2
4449+
"@lumino/domutils": ^2.0.1
4450+
"@lumino/dragdrop": ^2.1.4
4451+
"@lumino/keyboard": ^2.0.1
4452+
"@lumino/messaging": ^2.0.1
4453+
"@lumino/properties": ^2.0.1
4454+
"@lumino/signaling": ^2.1.2
4455+
"@lumino/virtualdom": ^2.0.1
4456+
checksum: ba7b8f8839c1cd2a41dbda13281094eb6981a270cccf4f25a0cf83686dcc526a2d8044a20204317630bb7dd4a04d65361408c7623a921549c781afca84b91c67
4457+
languageName: node
4458+
linkType: hard
4459+
43234460
"@mui/base@npm:5.0.0-alpha.98":
43244461
version: 5.0.0-alpha.98
43254462
resolution: "@mui/base@npm:5.0.0-alpha.98"

0 commit comments

Comments
 (0)