-
-
Notifications
You must be signed in to change notification settings - Fork 36
Support server-side execution #279
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
Changes from 4 commits
2e47ca1
0d722e1
4d9cecc
161029e
8faaf59
6a33bb8
a0f4610
3aec4df
27c7083
dfe4256
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,11 @@ import { | |
EditorExtensionRegistry, | ||
IEditorExtensionRegistry | ||
} from '@jupyterlab/codemirror'; | ||
import { type MarkdownCell } from '@jupyterlab/cells'; | ||
import { INotebookCellExecutor, runCell } from '@jupyterlab/notebook'; | ||
import { WebSocketAwarenessProvider } from '@jupyter/docprovider'; | ||
import { SidePanel, usersIcon } from '@jupyterlab/ui-components'; | ||
import { URLExt } from '@jupyterlab/coreutils'; | ||
import { PageConfig, URLExt } from '@jupyterlab/coreutils'; | ||
import { ServerConnection } from '@jupyterlab/services'; | ||
import { IStateDB, StateDB } from '@jupyterlab/statedb'; | ||
import { ITranslator, nullTranslator } from '@jupyterlab/translation'; | ||
|
@@ -189,3 +191,63 @@ export const userEditorCursors: JupyterFrontEndPlugin<void> = { | |
}); | ||
} | ||
}; | ||
|
||
export const notebookCellExecutor: JupyterFrontEndPlugin<INotebookCellExecutor> = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something to consider: do we want this plugin in a separate package in the future so that when we split frontend and backend (#269) we can still load this plugin but not the others? This question does not block merging this PR in any way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But does it make sense to have server-side execution without collaboration? The former is based on the latter, so in my opinion they go together. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be sufficient to have the collaborative drive, right? |
||
{ | ||
id: '@jupyter/collaboration-extension:notebook-cell-executor', | ||
description: | ||
'Add notebook cell executor that uses REST API instead of kernel protocol over WebSocket.', | ||
autoStart: true, | ||
provides: INotebookCellExecutor, | ||
activate: (app: JupyterFrontEnd): INotebookCellExecutor => { | ||
if (PageConfig.getOption('serverSideExecution') === 'true') { | ||
davidbrochart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return Object.freeze({ runCell: runCellServerSide }); | ||
} | ||
return Object.freeze({ runCell }); | ||
} | ||
}; | ||
|
||
async function runCellServerSide({ | ||
cell, | ||
notebook, | ||
notebookConfig, | ||
onCellExecuted, | ||
onCellExecutionScheduled, | ||
sessionContext, | ||
sessionDialogs, | ||
translator | ||
}: INotebookCellExecutor.IRunCellOptions): Promise<boolean> { | ||
switch (cell.model.type) { | ||
case 'markdown': | ||
(cell as MarkdownCell).rendered = true; | ||
cell.inputHidden = false; | ||
onCellExecuted({ cell, success: true }); | ||
break; | ||
case 'code': { | ||
const kernelId = sessionContext?.session?.kernel?.id; | ||
const settings = ServerConnection.makeSettings(); | ||
const apiURL = URLExt.join( | ||
settings.baseUrl, | ||
`api/kernels/${kernelId}/execute` | ||
); | ||
const cellId = cell.model.sharedModel.getId(); | ||
const documentId = `json:notebook:${notebook.sharedModel.getState( | ||
'file_id' | ||
)}`; | ||
const body = `{"cell_id":"${cellId}","document_id":"${documentId}"}`; | ||
const init = { | ||
method: 'POST', | ||
body | ||
}; | ||
try { | ||
await ServerConnection.makeRequest(apiURL, init, settings); | ||
} catch (error: any) { | ||
throw new ServerConnection.NetworkError(error); | ||
} | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
return Promise.resolve(true); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.