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

added pseudo kernel handling in updateSession #29

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/services/src/session/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class SessionConnection implements Session.ISessionConnection {
* Dispose of the resources held by the session.
*/
dispose(): void {
if (this.isDisposed) {
if (this._updating || this.isDisposed) {
return;
}
this._isDisposed = true;
Expand Down Expand Up @@ -391,10 +391,16 @@ export class SessionConnection implements Session.ISessionConnection {
private async _patch(
body: DeepPartial<Session.IModel>
): Promise<Session.IModel> {
const model = await updateSession(
{ ...body, id: this._id },
this.serverSettings
);
this._updating = true;
let model: Session.IModel;
try {
model = await updateSession(
{...body, id: this._id},
this.serverSettings
);
} finally {
this._updating = false;
}
this.update(model);
return model;
}
Expand Down Expand Up @@ -422,6 +428,7 @@ export class SessionConnection implements Session.ISessionConnection {
private _clientId: string;
private _kernel: Kernel.IKernelConnection | null = null;
private _isDisposed = false;
private _updating = false;
private _disposed = new Signal<this, void>(this);
private _kernelChanged = new Signal<
this,
Expand Down
41 changes: 35 additions & 6 deletions packages/services/src/session/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,45 @@ export async function updateSession(
settings: ServerConnection.ISettings = ServerConnection.makeSettings()
): Promise<Session.IModel> {
const url = getSessionUrl(settings.baseUrl, model.id);
const init = {
const body = JSON.stringify(model);
const bodyjson = JSON.parse(body);
bodyjson['id'] = '';
let init = {
method: 'PATCH',
body: JSON.stringify(model)
};
const response = await ServerConnection.makeRequest(url, init, settings);
if (response.status !== 200) {
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 !== 200 && response.status !== 201) {
throw await ServerConnection.ResponseError.create(response);
}
data = await response.json();
if (data.execution_state != 'waiting') {
console.log(
'Kernel started in update session ' + data.id + ' after ' + count + ' seconds'
);
break;
} else {
bodyjson['id'] = data.id;
init = {
method: 'PATCH',
body: JSON.stringify(bodyjson)
};
await sleep(2000);
console.log(
'Waiting for kernel in update session ' +
data.id +
' for ' +
2 * count +
' seconds'
);
}
}
if (count >= 300) {
throw new Error('10 minute timeout waiting for updated kernel to start');
}
const data = await response.json();
updateLegacySessionModel(data);
validateModel(data);
return data;
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies = [
"ipykernel>=6.5.0",
"jinja2>=3.0.3",
"jupyter_core",
"jupyter_server@git+https://github.com/spotinst/jupyter_server.git@ocean-spark-jupyterserver-jlab",
"jupyter_server@git+https://github.com/spotinst/jupyter_server.git@ddf0b98",
"jupyter-lsp>=2.0.0",
"jupyterlab_server>=2.27.1,<3",
"notebook_shim>=0.2",
Expand Down
Loading