handle missing crons @WIP

This commit is contained in:
Tyler Renelle 2013-01-28 22:32:04 -05:00
parent 3fdd43aeee
commit aca5ad4ca7
2 changed files with 10 additions and 8 deletions

View file

@ -0,0 +1,5 @@
db.users.update(
{ lastCron: { $exists: false} },
{ $set: { lastCron: +new Date } },
{ multi: true }
);

View file

@ -31,11 +31,8 @@ module.exports.deleteStaleAccounts = ->
collection.findEach un_registered, (err, user) ->
throw err if err
return unless user? #why does this happen sometimes?
unless user.lastCron
removeAccount(collection, user._id)
return
lastCron = new Date(user.lastCron)
diff = Math.abs(moment(today).sod().diff(moment(lastCron).sod(), "days"))
if diff > 30
removeAccount(collection, user._id)
if !!user.lastCron # for now ignore missing crons, still looking into why this is happening
lastCron = new Date(user.lastCron)
diff = Math.abs(moment(today).sod().diff(moment(lastCron).sod(), "days"))
if diff > 30
removeAccount(collection, user._id)