Server is ticking ever half-hour

This commit is contained in:
2019-05-20 08:31:33 +10:00
parent 08ac120f56
commit cbfbf2320b
3 changed files with 21 additions and 3 deletions
+1
View File
@@ -30,6 +30,7 @@ app.post('/profilerequest', profiles.profileRequest(connection));
app.post('/recruit', profiles.recruit(connection));
app.post('/train', profiles.train(connection));
app.post('/untrain', profiles.untrain(connection));
profiles.runGoldTick(connection);
//static directories
app.use('/styles', express.static(path.resolve(__dirname + '/../public/styles')) );
+19 -1
View File
@@ -3,7 +3,9 @@ require('dotenv').config();
//libraries
let formidable = require('formidable');
let CronJob = require('cron').CronJob;
//profile creation & requesting
const profileCreate = (connection) => (req, res) => {
//formidable handles forms
let form = formidable.IncomingForm();
@@ -95,6 +97,7 @@ function profileRequestInner(connection, req, res, fields) {
});
}
//actual actions to be taken
const recruit = (connection) => (req, res) => {
//formidable handles forms
let form = formidable.IncomingForm();
@@ -332,10 +335,25 @@ const untrain = (connection) => (req, res) => {
});
}
const runGoldTick = (connection) => {
let goldTickJob = new CronJob('0 */30 * * * *', () => {
let query = 'UPDATE profiles SET gold = gold + recruits;';
connection.query(query, (err) => {
if (err) throw err;
//debugging
//console.log(Date().toString() + ' gold tick');
});
});
goldTickJob.start();
}
module.exports = {
// profileCreate: profileCreate, //NOTE: Not actually used
profileRequest: profileRequest,
recruit: recruit,
train: train,
untrain: untrain
untrain: untrain,
runGoldTick: runGoldTick
}