Server is ticking ever half-hour
This commit is contained in:
@@ -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
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user