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/health-check/checks.js

44 lines
1.1 KiB
JavaScript

const superagent = require("superagent");
const HttpStatus = require("http-status-codes");
async function uploadCheck(done) {
const time = process.hrtime();
superagent
.post(`${process.env.PORTAL_URL}/skynet/skyfile`)
.attach("file", "package.json", "package.json")
.end((err, res) => {
const statusCode = (res && res.statusCode) || (err && err.statusCode) || null;
done({
name: "upload_file",
up: statusCode === HttpStatus.OK,
statusCode,
time: catchRequestTime(time),
});
});
}
function downloadCheck(done) {
const time = process.hrtime();
superagent.get(`${process.env.PORTAL_URL}`).end((err, res) => {
const statusCode = (res && res.statusCode) || (err && err.statusCode) || null;
done({
name: "download_file",
up: statusCode === HttpStatus.OK,
statusCode,
time: catchRequestTime(time),
});
});
}
function catchRequestTime(start) {
const diff = process.hrtime(start);
return Math.round((diff[0] * 1e9 + diff[1]) / 1e6); // msec
}
module.exports.checks = [uploadCheck, downloadCheck];