Skip to content

Commit

Permalink
🚦Slider server running status (#2601)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrekker authored Jul 16, 2023
1 parent fe236a0 commit a5c3227
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
47 changes: 46 additions & 1 deletion frontend/common/SliderServerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ const assert_response_ok = (/** @type {Response} */ r) => (r.ok ? r : Promise.re

const actions_to_keep = ["get_published_object"]

const get_start = (graph, v) => Object.values(graph).find((node) => Object.keys(node.downstream_cells_map).includes(v))?.cell_id
const get_starts = (graph, vars) => new Set([...vars].map((v) => get_start(graph, v)))
const recursive_dependencies = (graph, starts) => {
const deps = new Set(starts)
const ends = [...starts]
while (ends.length > 0) {
const node = ends.splice(0, 1)[0]
_.flatten(Object.values(graph[node].downstream_cells_map)).forEach((child) => {
if (!deps.has(child)) {
ends.push(child)
deps.add(child)
}
})
}
return deps
}

export const nothing_actions = ({ actions }) =>
Object.fromEntries(
Object.entries(actions).map(([k, v]) => [
Expand All @@ -23,6 +40,12 @@ export const nothing_actions = ({ actions }) =>
)

export const slider_server_actions = ({ setStatePromise, launch_params, actions, get_original_state, get_current_state, apply_notebook_patches }) => {
setStatePromise(
immer((state) => {
state.slider_server.connecting = true
})
)

const notebookfile_hash = fetch(new Request(launch_params.notebookfile, { integrity: launch_params.notebookfile_integrity }))
.then(assert_response_ok)
.then((r) => r.arrayBuffer())
Expand All @@ -36,7 +59,15 @@ export const slider_server_actions = ({ setStatePromise, launch_params, actions,
.then((r) => r.arrayBuffer())
.then((b) => unpack(new Uint8Array(b)))

bond_connections.then((x) => console.log("Bond connections:", x))
bond_connections.then((x) => {
console.log("Bond connections:", x)
setStatePromise(
immer((state) => {
state.slider_server.connecting = false
state.slider_server.interactive = Object.keys(x).length > 0
})
)
})

const mybonds = {}
const bonds_to_set = {
Expand All @@ -47,6 +78,16 @@ export const slider_server_actions = ({ setStatePromise, launch_params, actions,
const hash = await notebookfile_hash
const graph = await bond_connections

// compute dependencies and update cell running statuses
const dep_graph = get_current_state().cell_dependencies
const starts = get_starts(dep_graph, bonds_to_set.current)
const running_cells = [...recursive_dependencies(dep_graph, starts)]
await setStatePromise(
immer((state) => {
running_cells.forEach((cell_id) => (state.notebook.cell_results[cell_id][starts.has(cell_id) ? "running" : "queued"] = true))
})
)

if (bonds_to_set.current.size > 0) {
const to_send = new Set(bonds_to_set.current)
bonds_to_set.current.forEach((varname) => (graph[varname] ?? []).forEach((x) => to_send.add(x)))
Expand Down Expand Up @@ -88,6 +129,10 @@ export const slider_server_actions = ({ setStatePromise, launch_params, actions,
ids_of_cells_that_ran.forEach((id) => {
state.cell_results[id] = original.cell_results[id]
})
running_cells.forEach((id) => {
state.cell_results[id].queued = false
state.cell_results[id].running = false
})
})(get_current_state())
)
} catch (e) {
Expand Down
5 changes: 5 additions & 0 deletions frontend/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ export class Editor extends Component {

is_recording: false,
recording_waiting_to_start: false,

slider_server: {
connecting: false,
interactive: false,
},
}

this.setStatePromise = (fn) => new Promise((r) => this.setState(fn, r))
Expand Down

0 comments on commit a5c3227

Please sign in to comment.