update db before reading it in api

This commit is contained in:
Karol Wypchlo 2020-09-18 13:40:14 +02:00
parent 4d9a6d0cf3
commit 392cde2464
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