Improve indexer state response (#74)
* Improve indexer isSynced flag if RPC behind indexer DB * Change indexer state output format * Update comment * Add isStuck flagpull/75/head
parent
b0dd52b74c
commit
b660e84bea
@ -0,0 +1,26 @@ |
||||
import {ShardID} from 'src/types' |
||||
import {config} from 'src/config' |
||||
|
||||
const {shards} = config.indexer |
||||
|
||||
interface BlockMetrics { |
||||
lastBlockNumber: number |
||||
lastBlockUpdatedAt: number |
||||
} |
||||
|
||||
const metrics: Record<ShardID, BlockMetrics> = shards.reduce((acc, shardId) => { |
||||
acc[shardId] = { |
||||
lastBlockNumber: 0, |
||||
lastBlockUpdatedAt: 0, |
||||
} |
||||
return acc |
||||
}, {} as any) |
||||
|
||||
export const addBlock = (shardId: ShardID, blockNumber: number) => { |
||||
if (metrics[shardId].lastBlockNumber !== blockNumber) { |
||||
metrics[shardId].lastBlockNumber = blockNumber |
||||
metrics[shardId].lastBlockUpdatedAt = Date.now() |
||||
} |
||||
} |
||||
|
||||
export const getBlocksMetrics = (shardId: ShardID) => metrics[shardId] |
Loading…
Reference in new issue