mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 10:56:53 -05:00
Add Mandate configuration for session save delays
This commit is contained in:
parent
57e8e61b1c
commit
e5dda556c6
3 changed files with 51 additions and 21 deletions
|
@ -28,12 +28,11 @@ module.exports = class LevelBus extends Bus
|
|||
constructor: ->
|
||||
super(arguments...)
|
||||
@changedSessionProperties = {}
|
||||
highLoad = false
|
||||
saveDelay = window.serverConfig?.sessionSaveDelay
|
||||
[wait, maxWait] = switch
|
||||
when not application.isProduction() then [1, 5] # Save quickly in development.
|
||||
when not highLoad then [4, 10] # Save slowly when in production.
|
||||
when not me.isAnonymous() then [10, 30] # Save even more slowly during HoC scaling.
|
||||
else [20, 60] # Save super slowly if anonymous during HoC scaling.
|
||||
when not application.isProduction or not saveDelay then [1, 5] # Save quickly in development.
|
||||
when me.isAnonymous() then [saveDelay.anonymous.min, saveDelay.anonymous.max]
|
||||
else [saveDelay.registered.min, saveDelay.registered.max]
|
||||
@saveSession = _.debounce @reallySaveSession, wait * 1000, {maxWait: maxWait * 1000}
|
||||
@playerIsIdle = false
|
||||
|
||||
|
|
|
@ -5,14 +5,39 @@ module.exports = MandateSchema = {
|
|||
additionalProperties: false
|
||||
default:
|
||||
simulationThroughputRatio: 1
|
||||
properties: {
|
||||
sessionSaveDelay:
|
||||
registered: {min: 4, max: 10}
|
||||
anonymous: {min: 5, max: 15}
|
||||
#registered: {min: 10, max: 30} # High load, like during HoC scaling
|
||||
#anonymous: {min: 20, max: 60}
|
||||
properties:
|
||||
simulationThroughputRatio:
|
||||
name: 'Simulation Throughput Ratio'
|
||||
description: '0-1 fraction of requests for a match to simulate that should be granted.'
|
||||
type: 'number'
|
||||
minimum: 0
|
||||
maximum: 1
|
||||
}
|
||||
sessionSaveDelay:
|
||||
name: 'Session Save Delay'
|
||||
description: 'How often we save level sessions after code changes--min and max wait in seconds.'
|
||||
type: 'object'
|
||||
properties:
|
||||
registered:
|
||||
description: 'How often to save for registered players.'
|
||||
type: 'object'
|
||||
additionalProperties: false
|
||||
requiredProperties: ['min', 'max']
|
||||
properties:
|
||||
min: {type: 'number', minimum: 1, exclusiveMinimum: true, format: 'seconds'}
|
||||
max: {type: 'number', minimum: 5, exclusiveMinimum: true, format: 'seconds'}
|
||||
anonymous:
|
||||
description: 'How often to save for anonymous players.'
|
||||
type: 'object'
|
||||
additionalProperties: false
|
||||
requiredProperties: ['min', 'max']
|
||||
properties:
|
||||
min: {type: 'number', minimum: 1, exclusiveMinimum: true, format: 'seconds'}
|
||||
max: {type: 'number', minimum: 5, exclusiveMinimum: true, format: 'seconds'}
|
||||
}
|
||||
|
||||
c.extendBasicProperties MandateSchema, 'Mandate'
|
||||
|
|
|
@ -17,6 +17,7 @@ auth = require './server/routes/auth'
|
|||
routes = require './server/routes'
|
||||
UserHandler = require './server/users/user_handler'
|
||||
hipchat = require './server/hipchat'
|
||||
Mandate = require './server/models/Mandate'
|
||||
global.tv4 = require 'tv4' # required for TreemaUtils to work
|
||||
global.jsondiffpatch = require 'jsondiffpatch'
|
||||
global.stripe = require('stripe')(config.stripe.secretKey)
|
||||
|
@ -181,10 +182,15 @@ setupFallbackRouteToIndex = (app) ->
|
|||
# insert the user object directly into the html so the application can have it immediately. Sanitize </script>
|
||||
user = if req.user then JSON.stringify(UserHandler.formatEntity(req, req.user)).replace(/\//g, '\\/') else '{}'
|
||||
|
||||
data = data.replace '"serverConfigTag"', JSON.stringify
|
||||
picoCTF: config.picoCTF,
|
||||
production: config.isProduction
|
||||
|
||||
Mandate.findOne({}).cache(5 * 60 * 1000).exec (err, mandate) ->
|
||||
if err
|
||||
log.error "Error getting mandate config: #{err}"
|
||||
configData = {}
|
||||
else
|
||||
configData = _.omit mandate?.toObject() or {}, '_id'
|
||||
configData.picoCTF = config.picoCTF
|
||||
configData.production = config.isProduction
|
||||
data = data.replace '"serverConfigTag"', JSON.stringify configData
|
||||
data = data.replace('"userObjectTag"', user)
|
||||
data = data.replace('"amActuallyTag"', JSON.stringify(req.session.amActually))
|
||||
res.header 'Cache-Control', 'no-cache, no-store, must-revalidate'
|
||||
|
|
Loading…
Reference in a new issue