From 75b0766df164fe0d82c3c324810ba060cec5d8ec Mon Sep 17 00:00:00 2001 From: paulo-ocean Date: Fri, 26 Jul 2024 14:01:57 +0100 Subject: [PATCH] fix get indexing queue --- dashboard/src/components/IndexQueue.tsx | 51 ++++++++++++++++++------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/dashboard/src/components/IndexQueue.tsx b/dashboard/src/components/IndexQueue.tsx index 625289047..15080f021 100644 --- a/dashboard/src/components/IndexQueue.tsx +++ b/dashboard/src/components/IndexQueue.tsx @@ -9,6 +9,7 @@ import { } from '@mui/material' import styles from './Dashboard/index.module.css' import { useAdminContext } from '@/context/AdminProvider' +import Alert from '@mui/material/Alert' interface QueueItem { txId: string @@ -19,21 +20,32 @@ interface QueueItem { export default function IndexQueue() { const [queue, setQueue] = useState([]) const { networks } = useAdminContext() + const [avoidAskQueue, setAvoidAskQueue] = useState(false) + let intervalId: any = null useEffect(() => { const fetchQueue = () => { fetch('/api/services/indexQueue') - .then((response) => response.json()) - .then((data) => { - const transformedQueue = data.queue.map((item: any) => { - const network = networks.find((net) => net.chainId === item.chainId) - return { - txId: item.txId, - chainId: item.chainId, - chain: network ? network.network : 'Unknown Network' + .then((response) => { + if (response.status === 400) { + console.warn('Cannot fetch queue: Node is not running Indexer') + setAvoidAskQueue(true) + if (intervalId) { + clearInterval(intervalId) // Stop doing this, there is no point, since we don't have Indexer } - }) - setQueue(transformedQueue) + } else { + response.json().then((data) => { + const transformedQueue = data.queue.map((item: any) => { + const network = networks.find((net) => net.chainId === item.chainId) + return { + txId: item.txId, + chainId: item.chainId, + chain: network ? network.network : 'Unknown Network' + } + }) + setQueue(transformedQueue) + }) + } }) .catch((error) => { console.error('Error fetching queue:', error) @@ -41,14 +53,16 @@ export default function IndexQueue() { } fetchQueue() // Initial fetch - let pollingInterval = 2000 // Default polling interval + let pollingInterval = 10000 // Default polling interval (10 seconds) if (process.env.INDEXER_INTERVAL) { pollingInterval = Number(process.env.INDEXER_INTERVAL) } - const intervalId = setInterval(fetchQueue, pollingInterval) + intervalId = setInterval(fetchQueue, pollingInterval) return () => { - clearInterval(intervalId) // Clear interval on component unmount + if (intervalId) { + clearInterval(intervalId) // Clear interval on component unmount + } } }, []) @@ -88,6 +102,17 @@ export default function IndexQueue() { ) : (

Indexing queue is empty.

)} + {avoidAskQueue && ( + { + setAvoidAskQueue(false) + }} + > + Node is not running Indexer. No need to get queue at this point! + + )} ) }