fix(ui): ignore events after canceling session

This commit is contained in:
psychedelicious 2023-04-30 23:08:05 +10:00
parent 270657a62c
commit d5e152b35e
2 changed files with 26 additions and 3 deletions

View File

@ -79,6 +79,7 @@ export interface SystemState {
consoleLogLevel: InvokeLogLevel;
shouldLogToConsole: boolean;
statusTranslationKey: TFuncKey;
canceledSession: string;
}
const initialSystemState: SystemState = {
@ -109,6 +110,7 @@ const initialSystemState: SystemState = {
consoleLogLevel: 'error',
shouldLogToConsole: true,
statusTranslationKey: 'common.statusDisconnected',
canceledSession: '',
};
export const systemSlice = createSlice({
@ -254,6 +256,7 @@ export const systemSlice = createSlice({
*/
builder.addCase(socketSubscribed, (state, action) => {
state.sessionId = action.payload.sessionId;
state.canceledSession = '';
});
/**
@ -299,7 +302,7 @@ export const systemSlice = createSlice({
/**
* Invocation Started
*/
builder.addCase(invocationStarted, (state) => {
builder.addCase(invocationStarted, (state, action) => {
state.isCancelable = true;
state.isProcessing = true;
state.currentStatusHasSteps = false;
@ -340,14 +343,17 @@ export const systemSlice = createSlice({
builder.addCase(invocationComplete, (state, action) => {
const { data, timestamp } = action.payload;
state.isProcessing = true;
state.isCancelable = true;
// state.currentIteration = 0;
// state.totalIterations = 0;
state.currentStatusHasSteps = false;
state.currentStep = 0;
state.totalSteps = 0;
state.statusTranslationKey = 'common.statusProcessingComplete';
if (state.canceledSession === data.graph_execution_state_id) {
state.isProcessing = false;
state.isCancelable = true;
}
});
/**
@ -384,6 +390,7 @@ export const systemSlice = createSlice({
builder.addCase(sessionCanceled.fulfilled, (state, action) => {
const { timestamp } = action.payload;
state.canceledSession = action.meta.arg.sessionId;
state.isProcessing = false;
state.isCancelable = false;
state.isCancelScheduled = false;

View File

@ -90,6 +90,14 @@ export const setEventListeners = (arg: SetEventListenersArg) => {
* Invocation started
*/
socket.on('invocation_started', (data) => {
if (getState().system.canceledSession === data.graph_execution_state_id) {
log.trace(
{ data, sessionId: data.graph_execution_state_id },
`Ignored invocation started (${data.node.type}) for canceled session (${data.graph_execution_state_id})`
);
return;
}
log.info(
{ data, sessionId: data.graph_execution_state_id },
`Invocation started (${data.node.type})`
@ -101,6 +109,14 @@ export const setEventListeners = (arg: SetEventListenersArg) => {
* Generator progress
*/
socket.on('generator_progress', (data) => {
if (getState().system.canceledSession === data.graph_execution_state_id) {
log.trace(
{ data, sessionId: data.graph_execution_state_id },
`Ignored generator progress (${data.node.type}) for canceled session (${data.graph_execution_state_id})`
);
return;
}
log.trace(
{ data, sessionId: data.graph_execution_state_id },
`Generator progress (${data.node.type})`