Update healthcheck.js
- Check if the last synced block is matched with flo core wallet
This commit is contained in:
parent
28ba8e8232
commit
3f19804506
@ -35,9 +35,8 @@ checks.push(function check_API_sync() {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
//Check if the last synced block time is not too old
|
//Check if the last synced block is matched with flo core wallet
|
||||||
checks.push(function check_lastBlockTime() {
|
checks.push(function check_lastBlockTime() {
|
||||||
const ALLOW_BLOCK_DELAY = 60 * 60 * 1000; //1hr
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetch(URL + "/api/blocks?limit=1").then(res => {
|
fetch(URL + "/api/blocks?limit=1").then(res => {
|
||||||
if (!res.ok || res.status !== 200)
|
if (!res.ok || res.status !== 200)
|
||||||
@ -45,16 +44,19 @@ checks.push(function check_lastBlockTime() {
|
|||||||
res.json().then(data => {
|
res.json().then(data => {
|
||||||
if (!data.blocks.length)
|
if (!data.blocks.length)
|
||||||
return resolve(`Last Block not found`);
|
return resolve(`Last Block not found`);
|
||||||
let last_block_no = data.blocks[0].height, last_block_time = data.blocks[0].time;
|
let last_block_no = data.blocks[0].height;
|
||||||
last_block_time = last_block_time * 1000; //sec to ms
|
fetch('https://ranchimallflo.duckdns.org/api/v2.0/flocoreHeight').then(res2 => {
|
||||||
if (last_block_time + ALLOW_BLOCK_DELAY < Date.now())
|
res2.json().then(data_2 => {
|
||||||
return resolve(`Last Block#${last_block_no} synced at ${last_block_time}`);
|
let blockchain_height = data_2.blocks;
|
||||||
resolve(true);
|
if (blockchain_height != last_block_no)
|
||||||
|
return resolve(`Last Block#${last_block_no}. Blockchain height=${blockchain_height}`);
|
||||||
|
resolve(true);
|
||||||
|
}).catch(error => resolve(`Get block height: response not JSON`))
|
||||||
|
}).catch(error => reject(error))
|
||||||
}).catch(error => resolve(`Last Block API: response not JSON`))
|
}).catch(error => resolve(`Last Block API: response not JSON`))
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Promise.all(checks.map(c => c())).then(results => {
|
Promise.all(checks.map(c => c())).then(results => {
|
||||||
let reasons = results.filter(r => r !== true);
|
let reasons = results.filter(r => r !== true);
|
||||||
if (!reasons.length) {
|
if (!reasons.length) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user