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

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-09-09 12:25:00 +00:00
const superagent = require("superagent");
const { StatusCodes } = require("http-status-codes");
const { calculateElapsedTime, getResponseContent } = require("../utils");
2020-09-09 12:25:00 +00:00
// uploadCheck returns the result of uploading a sample file
async function uploadCheck(done) {
const time = process.hrtime();
superagent
.post(`http://${process.env.PORTAL_URL}/skynet/skyfile`)
.attach("file", "package.json", "package.json")
.end((error, response) => {
const statusCode = (response && response.statusCode) || (error && error.statusCode) || null;
done({
name: "upload_file",
up: statusCode === StatusCodes.OK,
statusCode,
errorResponseContent: getResponseContent(error?.response),
2020-09-09 12:53:05 +00:00
time: calculateElapsedTime(time),
2020-09-09 12:25:00 +00:00
});
});
}
// downloadCheck returns the result of downloading the hard coded link
async function downloadCheck(done) {
const time = process.hrtime();
const skylink = "AACogzrAimYPG42tDOKhS3lXZD8YvlF8Q8R17afe95iV2Q";
let statusCode, errorResponseContent;
2020-09-09 12:25:00 +00:00
try {
const response = await superagent.get(`http://${process.env.PORTAL_URL}/${skylink}?nocache=true`);
statusCode = response.statusCode;
} catch (error) {
statusCode = error.statusCode || error.status;
errorResponseContent = getResponseContent(error.response);
2020-09-09 12:25:00 +00:00
}
done({
name: "download_file",
up: statusCode === StatusCodes.OK,
statusCode,
errorResponseContent,
2020-09-09 12:53:05 +00:00
time: calculateElapsedTime(time),
2020-09-09 12:25:00 +00:00
});
}
module.exports.criticalChecks = [uploadCheck, downloadCheck];