Simulator handles when there are no Greed matches to randomly simulate.

This commit is contained in:
Nick Winter 2014-06-27 08:50:04 -07:00
parent 802d43651e
commit 58bf85d234
2 changed files with 10 additions and 0 deletions
app/lib/simulator
server/queues

View file

@ -37,6 +37,10 @@ module.exports = class Simulator extends CocoClass
console.warn "There was an error fetching two games! #{JSON.stringify errorData}"
success: (taskData) =>
return if @destroyed
unless taskData
@trigger 'statusUpdate', "No games to simulate. Trying another game in #{@retryDelayInSeconds} seconds."
@simulateAnotherTaskAfterDelay()
return
@trigger 'statusUpdate', 'Setting up simulation...'
#refactor this
@task = new SimulationTask(taskData)

View file

@ -138,6 +138,9 @@ module.exports.getTwoGames = (req, res) ->
selection = "team totalScore transpiledCode submittedCodeLanguage teamSpells levelID creatorName creator submitDate"
LevelSession.count queryParams, (err, numberOfHumans) =>
if err? then return errors.serverError(res, "Couldn't get the number of human games")
unless numberOfHumans
res.send(204, "No games to score.")
return res.end()
humanSkipCount = Math.floor(Math.random() * numberOfHumans)
ogreCountParams =
"levelID": "greed"
@ -145,6 +148,9 @@ module.exports.getTwoGames = (req, res) ->
"team":"ogres"
LevelSession.count ogreCountParams, (err, numberOfOgres) =>
if err? then return errors.serverError(res, "Couldnt' get the number of ogre games")
unless numberOfOgres
res.send(204, "No games to score.")
return res.end()
ogresSkipCount = Math.floor(Math.random() * numberOfOgres)
query = LevelSession