From c23895a69c0ab6f63e63bc125be07a71dad82e12 Mon Sep 17 00:00:00 2001 From: Sigmar Stefansson Date: Mon, 12 Feb 2024 09:25:39 +0000 Subject: [PATCH] move ocean specific code to 4.1.0 --- dev_mode/package.json | 2 +- jupyterlab/semver.py | 3 ++ jupyterlab/staging/package.json | 2 +- packages/services/src/kernel/default.ts | 2 +- packages/services/src/session/restapi.ts | 46 ++++++++++++++++++++---- 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/dev_mode/package.json b/dev_mode/package.json index 54ea50b3a5a7..7f6a42a305ca 100644 --- a/dev_mode/package.json +++ b/dev_mode/package.json @@ -97,7 +97,7 @@ "@jupyterlab/rendermime-interfaces": "~3.9.0", "@jupyterlab/running": "~4.1.0", "@jupyterlab/running-extension": "~4.1.0", - "@jupyterlab/services": "~7.1.0", + "@jupyterlab/services": "../packages/services", "@jupyterlab/settingeditor": "~4.1.0", "@jupyterlab/settingeditor-extension": "~4.1.0", "@jupyterlab/settingregistry": "~4.1.0", diff --git a/jupyterlab/semver.py b/jupyterlab/semver.py index e48583c0a21f..6a6ce6bc96ad 100644 --- a/jupyterlab/semver.py +++ b/jupyterlab/semver.py @@ -747,6 +747,9 @@ def make_range(range_, loose): class Range: def __init__(self, range_, loose): + if "/services" in range_: + range_ = "~7.1.0" + self.loose = loose # First, split based on boolean or || self.raw = range_ diff --git a/jupyterlab/staging/package.json b/jupyterlab/staging/package.json index 35c98a93db27..c662d0922b1b 100644 --- a/jupyterlab/staging/package.json +++ b/jupyterlab/staging/package.json @@ -97,7 +97,7 @@ "@jupyterlab/rendermime-interfaces": "~3.9.0", "@jupyterlab/running": "~4.1.0", "@jupyterlab/running-extension": "~4.1.0", - "@jupyterlab/services": "~7.1.0", + "@jupyterlab/services": "../../packages/services", "@jupyterlab/settingeditor": "~4.1.0", "@jupyterlab/settingeditor-extension": "~4.1.0", "@jupyterlab/settingregistry": "~4.1.0", diff --git a/packages/services/src/kernel/default.ts b/packages/services/src/kernel/default.ts index 7ce48b4b138b..4b5877f4d52e 100644 --- a/packages/services/src/kernel/default.ts +++ b/packages/services/src/kernel/default.ts @@ -1235,7 +1235,7 @@ export class KernelConnection implements Kernel.IKernelConnection { /** * Create the kernel websocket connection and add socket status handlers. */ - private _createSocket = (useProtocols = true) => { + private _createSocket = (useProtocols = false) => { this._errorIfDisposed(); // Make sure the socket is clear diff --git a/packages/services/src/session/restapi.ts b/packages/services/src/session/restapi.ts index 6198c2829620..def827e48047 100644 --- a/packages/services/src/session/restapi.ts +++ b/packages/services/src/session/restapi.ts @@ -96,6 +96,9 @@ export async function getSessionModel( return data; } +function sleep(ms: number | undefined) { + return new Promise(resolve => setTimeout(resolve, ms)); +} /** * Create a new session, or return an existing session if the session path * already exists. @@ -105,16 +108,45 @@ export async function startSession( settings: ServerConnection.ISettings = ServerConnection.makeSettings() ): Promise { const url = URLExt.join(settings.baseUrl, SESSION_SERVICE_URL); - const init = { + const body = JSON.stringify(options); + const bodyjson = JSON.parse(body); + bodyjson['id'] = ''; + let init = { method: 'POST', - body: JSON.stringify(options) + body: JSON.stringify(bodyjson) }; - const response = await ServerConnection.makeRequest(url, init, settings); - if (response.status !== 201) { - const err = await ServerConnection.ResponseError.create(response); - throw err; + let data = { id: '', execution_state: 'waiting' }; + let count = 0; + while (count++ < 300) { + const response = await ServerConnection.makeRequest(url, init, settings); + if (response.status !== 201) { + throw await ServerConnection.ResponseError.create(response); + } + data = await response.json(); + if (data.execution_state != 'waiting') { + console.log( + 'Kernel started in session ' + data.id + ' after ' + count + ' seconds' + ); + break; + } else { + bodyjson['id'] = data.id; + init = { + method: 'POST', + body: JSON.stringify(bodyjson) + }; + await sleep(2000); + console.log( + 'Waiting for kernel in session ' + + data.id + + ' for ' + + 2 * count + + ' seconds' + ); + } + } + if (count >= 300) { + throw new Error('10 minute timeout waiting for kernel to start'); } - const data = await response.json(); updateLegacySessionModel(data); validateModel(data); return data;