move preen_users to real cron (remember to setup on the server with crontab)

This commit is contained in:
Tyler Renelle
2013-02-13 11:08:21 -05:00
parent 0dac392b57
commit c0efb23961
3 changed files with 1 additions and 45 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
// include moment
// mongo habitrpg node_modules/moment/moment.js migrations/20130212_preen_cron.js
/*
Users are allowed to experiment with the site before registering. Every time a new browser visits habitrpg, a new
-41
View File
@@ -1,41 +0,0 @@
moment = require('moment')
mongo = require("mongoskin")
_ = require('underscore')
###
Users are allowed to experiment with the site before registering. Every time a new browser visits habitrpg, a new
"staged" account is created - and if the user later registeres, that staged account is considered a "production" account.
This function removes all staged accounts that have been abandoned - either older than a month, or corrupted in some way (lastCron==undefined)
###
module.exports.deleteStaleAccounts = ->
un_registered = { "auth.local": {$exists: false} , "auth.facebook": {$exists: false} }
registered = { $or: [
{ 'auth.local': { $exists: true } },
{ 'auth.facebook': { $exists: true} }
]};
collection = mongo.db(process.env.NODE_DB_URI, {safe:true}).collection("users")
collection.count registered, (err, result) -> console.log("#{result} registered users [before]")
collection.count un_registered, (err, result) -> console.log("#{result} un-registered users [before]")
today = +new Date
# isValidDate = (d) ->
# return false if Object::toString.call(d) isnt "[object Date]"
# not isNaN(d.getTime())
removeAccount = (collection, id) -> collection.remove {_id: id}, (err, res) -> throw err if err
collection.findEach un_registered, (err, user) ->
throw err if err
return unless user? #why does this happen sometimes?
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).startOf('day').diff(moment(lastCron).startOf('day'), "days"))
if diff > 10
removeAccount(collection, user._id)
else
# cron was missing for some reason
collection.update {_id: user._id}, {$set:{lastCron: today}}, (err, res) -> throw err if err
-3
View File
@@ -10,9 +10,6 @@ auth = require 'derby-auth'
priv = require './private'
habitrpgStore = require('./store')
## Run server cron ##
#require('./cron').deleteStaleAccounts()
## RACER CONFIGURATION ##
racer = require 'racer'