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/schedule.js

29 lines
985 B
JavaScript
Raw Normal View History

const schedule = require("node-schedule");
const db = require("./db");
const { basicChecks } = require("./basicChecks");
const { verboseChecks } = require("./verboseChecks");
// execute the basic health-check script every 5 minutes
const basicJob = schedule.scheduleJob("*/5 * * * *", async () => {
const entry = { date: new Date().toISOString(), checks: [] };
entry.checks = await Promise.all(basicChecks.map((check) => new Promise(check)));
db.get("entries").push(entry).write();
});
// execute the verbose health-check script once a day at 3am
const verboseJob = schedule.scheduleJob("* 3 * * *", async () => {
const entry = { date: new Date().toISOString(), checks: [] };
entry.checks = await Promise.all(verboseChecks.map((check) => new Promise(check)));
db.get("entries").push(entry).write();
});
// Launch Health check jobs
2020-07-30 10:00:58 +00:00
setTimeout(() => {
basicJob.invoke();
verboseJob.invoke();
2020-07-30 10:00:58 +00:00
}, 60 * 1000); // delay for 60s to give other services time to start up