Skip to content
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

Make server extension verification call during extension startup non-blocking #480

Merged
merged 7 commits into from
Feb 9, 2024
47 changes: 29 additions & 18 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { FileBrowser, IFileBrowserFactory } from '@jupyterlab/filebrowser';
import { ILauncher } from '@jupyterlab/launcher';
import { INotebookTracker } from '@jupyterlab/notebook';
import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
andrii-i marked this conversation as resolved.
Show resolved Hide resolved
import { Contents, ServerConnection } from '@jupyterlab/services';
import { ITranslator } from '@jupyterlab/translation';

Expand Down Expand Up @@ -46,6 +47,33 @@ type EventLog = {
timestamp: Date;
};

type verifyServExtProps = {
andrii-i marked this conversation as resolved.
Show resolved Hide resolved
api: SchedulerService;
trans: IRenderMime.TranslationBundle;
};

/**
* Call API to verify that the server extension is actually installed.
*/
async function verifyServExt(props: verifyServExtProps) {
andrii-i marked this conversation as resolved.
Show resolved Hide resolved
try {
await props.api.getJobs({ max_items: 0 });
andrii-i marked this conversation as resolved.
Show resolved Hide resolved
} catch (e: unknown) {
// in case of 404, show missing server extension dialog and return
if (
e instanceof ServerConnection.ResponseError &&
e.response.status === 404
) {
showDialog({
title: props.trans.__('Jupyter Scheduler server extension not found'),
body: SERVER_EXTENSION_404_JSX,
buttons: [Dialog.okButton()]
}).catch(console.warn);
return;
}
}
}

/**
* Initialization data for the jupyterlab-scheduler extension.
*/
Expand Down Expand Up @@ -150,24 +178,7 @@ async function activatePlugin(
): Promise<void> {
andrii-i marked this conversation as resolved.
Show resolved Hide resolved
const trans = translator.load('jupyterlab');
const api = new SchedulerService({});

// Call API to verify that the server extension is actually installed
try {
await api.getJobs({ max_items: 0 });
} catch (e: unknown) {
// in case of 404, show missing server extension dialog and return
if (
e instanceof ServerConnection.ResponseError &&
e.response.status === 404
) {
showDialog({
title: trans.__('Jupyter Scheduler server extension not found'),
body: SERVER_EXTENSION_404_JSX,
buttons: [Dialog.okButton()]
}).catch(console.warn);
return;
}
}
verifyServExt({ api, trans });

const { commands } = app;
const fileBrowserTracker = browserFactory.tracker;
Expand Down
Loading