back to syncronous calls on the client
This commit is contained in:
+1
-2
@@ -49,8 +49,6 @@ get('/:uidParam?', function(page, model, _arg, next) {
|
||||
model.fn('_user._tnl', '_user.stats.lvl', function(lvl) {
|
||||
return (lvl * 100) / 5;
|
||||
});
|
||||
scoring.setModel(model);
|
||||
scoring.cron();
|
||||
return page.render();
|
||||
});
|
||||
});
|
||||
@@ -304,5 +302,6 @@ ready(function(model) {
|
||||
model.set('_items.weapon', content.items.weapon[1]);
|
||||
return model.set('_user.balance', model.get('_user.balance') - 0.50);
|
||||
};
|
||||
setTimeout(scoring.cron, 2000);
|
||||
return setInterval(scoring.cron, 3600000);
|
||||
});
|
||||
|
||||
+21
-22
@@ -200,18 +200,18 @@ score = function(taskId, direction, options) {
|
||||
};
|
||||
|
||||
cron = function() {
|
||||
var daysPassed, lastCron, tallyTask, tasks, today, todoTally;
|
||||
var daysPassed, expTally, lastCron, lvl, tallyTask, today, todoTally;
|
||||
today = new Date();
|
||||
user.setNull('lastCron', today);
|
||||
lastCron = user.get('lastCron');
|
||||
daysPassed = helpers.daysBetween(today, lastCron);
|
||||
if (daysPassed > 0) {
|
||||
todoTally = 0;
|
||||
tallyTask = function(taskObj, next) {
|
||||
tallyTask = function(taskObj, callback) {
|
||||
var absVal, completed, dayMapping, daysFailed, id, repeat, task, type, value;
|
||||
id = taskObj.id, type = taskObj.type, completed = taskObj.completed, repeat = taskObj.repeat;
|
||||
if (id == null) {
|
||||
return;
|
||||
return callback('a task had a null id during cron, this should not be happening');
|
||||
}
|
||||
task = user.at("tasks." + id);
|
||||
if (type === 'todo' || type === 'daily') {
|
||||
@@ -258,27 +258,26 @@ cron = function() {
|
||||
}).set('completed', false);
|
||||
}
|
||||
}
|
||||
return next();
|
||||
return callback();
|
||||
};
|
||||
tasks = _.toArray(user.get('tasks'));
|
||||
return async.forEach(tasks, tallyTask, function(err) {
|
||||
var expTally, lvl;
|
||||
user.push('history.todos', {
|
||||
date: today,
|
||||
value: todoTally
|
||||
});
|
||||
expTally = user.get('stats.exp');
|
||||
lvl = 0;
|
||||
while (lvl < (user.get('stats.lvl') - 1)) {
|
||||
lvl++;
|
||||
expTally += (lvl * 100) / 5;
|
||||
}
|
||||
user.push('history.exp', {
|
||||
date: today,
|
||||
value: expTally
|
||||
});
|
||||
return user.set('lastCron', today);
|
||||
_.each(user.get('tasks'), function(taskObj) {
|
||||
return tallyTask(taskObj, function() {});
|
||||
});
|
||||
user.push('history.todos', {
|
||||
date: today,
|
||||
value: todoTally
|
||||
});
|
||||
expTally = user.get('stats.exp');
|
||||
lvl = 0;
|
||||
while (lvl < (user.get('stats.lvl') - 1)) {
|
||||
lvl++;
|
||||
expTally += (lvl * 100) / 5;
|
||||
}
|
||||
user.push('history.exp', {
|
||||
date: today,
|
||||
value: expTally
|
||||
});
|
||||
return user.set('lastCron', today);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user