update db before reading it in api
This commit is contained in:
parent
4d9a6d0cf3
commit
392cde2464
|
@ -6,6 +6,7 @@ if (!process.env.PORTAL_URL) {
|
||||||
|
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const bodyparser = require("body-parser");
|
const bodyparser = require("body-parser");
|
||||||
|
const db = require("./db");
|
||||||
|
|
||||||
require("./schedule");
|
require("./schedule");
|
||||||
|
|
||||||
|
@ -16,6 +17,10 @@ const server = express();
|
||||||
|
|
||||||
server.use(bodyparser.urlencoded({ extended: false }));
|
server.use(bodyparser.urlencoded({ extended: false }));
|
||||||
server.use(bodyparser.json());
|
server.use(bodyparser.json());
|
||||||
|
server.use((req, res, next) => {
|
||||||
|
db.read();
|
||||||
|
next();
|
||||||
|
})
|
||||||
|
|
||||||
server.get("/health-check", require("./api/index"));
|
server.get("/health-check", require("./api/index"));
|
||||||
server.get("/health-check/critical", require("./api/critical"));
|
server.get("/health-check/critical", require("./api/critical"));
|
||||||
|
|
|
@ -10,7 +10,7 @@ const criticalJob = schedule.scheduleJob("*/5 * * * *", async () => {
|
||||||
checks: await Promise.all(criticalChecks.map((check) => new Promise(check))),
|
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
|
// 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))),
|
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
|
// Launch Health check jobs
|
||||||
|
|
Reference in New Issue