Skip to content

Commit 70a0067

Browse files
authored
Merge pull request #321 from cardanoapi/fix/cardano-node-block-time-stamp
fix: secSinceLastBlock in cardano-node in agent-manager
2 parents 39d56f3 + b046340 commit 70a0067

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

agent-manager/src/controller/health.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ async function healthCheck(req: Request, res: Response) {
2626
metadataHealthCheck(),
2727
])
2828

29-
const blockLastTimeStamp = cardanoNodeStatus.lastTimeStamp
30-
const secsSinceLastBlock = blockLastTimeStamp ? new Date(Date.now() - blockLastTimeStamp).getSeconds() : null
31-
3229
const isHealthy =
3330
isKafkaHealthy &&
3431
nodeStatus.isHealthy &&
@@ -45,8 +42,8 @@ async function healthCheck(req: Request, res: Response) {
4542
},
4643
cardanoNode: {
4744
isHealthy: nodeStatus.isHealthy,
48-
secsSinceLastBlock,
49-
lastBlockTime: blockLastTimeStamp ? new Date(blockLastTimeStamp).toLocaleTimeString() : null,
45+
secsSinceLastBlock: nodeStatus.secsSinceLastBlock,
46+
lastBlockTime: new Date(nodeStatus.lastBlockTimeStamp).toLocaleTimeString(),
5047
lastBlock: nodeStatus.block,
5148
},
5249
dbSync: {

agent-manager/src/service/healthCheck/cardanoNode.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ class CardanoNodeStatus {
2020
}
2121

2222
checkStatus() {
23-
return { isHealthy: Date.now() - this.lastTimeStamp < 6 * 60 * 1000, block: this.block }
23+
const currentTimeStamp = Date.now()
24+
const secsSinceLastBlock = currentTimeStamp - this.lastTimeStamp
25+
return {
26+
isHealthy: secsSinceLastBlock < 6 * 60 * 1000,
27+
block: this.block,
28+
secsSinceLastBlock: Math.floor(secsSinceLastBlock / 1000),
29+
lastBlockTimeStamp: this.lastTimeStamp,
30+
}
2431
}
2532
}
2633

0 commit comments

Comments
 (0)