Some work on making simulation unstoppable.

This commit is contained in:
Nick Winter 2014-12-09 09:00:34 -08:00
parent a97baa2207
commit 6f437d11b1
3 changed files with 25 additions and 6 deletions

View file

@ -10,7 +10,7 @@ module.exports = class Simulator extends CocoClass
@options ?= {}
_.extend @, Backbone.Events
@trigger 'statusUpdate', 'Starting simulation!'
@retryDelayInSeconds = 10
@retryDelayInSeconds = 2
@taskURL = '/queue/scoring'
@simulatedByYou = 0
@god = new God maxAngels: 1, workerCode: @options.workerCode, headless: true # Start loading worker.
@ -85,7 +85,11 @@ module.exports = class Simulator extends CocoClass
processSingleGameResults: (simulationResults) ->
return console.error "Weird, we destroyed the Simulator before it processed results?" if @destroyed
taskResults = @formTaskResultsObject simulationResults
try
taskResults = @formTaskResultsObject simulationResults
catch error
console.log "Failed to form task results:", error
return @cleanupAndSimulateAnotherTask()
console.log 'Processing results:', taskResults
humanSessionRank = taskResults.sessions[0].metrics.rank
ogreSessionRank = taskResults.sessions[1].metrics.rank
@ -237,7 +241,11 @@ module.exports = class Simulator extends CocoClass
processResults: (simulationResults) ->
return console.error "Weird, we destroyed the Simulator before it processed results?" if @destroyed
taskResults = @formTaskResultsObject simulationResults
try
taskResults = @formTaskResultsObject simulationResults
catch error
console.log "Failed to form task results:", error
return @cleanupAndSimulateAnotherTask()
unless taskResults.taskID
console.error "*** Error: taskResults has no taskID ***\ntaskResults:", taskResults
@cleanupAndSimulateAnotherTask()

View file

@ -48,7 +48,7 @@ block content
strong Variables
| - adds the skill of referencing values that change over time.
p Students may continue past level 12, depending on their speed and interest, to learn two additional concepts in later levels:
p Students may continue past level 20, depending on their speed and interest, to learn two additional concepts in later levels:
ol
li
strong Conditional logic

View file

@ -27,6 +27,8 @@ module.exports = class SimulateTabView extends CocoView
onLoaded: ->
super()
@render()
if document.location.hash is '#simulate' and not @simulator
@startSimulating()
getRenderData: ->
ctx = super()
@ -43,9 +45,18 @@ module.exports = class SimulateTabView extends CocoView
onSimulateButtonClick: (e) ->
application.tracker?.trackEvent 'Simulate Button Click', {}
@startSimulating
startSimulating: ->
@simulationPageRefreshTimeout = _.delay @refreshAndContinueSimulating, 20 * 60 * 1000
@simulateNextGame()
$('#simulate-button').prop 'disabled', true
$('#simulate-button').text 'Simulating...'
@simulateNextGame()
refreshAndContinueSimulating: =>
# We refresh the page every now and again to make sure simulations haven't gotten derailed by bogus games, and that simulators don't hang on to old, stale code or data.
document.location.hash = '#simulate'
document.location.reload()
simulateNextGame: ->
unless @simulator
@ -101,7 +112,7 @@ module.exports = class SimulateTabView extends CocoView
console.log jqxhr.responseText
destroy: ->
clearInterval @refreshInterval
clearTimeout @simulationPageRefreshTimeout
@simulator?.destroy()
super()