prune state.json

This commit is contained in:
Karol Wypchlo 2021-01-29 23:17:43 +01:00
parent 2d91181843
commit 2c1ccd0557
1 changed files with 7 additions and 2 deletions

View File

@ -1,3 +1,5 @@
const { getYesterdayISOString } = require("./utils");
require("yargs/yargs")(process.argv.slice(2)).command( require("yargs/yargs")(process.argv.slice(2)).command(
"$0 <type>", "$0 <type>",
"Skynet portal health checks", "Skynet portal health checks",
@ -31,7 +33,10 @@ require("yargs/yargs")(process.argv.slice(2)).command(
checks: await Promise.all(checks.map((check) => new Promise(check))), checks: await Promise.all(checks.map((check) => new Promise(check))),
}; };
// read before writing to make sure no external changes are overwritten db.read() // read before writing to make sure no external changes are overwritten
db.read().get(type).push(entry).write(); .get(type) // get the list of records of given type
.push(entry) // insert new record
.remove(({ date }) => date < getYesterdayISOString()) // drop old records
.write();
} }
).argv; ).argv;