feat: revamp abort run handler

This commit is contained in:
Rohit
2025-06-12 11:16:31 +05:30
parent 02c603c518
commit 83280fbcf3

View File

@@ -43,22 +43,59 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
runId: '', runId: '',
robotMetaId: '' robotMetaId: ''
}); });
const [queuedRuns, setQueuedRuns] = React.useState<Set<string>>(new Set());
let aborted = false; let aborted = false;
const { notify, setRerenderRuns, setRecordingId } = useGlobalInfoStore(); const { notify, setRerenderRuns, setRecordingId } = useGlobalInfoStore();
const navigate = useNavigate(); const navigate = useNavigate();
const abortRunHandler = (runId: string) => { const abortRunHandler = (runId: string, robotName: string, browserId: string) => {
notify('info', t('main_page.notifications.abort_initiated', { name: robotName }));
aborted = true; aborted = true;
notifyAboutAbort(runId).then(async (response) => { notifyAboutAbort(runId).then(async (response) => {
if (response) { if (!response.success) {
notify('success', t('main_page.notifications.abort_success', { name: runningRecordingName })); notify('error', t('main_page.notifications.abort_failed', { name: robotName }));
await stopRecording(ids.browserId); setRerenderRuns(true);
} else { return;
notify('error', t('main_page.notifications.abort_failed', { name: runningRecordingName }));
} }
})
if (response.isQueued) {
setRerenderRuns(true);
notify('success', t('main_page.notifications.abort_success', { name: robotName }));
setQueuedRuns(prev => {
const newSet = new Set(prev);
newSet.delete(runId);
return newSet;
});
return;
}
const abortSocket = io(`${apiUrl}/${browserId}`, {
transports: ["websocket"],
rejectUnauthorized: false
});
abortSocket.on('run-aborted', (abortData) => {
if (abortData.runId === runId) {
notify('success', t('main_page.notifications.abort_completed', { name: abortData.robotName || robotName }));
setRerenderRuns(true);
abortSocket.disconnect();
}
});
abortSocket.on('connect_error', (error) => {
console.log('Abort socket connection error:', error);
notify('error', t('main_page.notifications.abort_failed', { name: robotName }));
setRerenderRuns(true);
abortSocket.disconnect();
});
});
} }
const setRecordingInfo = (id: string, name: string) => { const setRecordingInfo = (id: string, name: string) => {
@@ -156,7 +193,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
case 'runs': case 'runs':
return <Runs return <Runs
currentInterpretationLog={currentInterpretationLog} currentInterpretationLog={currentInterpretationLog}
abortRunHandler={() => abortRunHandler(ids.runId)} abortRunHandler={abortRunHandler}
runId={ids.runId} runId={ids.runId}
runningRecordingName={runningRecordingName} runningRecordingName={runningRecordingName}
/>; />;