Skip to content

Commit

Permalink
Fixes: Workbench not editable for a little while after it's stopped (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcreasy committed Aug 17, 2023
1 parent d61c590 commit 8b97fdf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
14 changes: 7 additions & 7 deletions frontend/src/pages/projects/notebook/NotebookStatusToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { computeNotebooksTolerations } from '~/utilities/tolerations';
import { useAppContext } from '~/app/AppContext';
import { currentlyHasPipelines } from '~/concepts/pipelines/elyra/utils';
import { NotebookState } from './types';
import useRefreshNotebookUntilStart from './useRefreshNotebookUntilStart';
import useRefreshNotebookUntilStartOrStop from './useRefreshNotebookUntilStartOrStop';
import StopNotebookConfirmModal from './StopNotebookConfirmModal';
import useStopNotebookModalAvailability from './useStopNotebookModalAvailability';
import NotebookStatusText from './NotebookStatusText';
Expand All @@ -24,12 +24,12 @@ const NotebookStatusToggle: React.FC<NotebookStatusToggleProps> = ({
doListen,
enablePipelines,
}) => {
const { notebook, isStarting, isRunning, refresh } = notebookState;
const { notebook, isStarting, isRunning, isStopping, refresh } = notebookState;
const gpuNumber = useNotebookGPUNumber(notebook);
const { size } = useNotebookDeploymentSize(notebook);
const [isOpenConfirm, setOpenConfirm] = React.useState(false);
const [inProgress, setInProgress] = React.useState(false);
const listenToNotebookStart = useRefreshNotebookUntilStart(notebookState, doListen);
const listenToNotebookStart = useRefreshNotebookUntilStartOrStop(notebookState, doListen);
const [dontShowModalValue] = useStopNotebookModalAvailability();
const { dashboardConfig } = useAppContext();
const notebookName = notebook.metadata.name;
Expand All @@ -42,8 +42,8 @@ const NotebookStatusToggle: React.FC<NotebookStatusToggleProps> = ({
let label = '';
if (isStarting) {
label = 'Starting...';
} else if (inProgress) {
label = isChecked ? 'Starting...' : 'Stopping...';
} else if (isStopping) {
label = 'Stopping...';
} else {
label = isRunning ? 'Running' : 'Stopped';
}
Expand Down Expand Up @@ -72,7 +72,7 @@ const NotebookStatusToggle: React.FC<NotebookStatusToggleProps> = ({
setInProgress(true);
stopNotebook(notebookName, notebookNamespace).then(() => {
refresh().then(() => setInProgress(false));
listenToNotebookStart(false);
listenToNotebookStart(true, true);
});
}, [notebookName, notebookNamespace, refresh, listenToNotebookStart, fireNotebookTrackingEvent]);

Expand All @@ -82,7 +82,7 @@ const NotebookStatusToggle: React.FC<NotebookStatusToggleProps> = ({
<FlexItem>
<Switch
aria-label={label}
isDisabled={inProgress}
isDisabled={inProgress || isStopping}
id={`${notebookName}-${notebookNamespace}`}
isChecked={isChecked}
onClick={() => {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/projects/notebook/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const getNotebooksStatus = async (
notebook: notebooks[i],
isStarting: !isStopped && !podsReady,
isRunning: !isStopped && podsReady,
isStopping: isStopped && podsReady,
isStopped: isStopped && !podsReady,
runningPodUid: pods[0]?.metadata?.uid || '',
},
];
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/projects/notebook/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export type NotebookDataState = {
notebook: NotebookKind;
isStarting: boolean;
isRunning: boolean;
isStopping: boolean;
isStopped: boolean;
runningPodUid: string;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ import * as React from 'react';
import { FAST_POLL_INTERVAL } from '~/utilities/const';
import { NotebookState } from './types';

const useRefreshNotebookUntilStart = (
const useRefreshNotebookUntilStartOrStop = (
notebookState: NotebookState,
doListen: boolean,
): ((listen: boolean) => void) => {
): ((listen: boolean, stop?: boolean) => void) => {
const [watchingForNotebook, setWatchingForNotebook] = React.useState(false);
const [watchingForStop, setWatchingForStop] = React.useState(false);
const lastNotebookState = React.useRef<NotebookState>(notebookState);
lastNotebookState.current = notebookState;

React.useEffect(() => {
let interval: ReturnType<typeof setInterval>;
if (watchingForNotebook && doListen) {
interval = setInterval(() => {
const { isRunning, refresh } = lastNotebookState.current;
if (!isRunning) {
const { isRunning, isStopped, refresh } = lastNotebookState.current;
const condition = watchingForStop ? isStopped : isRunning;
if (!condition) {
refresh().catch((e) => {
/* eslint-disable-next-line no-console */
console.error('Error refreshing, stopping notebook refresh', e);
Expand All @@ -30,11 +32,15 @@ const useRefreshNotebookUntilStart = (
return () => {
clearInterval(interval);
};
}, [watchingForNotebook, doListen]);
}, [watchingForStop, watchingForNotebook, doListen]);

return React.useCallback((listen: boolean) => {
/**
* The second parameter allows listening for the notebook to be stopped. Default is to wait until started.
*/
return React.useCallback((listen: boolean, waitForStop = false) => {
setWatchingForStop(waitForStop);
setWatchingForNotebook(listen);
}, []);
};

export default useRefreshNotebookUntilStart;
export default useRefreshNotebookUntilStartOrStop;
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const NotebookTableRow: React.FC<NotebookTableRowProps> = ({
<ActionsColumn
items={[
{
isDisabled: obj.isStarting,
isDisabled: obj.isStarting || obj.isStopping,
title: 'Edit workbench',
onClick: () => {
navigate(
Expand Down

0 comments on commit 8b97fdf

Please sign in to comment.