poll for events processing completion (#12689)

This commit is contained in:
Keith Grant
2022-08-31 13:03:35 -07:00
committed by GitHub
parent 8ad948f268
commit 8a06ffbe15

View File

@@ -10,7 +10,7 @@ import {
InfiniteLoader, InfiniteLoader,
List, List,
} from 'react-virtualized'; } from 'react-virtualized';
import { Button } from '@patternfly/react-core'; import { Button, Alert } from '@patternfly/react-core';
import AlertModal from 'components/AlertModal'; import AlertModal from 'components/AlertModal';
import { CardBody as _CardBody } from 'components/Card'; import { CardBody as _CardBody } from 'components/Card';
@@ -99,6 +99,7 @@ function JobOutput({ job, eventRelatedSearchableKeys, eventSearchableKeys }) {
const scrollHeight = useRef(0); const scrollHeight = useRef(0);
const history = useHistory(); const history = useHistory();
const eventByUuidRequests = useRef([]); const eventByUuidRequests = useRef([]);
const eventsProcessedDelay = useRef(250);
const fetchEventByUuid = async (uuid) => { const fetchEventByUuid = async (uuid) => {
let promise = eventByUuidRequests.current[uuid]; let promise = eventByUuidRequests.current[uuid];
@@ -156,6 +157,7 @@ function JobOutput({ job, eventRelatedSearchableKeys, eventSearchableKeys }) {
); );
const [isMonitoringWebsocket, setIsMonitoringWebsocket] = useState(false); const [isMonitoringWebsocket, setIsMonitoringWebsocket] = useState(false);
const [lastScrollPosition, setLastScrollPosition] = useState(0); const [lastScrollPosition, setLastScrollPosition] = useState(0);
const [showEventsRefresh, setShowEventsRefresh] = useState(false);
useEffect(() => { useEffect(() => {
if (!isTreeReady || !onReadyEvents.length) { if (!isTreeReady || !onReadyEvents.length) {
@@ -196,14 +198,28 @@ function JobOutput({ job, eventRelatedSearchableKeys, eventSearchableKeys }) {
rebuildEventsTree(); rebuildEventsTree();
}, [isFlatMode]); // eslint-disable-line react-hooks/exhaustive-deps }, [isFlatMode]); // eslint-disable-line react-hooks/exhaustive-deps
const pollForEventsProcessed = useCallback(async () => {
const {
data: { event_processing_finished },
} = await getJobModel(job.type).readDetail(job.id);
if (event_processing_finished) {
setShowEventsRefresh(true);
return;
}
const fiveMinutes = 1000 * 60 * 5;
if (eventsProcessedDelay.current >= fiveMinutes) {
return;
}
setTimeout(pollForEventsProcessed, eventsProcessedDelay.current);
eventsProcessedDelay.current *= 2;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [job.id, job.type, lastScrollPosition]);
useEffect(() => { useEffect(() => {
if (!isJobRunning(jobStatus)) { if (!isJobRunning(jobStatus)) {
setTimeout(() => { if (wsEvents.length) {
loadJobEvents().then(() => { pollForEventsProcessed();
setWsEvents([]); }
scrollToRow(lastScrollPosition);
});
}, 500);
return; return;
} }
let batchTimeout; let batchTimeout;
@@ -268,7 +284,8 @@ function JobOutput({ job, eventRelatedSearchableKeys, eventSearchableKeys }) {
setIsMonitoringWebsocket(false); setIsMonitoringWebsocket(false);
isMounted.current = false; isMounted.current = false;
}; };
}, [isJobRunning(jobStatus)]); // eslint-disable-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [isJobRunning(jobStatus), pollForEventsProcessed]);
useEffect(() => { useEffect(() => {
if (isFollowModeEnabled) { if (isFollowModeEnabled) {
@@ -681,6 +698,26 @@ function JobOutput({ job, eventRelatedSearchableKeys, eventSearchableKeys }) {
isFollowModeEnabled={isFollowModeEnabled} isFollowModeEnabled={isFollowModeEnabled}
setIsFollowModeEnabled={setIsFollowModeEnabled} setIsFollowModeEnabled={setIsFollowModeEnabled}
/> />
{showEventsRefresh ? (
<Alert
variant="default"
title={
<>
{t`Events processing complete.`}{' '}
<Button
variant="link"
isInline
onClick={() => {
loadJobEvents().then(() => {
setWsEvents([]);
});
setShowEventsRefresh(false);
}}
>{t`Reload output`}</Button>
</>
}
/>
) : null}
<PageControls <PageControls
onScrollFirst={handleScrollFirst} onScrollFirst={handleScrollFirst}
onScrollLast={handleScrollLast} onScrollLast={handleScrollLast}