try using setTimeout to fix poormanscron-on-load issue

This commit is contained in:
Tyler Renelle 2012-08-06 13:39:27 -04:00
parent 6d204fb08c
commit 203632b6a1
2 changed files with 8 additions and 4 deletions

View file

@ -302,6 +302,9 @@ ready(function(model) {
return model.set('_user.lastCron', today);
}
};
setTimeout((function() {
return poormanscron();
}), 2000);
setInterval((function() {
return poormanscron();
}), 3600000);

View file

@ -235,7 +235,6 @@ ready (model) ->
# ========== CRON ==========
#TODO: remove when cron implemented
exports.poormanscron = poormanscron = () ->
today = new Date()
model.setNull('_user.lastCron', today)
@ -245,9 +244,11 @@ ready (model) ->
for n in [1..daysPassed]
scoring.tally(model)
model.set('_user.lastCron', today) # reset cron
## FIXME scoring.tally isn't working for calling poormanscron() on refresh, but does
## for setInterval & button-click -- what's going on?
# poormanscron() # Run once on refresh
# FIXME seems can't call poormanscron() instantly, have to call after some time (2s here)
# Doesn't do anything otherwise. Don't know why... model not initialized enough yet?
setTimeout (-> # Run once on refresh
poormanscron()
), 2000
setInterval (-> # Then run once every hour
poormanscron()
), 3600000