This repository has been archived on 2022-10-07. You can view files and clone it, but cannot push or open issues or pull requests.
skynet-webportal/packages/health-check/src/run.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-01-26 16:00:13 +00:00
require("yargs/yargs")(process.argv.slice(2)).command(
"$0 <type>",
"Skynet portal health checks",
(yargs) => {
yargs
.positional("type", {
describe: "Type of checks to run",
type: "string",
choices: ["critical", "verbose"],
})
.option("portal-url", {
2021-01-26 11:18:40 +00:00
describe: "Skynet portal url",
default: process.env.PORTAL_URL || "https://siasky.net",
type: "string",
2021-01-26 16:00:13 +00:00
})
.option("state-dir", {
2021-01-26 11:18:40 +00:00
describe: "State directory",
default: process.env.STATE_DIR || "state",
type: "string",
2021-01-26 16:00:13 +00:00
});
},
async ({ type, portalUrl, stateDir }) => {
2021-01-26 11:18:40 +00:00
process.env.PORTAL_URL = portalUrl;
process.env.STATE_DIR = stateDir;
const db = require("../src/db");
const checks = require(`../src/checks/${type}`);
const entry = {
2021-01-26 16:00:13 +00:00
date: new Date().toISOString(),
checks: await Promise.all(checks.map((check) => new Promise(check))),
2021-01-26 11:18:40 +00:00
};
// read before writing to make sure no external changes are overwritten
db.read().get(type).push(entry).write();
2021-01-26 16:00:13 +00:00
}
).argv;