feat(backend): add cron and ping members

This commit is contained in:
NoobTW 2022-08-25 07:52:23 +08:00
parent 54ec7677db
commit d3fdac61bd
No known key found for this signature in database
GPG key ID: 3C04B63FD6FB4159
4 changed files with 676 additions and 18901 deletions

View file

@ -4,9 +4,11 @@ const logger = require("morgan");
const compression = require("compression");
const bearerToken = require("express-bearer-token");
const helmet = require("helmet");
const cron = require("node-cron");
const db = require("./utils/db");
const initAdmin = require("./utils/init-admin");
const pingAll = require("./utils/ping");
const authRoutes = require("./routes/auth");
const networkRoutes = require("./routes/network");
@ -74,4 +76,13 @@ app.use(async function (err, req, res) {
res.status(500).json({ error: "500 Internal server error" });
});
// ping all networks every 5 minutes
cron.schedule('5 * * * *', () => {
const networks = db.get('networks').value();
networks.forEach((network) => {
pingAll(network);
})
});
module.exports = app;