mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Add options for separate level session database and aux level session database.
This commit is contained in:
parent
f8a67ace0e
commit
88bd74a5a5
3 changed files with 42 additions and 2 deletions
|
@ -31,6 +31,6 @@ AnalyticsLogEventSchema.statics.logEvent = (user, event, properties={}) ->
|
||||||
unless config.proxy
|
unless config.proxy
|
||||||
analyticsMongoose = mongoose.createConnection()
|
analyticsMongoose = mongoose.createConnection()
|
||||||
analyticsMongoose.open "mongodb://#{config.mongo.analytics_host}:#{config.mongo.analytics_port}/#{config.mongo.analytics_db}", (error) ->
|
analyticsMongoose.open "mongodb://#{config.mongo.analytics_host}:#{config.mongo.analytics_port}/#{config.mongo.analytics_db}", (error) ->
|
||||||
log.warn "Couldnt connect to analytics", error
|
log.error "Couldnt connect to analytics", error if error
|
||||||
|
|
||||||
module.exports = AnalyticsLogEvent = analyticsMongoose.model('analytics.log.event', AnalyticsLogEventSchema, config.mongo.analytics_collection)
|
module.exports = AnalyticsLogEvent = analyticsMongoose.model('analytics.log.event', AnalyticsLogEventSchema, config.mongo.analytics_collection)
|
||||||
|
|
|
@ -106,4 +106,35 @@ LevelSessionSchema.set('toObject', {
|
||||||
return ret
|
return ret
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = LevelSession = mongoose.model('level.session', LevelSessionSchema, 'level.sessions')
|
if config.mongo.level_session_host?
|
||||||
|
levelSessionMongo = mongoose.createConnection()
|
||||||
|
levelSessionMongo.open "mongodb://#{config.mongo.level_session_host}:#{config.mongo.level_session_port}/#{config.mongo.level_session_db}", (error) ->
|
||||||
|
if error
|
||||||
|
log.error "Couldnt connect to session mongo!", error
|
||||||
|
else
|
||||||
|
log.info "Connected to seperate level session server."
|
||||||
|
else
|
||||||
|
levelSessionMongo = mongoose
|
||||||
|
|
||||||
|
LevelSession = levelSessionMongo.model('level.session', LevelSessionSchema, 'level.sessions')
|
||||||
|
|
||||||
|
if config.mongo.level_session_aux_host?
|
||||||
|
auxLevelSessionMongo = mongoose.createConnection()
|
||||||
|
auxLevelSessionMongo.open "mongodb://#{config.mongo.level_session_aux_host}:#{config.mongo.level_session_aux_port}/#{config.mongo.level_session_aux_db}", (error) ->
|
||||||
|
if error
|
||||||
|
log.error "Couldnt connect to AUX session mongo!", error
|
||||||
|
else
|
||||||
|
log.info "Connected to seperate level AUX session server."
|
||||||
|
|
||||||
|
auxLevelSession = auxLevelSessionMongo.model('level.session', LevelSessionSchema, 'level.sessions')
|
||||||
|
|
||||||
|
LevelSessionSchema.post 'save', (d) ->
|
||||||
|
return unless d instanceof LevelSession
|
||||||
|
console.log "Saving D", arguments
|
||||||
|
o = d.toObject {transform: ((x, r) -> r), virtuals: false}
|
||||||
|
console.log "Guess I should write", o
|
||||||
|
auxLevelSession.collection.save o, {w:1}, (err, v) ->
|
||||||
|
console.log err.stack if err
|
||||||
|
console.log("update sent", arguments)
|
||||||
|
|
||||||
|
module.exports = LevelSession
|
||||||
|
|
|
@ -26,6 +26,15 @@ config.mongo =
|
||||||
mongoose_tokyo_replica_string: process.env.COCO_MONGO_MONGOOSE_TOKYO_REPLICA_STRING or ''
|
mongoose_tokyo_replica_string: process.env.COCO_MONGO_MONGOOSE_TOKYO_REPLICA_STRING or ''
|
||||||
mongoose_saoPaulo_replica_string : process.env.COCO_MONGO_MONGOOSE_SAOPAULO_REPLICA_STRING or ''
|
mongoose_saoPaulo_replica_string : process.env.COCO_MONGO_MONGOOSE_SAOPAULO_REPLICA_STRING or ''
|
||||||
|
|
||||||
|
if process.env.COCO_MONGO_LS_HOST? or process.env.COCO_MONGO_LS_DATABASE_NAME?
|
||||||
|
config.mongo.level_session_host = process.env.COCO_MONGO_LS_HOST or process.env.COCO_MONGO_HOST or 'localhost'
|
||||||
|
config.mongo.level_session_port = process.env.COCO_MONGO_LS_PORT or process.env.COCO_MONGO_PORT or 27017
|
||||||
|
config.mongo.level_session_db = process.env.COCO_MONGO_LS_DATABASE_NAME or process.env.COCO_MONGO_DATABASE_NAME or 'coco'
|
||||||
|
|
||||||
|
if process.env.COCO_MONGO_LS_AUX_HOST? and process.env.COCO_MONGO_LS_AUX_PORT? and process.env.COCO_MONGO_LS_AUX_DATABASE_NAME
|
||||||
|
config.mongo.level_session_aux_host = process.env.COCO_MONGO_LS_AUX_HOST or process.env.COCO_MONGO_HOST or 'localhost'
|
||||||
|
config.mongo.level_session_aux_port = process.env.COCO_MONGO_LS_AUX_PORT or process.env.COCO_MONGO_PORT or 27017
|
||||||
|
config.mongo.level_session_aux_db = process.env.COCO_MONGO_LS_AUX_DATABASE_NAME or 'coco_aux'
|
||||||
|
|
||||||
|
|
||||||
if config.tokyo or config.saoPaulo
|
if config.tokyo or config.saoPaulo
|
||||||
|
|
Loading…
Reference in a new issue