Skip to content

Commit

Permalink
Close events SSE connection when notebook complete
Browse files Browse the repository at this point in the history
When the execution is complete and the HTML is available (html_hash is
set) we can stop watching the /events endpoint because nothing is going
to change.

Also clean up logging. Only make console.error statements on errors; we
no longer need regular logging of all actions.
  • Loading branch information
jonathansick committed Jan 31, 2025
1 parent 89b2b24 commit 055f77b
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function TimesSquareHtmlEventsProvider({ children }) {
signal: abortController.signal,
onopen(res) {
if (res.status >= 400 && res.status < 500 && res.status !== 429) {
console.log(`Client side error ${fullHtmlEventsUrl}`, res);
console.error(`Client side error ${fullHtmlEventsUrl}`, res);
}
},
onmessage(event) {
Expand All @@ -43,9 +43,21 @@ export default function TimesSquareHtmlEventsProvider({ children }) {
return;
}
setHtmlEvent(parsedData);

if (
parsedData.execution_status == 'complete' &&
parsedData.html_hash
) {
abortController.abort();
}
},
onclose() {},
onerror(err) {},
onerror(err) {
console.error(
`Error fetching Times Square events SSE ${fullHtmlEventsUrl}`,
err
);
},
});
}
}
Expand Down

0 comments on commit 055f77b

Please sign in to comment.