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
999 B
JavaScript
Raw Normal View History

const schedule = require("node-schedule");
const db = require("./db");
2020-09-09 12:25:00 +00:00
const { criticalChecks } = require("./checks/critical");
const { verboseChecks } = require("./checks/verbose");
2020-09-09 12:25:00 +00:00
// execute the critical health-check script every 5 minutes
2020-09-10 10:15:54 +00:00
const criticalJob = schedule.scheduleJob("*/5 * * * *", async () => {
const entry = { date: new Date().toISOString(), checks: [] };
2020-09-09 12:25:00 +00:00
entry.checks = await Promise.all(criticalChecks.map((check) => new Promise(check)));
2020-09-10 10:15:54 +00:00
db.get("critical").push(entry).write();
});
2020-08-26 15:17:33 +00:00
// execute the verbose health-check script once per hour
const verboseJob = schedule.scheduleJob("0 * * * *", async () => {
const entry = { date: new Date().toISOString(), checks: [] };
entry.checks = await Promise.all(verboseChecks.map((check) => new Promise(check)));
2020-09-10 10:15:54 +00:00
db.get("verbose").push(entry).write();
});
// Launch Health check jobs
2020-07-30 10:00:58 +00:00
setTimeout(() => {
2020-09-10 10:15:54 +00:00
criticalJob.invoke();
verboseJob.invoke();
2020-09-10 10:15:54 +00:00
}, 60 * 0); // delay for 60s to give other services time to start up