Skip to content

Commit

Permalink
add index queue changes lost on merge
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ocean committed Jul 31, 2024
1 parent f4bfb44 commit 8211ade
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions dashboard/src/components/IndexQueue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,36 +20,49 @@ interface QueueItem {
export default function IndexQueue() {
const [queue, setQueue] = useState<QueueItem[]>([])
const { networks } = useAdminContext()
const [avoidAskQueue, setAvoidAskQueue] = useState<boolean>(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)
})
}

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
}
}
}, [])

Expand Down Expand Up @@ -88,6 +102,17 @@ export default function IndexQueue() {
) : (
<p>Indexing queue is empty.</p>
)}
{avoidAskQueue && (
<Alert
style={{ width: 640 }}
severity="warning"
onClose={() => {
setAvoidAskQueue(false)
}}
>
Node is not running Indexer. No need to get queue at this point!
</Alert>
)}
</div>
)
}

0 comments on commit 8211ade

Please sign in to comment.