Merge pull request #405 from NebulousLabs/healthcheck-cli-fix

update db before reading it in api
This commit is contained in:
Karol Wypchło 2020-09-18 17:05:43 +02:00 committed by GitHub
commit 97e312f75a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -6,6 +6,7 @@ if (!process.env.PORTAL_URL) {
const express = require("express");
const bodyparser = require("body-parser");
const db = require("./db");
require("./schedule");
@ -16,6 +17,10 @@ const server = express();
server.use(bodyparser.urlencoded({ extended: false }));
server.use(bodyparser.json());
server.use((req, res, next) => {
db.read();
next();
});
server.get("/health-check", require("./api/index"));
server.get("/health-check/critical", require("./api/critical"));

View File

@ -10,7 +10,7 @@ const criticalJob = schedule.scheduleJob("*/5 * * * *", async () => {
checks: await Promise.all(criticalChecks.map((check) => new Promise(check))),
};
db.get("critical").push(entry).write();
db.read().get("critical").push(entry).write();
});
// execute the verbose health-check script once per hour
@ -20,7 +20,7 @@ const verboseJob = schedule.scheduleJob("0 * * * *", async () => {
checks: await Promise.all(verboseChecks.map((check) => new Promise(check))),
};
db.get("verbose").push(entry).write();
db.read().get("verbose").push(entry).write();
});
// Launch Health check jobs