-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd1273d
commit 4988256
Showing
1 changed file
with
17 additions
and
8 deletions.
There are no files selected for viewing
25 changes: 17 additions & 8 deletions
25
tf-managed/modules/snapshot-monitoring/snapshot-age-monitor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
var assert = require('assert'); | ||
var assert = require("assert"); | ||
|
||
function check_snapshot(url, genesisTime) { | ||
var callback = function (err, response, body) { | ||
assert.equal(response.statusCode, 200, 'Expected a 200 OK response'); | ||
assert.equal(response.statusCode, 200, "Expected a 200 OK response"); | ||
|
||
var snapshotName = response.url.split('/').pop(); | ||
var snapshotName = response.url.split("/").pop(); | ||
var height = snapshotName.match(/height_(\d+)/)[1]; | ||
|
||
var currentTime = Math.floor(Date.now() / 1000); | ||
var snapshotTime = height * 30 + genesisTime; | ||
var snapshotAgeInMinutes = (currentTime - snapshotTime) / 60; | ||
|
||
assert(snapshotAgeInMinutes < 360, 'Expected snapshot to be less than 360 minutes old'); | ||
} | ||
assert( | ||
snapshotAgeInMinutes < 360, | ||
"Expected snapshot to be less than 360 minutes old" | ||
); | ||
}; | ||
|
||
$http.head(url, callback) | ||
$http.head(url, callback); | ||
} | ||
|
||
check_snapshot('https://forest-archive.chainsafe.dev/latest/calibnet/', 1667326380) | ||
check_snapshot('https://forest-archive.chainsafe.dev/latest/mainnet/', 1598306400) | ||
check_snapshot( | ||
"https://forest-archive.chainsafe.dev/latest/calibnet/", | ||
1667326380 | ||
); | ||
check_snapshot( | ||
"https://forest-archive.chainsafe.dev/latest/mainnet/", | ||
1598306400 | ||
); |