back to syncronous calls on the client

This commit is contained in:
Tyler Renelle
2012-09-24 20:09:38 -04:00
parent 893b0bd383
commit ce901f7b93
4 changed files with 42 additions and 45 deletions
+1 -2
View File
@@ -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
View File
@@ -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);
}
};