-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from SkynetLabs/esm
migrate codebase to esm
- Loading branch information
Showing
19 changed files
with
314 additions
and
430 deletions.
There are no files selected for viewing
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
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,85 +1,3 @@ | ||
#!/usr/bin/env node | ||
#!/bin/ash | ||
|
||
process.env.NODE_ENV = process.env.NODE_ENV || "production"; | ||
|
||
require("yargs/yargs")(process.argv.slice(2)) | ||
.help() | ||
.demandCommand() | ||
.strict(true) | ||
.command( | ||
"enable", | ||
"Mark portal as enabled", | ||
() => {}, | ||
() => { | ||
const db = require("../src/db"); | ||
|
||
db.set("disabled", false).write(); | ||
} | ||
) | ||
.command( | ||
"disable <reason>", | ||
"Mark portal as disabled (provide meaningful reason)", | ||
() => {}, | ||
({ reason }) => { | ||
const db = require("../src/db"); | ||
|
||
db.set("disabled", reason).write(); | ||
} | ||
) | ||
.command( | ||
"run <type>", | ||
"Skynet portal health checks", | ||
(yargs) => { | ||
yargs | ||
.positional("type", { | ||
describe: "Type of checks to run", | ||
type: "string", | ||
choices: ["critical", "extended"], | ||
}) | ||
.option("portal-url", { | ||
describe: "Skynet portal url", | ||
default: process.env.PORTAL_DOMAIN ? `https://${process.env.PORTAL_DOMAIN}` : "https://siasky.net", | ||
type: "string", | ||
}) | ||
.option("state-dir", { | ||
describe: "State directory", | ||
default: process.env.STATE_DIR || "state", | ||
type: "string", | ||
}); | ||
}, | ||
async ({ type, portalUrl, stateDir }) => { | ||
const { hostname: portalDomain } = new URL(portalUrl); // extract domain from portal url | ||
process.env.PORTAL_DOMAIN = portalDomain; | ||
process.env.STATE_DIR = stateDir; | ||
|
||
const util = require("util"); | ||
const { getYesterdayISOString } = require("../src/utils"); | ||
const createMiddleware = require("../src/checks/middleware"); | ||
const db = require("../src/db"); | ||
const checks = require(`../src/checks/${type}`); | ||
const middleware = await createMiddleware(); | ||
|
||
const entry = { | ||
date: new Date().toISOString(), | ||
// run all checks, filter empty responses (skipped) and pass the response through the middleware | ||
checks: (await Promise.all(checks.map((check) => check()))).filter(Boolean).map(middleware), | ||
}; | ||
|
||
db.read() // read before writing to make sure no external changes are overwritten | ||
.get(type) // get the list of records of given type | ||
.push(entry) // insert new record | ||
.remove(({ date }) => date < getYesterdayISOString()) // drop old records | ||
.write(); | ||
|
||
// exit with code 1 if any of the checks report failure | ||
if (entry.checks.some(({ up }) => !up)) { | ||
console.log( | ||
util.inspect( | ||
entry.checks.filter(({ up }) => !up), | ||
{ colors: true, depth: 7 } // increase depth to ensure errors are printed | ||
) | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
).argv; | ||
node /usr/app/src/cli $@ |
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
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.