Add Mandate for modifying simulation throughput on the fly, other things later

This commit is contained in:
Nick Winter 2015-12-15 16:37:53 -08:00 committed by Rob
parent e0c88cf146
commit 129d3b793d
7 changed files with 43 additions and 10 deletions

View file

@ -59,6 +59,7 @@ module.exports = class Simulator extends CocoClass
success: (taskData) =>
return if @destroyed
unless taskData
@retryDelayInSeconds = 10
@trigger 'statusUpdate', "No games to simulate. Trying another game in #{@retryDelayInSeconds} seconds."
@simulateAnotherTaskAfterDelay()
return

View file

@ -0,0 +1,6 @@
CocoModel = require './CocoModel'
module.exports = class MandateModel extends CocoModel
@className: 'Mandate'
@schema: require 'schemas/models/mandate.schema'
urlRoot: '/db/mandates'

View file

@ -0,0 +1,18 @@
c = require './../schemas'
module.exports = MandateSchema = {
type: 'object'
additionalProperties: false
default:
simulationThroughputRatio: 1
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
}
}
c.extendBasicProperties MandateSchema, 'Mandate'

View file

@ -26,9 +26,8 @@ module.exports = class SimulateTabView extends CocoView
onLoaded: ->
super()
@render()
# Save our MongoDB oplog!
#if (document.location.hash is '#simulate' or @options.level.get('type') is 'course-ladder') and not @simulator
# @startSimulating()
if (document.location.hash is '#simulate' or @options.level.get('type') is 'course-ladder') and not @simulator
@startSimulating()
getRenderData: ->
ctx = super()

View file

@ -427,7 +427,7 @@ module.exports = class PlayLevelView extends RootView
shouldSimulate: ->
return true if @getQueryVariable('simulate') is true
return false # Save our MongoDB oplog!
return false if @getQueryVariable('simulate') is false
stillBuggy = true # Keep this true while we still haven't fixed the zombie worker problem when simulating the more difficult levels on Chrome
defaultCores = 2
cores = window.navigator.hardwareConcurrency or defaultCores # Available on Chrome/Opera, soon Safari

View file

@ -0,0 +1,5 @@
mongoose = require('mongoose')
config = require '../../server_config'
MandateSchema = new mongoose.Schema {}, {strict: false, read: config.mongo.readpref}
module.exports = mongoose.model('mandate', MandateSchema)

View file

@ -3,6 +3,7 @@ async = require 'async'
errors = require '../../commons/errors'
scoringUtils = require './scoringUtils'
LevelSession = require '../../levels/sessions/LevelSession'
Mandate = require '../../models/Mandate'
module.exports = getTwoGames = (req, res) ->
#return errors.unauthorized(res, 'You need to be logged in to get games.') unless req.user?.get('email')
@ -10,11 +11,15 @@ module.exports = getTwoGames = (req, res) ->
humansSessionID = req.body.humansGameID
ogresSessionID = req.body.ogresGameID
return getSpecificSessions res, humansSessionID, ogresSessionID if humansSessionID and ogresSessionID
options =
background: req.body.background
levelID: req.body.levelID
leagueID: req.body.leagueID
getRandomSessions req.user, options, sendSessionsResponse(res)
Mandate.findOne({}).cache(5 * 60 * 1000).exec (err, mandate) ->
if err then return errors.serverError res, "Error fetching our Mandate: #{err}"
if (throughputRatio = mandate?.get 'simulationThroughputRatio')? and Math.random() > throughputRatio
return sendSessionsResponse(res)(null, [])
options =
background: req.body.background
levelID: req.body.levelID
leagueID: req.body.leagueID
getRandomSessions req.user, options, sendSessionsResponse(res)
sessionSelectionString = 'team totalScore transpiledCode submittedCodeLanguage teamSpells levelID creatorName creator submitDate leagues'
@ -22,7 +27,6 @@ sendSessionsResponse = (res) ->
(err, sessions) ->
if err then return errors.serverError res, "Couldn't get two games to simulate: #{err}"
unless _.filter(sessions).length is 2
console.log 'No games to score.', sessions.length
res.send 204, 'No games to score.'
return res.end()
taskObject = messageGenerated: Date.now(), sessions: (scoringUtils.formatSessionInformation session for session in sessions)