Merge pull request #13075 from keithjgrant/13059-running-job-output-gap

Fix gap between API-loaded job events and WS-streamed events
This commit is contained in:
Sarah Akus
2023-01-05 13:46:10 -05:00
committed by GitHub

View File

@@ -187,7 +187,9 @@ function JobOutput({ job, eventRelatedSearchableKeys, eventSearchableKeys }) {
useEffect(() => { useEffect(() => {
const pendingRequests = Object.values(eventByUuidRequests.current || {}); const pendingRequests = Object.values(eventByUuidRequests.current || {});
setHasContentLoading(true); // prevents "no content found" screen from flashing setHasContentLoading(true); // prevents "no content found" screen from flashing
setIsFollowModeEnabled(false); if (location.search) {
setIsFollowModeEnabled(false);
}
Promise.allSettled(pendingRequests).then(() => { Promise.allSettled(pendingRequests).then(() => {
setRemoteRowCount(0); setRemoteRowCount(0);
clearLoadedEvents(); clearLoadedEvents();
@@ -251,6 +253,9 @@ function JobOutput({ job, eventRelatedSearchableKeys, eventSearchableKeys }) {
}); });
const updated = oldWsEvents.concat(newEvents); const updated = oldWsEvents.concat(newEvents);
jobSocketCounter.current = updated.length; jobSocketCounter.current = updated.length;
if (!oldWsEvents.length && min > remoteRowCount + 1) {
loadJobEvents(min);
}
return updated.sort((a, b) => a.counter - b.counter); return updated.sort((a, b) => a.counter - b.counter);
}); });
setCssMap((prevCssMap) => ({ setCssMap((prevCssMap) => ({
@@ -358,7 +363,7 @@ function JobOutput({ job, eventRelatedSearchableKeys, eventSearchableKeys }) {
} }
}; };
const loadJobEvents = async () => { const loadJobEvents = async (firstWsCounter = null) => {
const [params, loadRange] = getEventRequestParams(job, 50, [1, 50]); const [params, loadRange] = getEventRequestParams(job, 50, [1, 50]);
if (isMounted.current) { if (isMounted.current) {
@@ -371,6 +376,9 @@ function JobOutput({ job, eventRelatedSearchableKeys, eventSearchableKeys }) {
if (isFlatMode) { if (isFlatMode) {
params.not__stdout = ''; params.not__stdout = '';
} }
if (firstWsCounter) {
params.counter__lt = firstWsCounter;
}
const qsParams = parseQueryString(QS_CONFIG, location.search); const qsParams = parseQueryString(QS_CONFIG, location.search);
const eventPromise = getJobModel(job.type).readEvents(job.id, { const eventPromise = getJobModel(job.type).readEvents(job.id, {
...params, ...params,
@@ -435,7 +443,7 @@ function JobOutput({ job, eventRelatedSearchableKeys, eventSearchableKeys }) {
if (getEvent(counter)) { if (getEvent(counter)) {
return true; return true;
} }
if (index > remoteRowCount && index < remoteRowCount + wsEvents.length) { if (index >= remoteRowCount && index < remoteRowCount + wsEvents.length) {
return true; return true;
} }
return currentlyLoading.includes(counter); return currentlyLoading.includes(counter);
@@ -462,7 +470,7 @@ function JobOutput({ job, eventRelatedSearchableKeys, eventSearchableKeys }) {
} }
if ( if (
!event && !event &&
index > remoteRowCount && index >= remoteRowCount &&
index < remoteRowCount + wsEvents.length index < remoteRowCount + wsEvents.length
) { ) {
event = wsEvents[index - remoteRowCount]; event = wsEvents[index - remoteRowCount];
@@ -629,10 +637,14 @@ function JobOutput({ job, eventRelatedSearchableKeys, eventSearchableKeys }) {
setIsFollowModeEnabled(false); setIsFollowModeEnabled(false);
}; };
const scrollToEnd = () => { const scrollToEnd = useCallback(() => {
scrollToRow(-1); scrollToRow(-1);
setTimeout(() => scrollToRow(-1), 100); let timeout;
}; if (isFollowModeEnabled) {
setTimeout(() => scrollToRow(-1), 100);
}
return () => clearTimeout(timeout);
}, [isFollowModeEnabled]);
const handleScrollLast = () => { const handleScrollLast = () => {
scrollToEnd(); scrollToEnd();