Trying (new Date) instead of new Date() due to multiple crons on 1 day bug

This commit is contained in:
Tyler Renelle 2012-07-13 09:43:53 -05:00
parent 682d0d1180
commit 3a155fb306
2 changed files with 11 additions and 5 deletions

View file

@ -518,15 +518,20 @@ ready(function(model) {
exports.poormanscron = poormanscron = function() {
var DAY, daysPassed, lastCron, today;
model.setNull('_user.lastCron', new Date());
lastCron = new Date(new Date(model.get('_user.lastCron')).toDateString());
today = new Date(new Date().toDateString());
lastCron = new Date((new Date(model.get('_user.lastCron'))).toDateString());
today = new Date((new Date).toDateString());
DAY = 1000 * 60 * 60 * 24;
daysPassed = Math.floor((today.getTime() - lastCron.getTime()) / DAY);
if (daysPassed > 0) {
_(daysPassed).times(function() {
return endOfDayTally();
});
return model.set('_user.lastCron', today);
model.set('_user.lastCron', today);
return console.log({
today: today,
lastCron: lastCron,
daysPassed: daysPassed
}, 'cron debugging');
}
};
poormanscron();

View file

@ -398,14 +398,15 @@ ready (model) ->
#TODO: remove when cron implemented
exports.poormanscron = poormanscron = ->
model.setNull('_user.lastCron', new Date())
lastCron = new Date(new Date(model.get('_user.lastCron')).toDateString()) # calculate as midnight
today = new Date(new Date().toDateString()) # calculate as midnight
lastCron = new Date( (new Date(model.get('_user.lastCron'))).toDateString() ) # calculate as midnight
today = new Date((new Date).toDateString()) # calculate as midnight
DAY = 1000 * 60 * 60 * 24
daysPassed = Math.floor((today.getTime() - lastCron.getTime()) / DAY)
if daysPassed > 0
_(daysPassed).times ->
endOfDayTally()
model.set('_user.lastCron', today) # reset cron
console.log {today: today, lastCron: lastCron, daysPassed: daysPassed}, 'cron debugging'
poormanscron() # Run once on refresh
setInterval (-> # Then run once every hour
poormanscron()