aboutsummaryrefslogtreecommitdiff
path: root/src/api/structures/Server.js
diff options
context:
space:
mode:
authorKana <[email protected]>2021-01-08 19:48:25 +0900
committerGitHub <[email protected]>2021-01-08 19:48:25 +0900
commit3cfb2721ce64ab94fdbc9c97b54602acc3c654be (patch)
treeb427becf78c51081e58f1b2af98b2662f7626a39 /src/api/structures/Server.js
parentMerge pull request #248 from WeebDev/feature/stats-dashboard (diff)
parentfix: pg driver doesn't return anything without .returning() (diff)
downloadhost.fuwn.me-3cfb2721ce64ab94fdbc9c97b54602acc3c654be.tar.xz
host.fuwn.me-3cfb2721ce64ab94fdbc9c97b54602acc3c654be.zip
Merge pull request #250 from Zephyrrus/feature/system_status_page
Feature/system status page
Diffstat (limited to 'src/api/structures/Server.js')
-rw-r--r--src/api/structures/Server.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/api/structures/Server.js b/src/api/structures/Server.js
index 0dec72a..446c621 100644
--- a/src/api/structures/Server.js
+++ b/src/api/structures/Server.js
@@ -14,8 +14,11 @@ const jetpack = require('fs-jetpack');
const path = require('path');
const morgan = require('morgan');
const rfs = require('rotating-file-stream');
+const CronJob = require('cron').CronJob;
const log = require('../utils/Log');
+const Util = require('../utils/Util');
+
// eslint-disable-next-line no-unused-vars
const rateLimiter = new RateLimit({
windowMs: parseInt(process.env.RATE_LIMIT_WINDOW, 10),
@@ -55,6 +58,9 @@ class Server {
// Serve the uploads
this.server.use(express.static(path.join(__dirname, '../../../uploads')));
this.routesFolder = path.join(__dirname, '../routes');
+
+ // Save the cron job instances in case we want to stop them later
+ this.jobs = {};
}
registerAllTheRoutes() {
@@ -95,6 +101,11 @@ class Server {
});
}
+ createJobs() {
+ // TODO: move into the database config. (we can just show the crontab line for start, later on we can add dropdowns and stuff)
+ this.jobs.stats = new CronJob('0 0 * * * *', Util.saveStatsToDb, null, true);
+ }
+
start() {
jetpack.dir('uploads/chunks');
jetpack.dir('uploads/thumbs/square');
@@ -105,6 +116,8 @@ class Server {
log.success(`Backend ready and listening on port ${this.port}`);
});
server.setTimeout(600000);
+
+ this.createJobs();
}
}