mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Scheduling fixes
This commit is contained in:
parent
94b98a2d46
commit
81466675ec
1 changed files with 43 additions and 34 deletions
|
@ -108,39 +108,48 @@ module.exports.processTaskResult = (req, res) ->
|
||||||
console.log "Deleted message."
|
console.log "Deleted message."
|
||||||
if err? then return errors.badInput res, "The queue message is already back in the queue, rejecting results."
|
if err? then return errors.badInput res, "The queue message is already back in the queue, rejecting results."
|
||||||
|
|
||||||
logTaskComputation clientResponseObject, taskLog, (logErr) ->
|
LevelSession.findOne(_id: clientResponseObject.originalSessionID).lean().exec (err, levelSession) ->
|
||||||
if logErr? then return errors.serverError res, "There as a problem logging the task computation: #{logErr}"
|
if err? then return errors.serverError res, "There was a problem finding the level session:#{err}"
|
||||||
|
|
||||||
updateSessions clientResponseObject, (updateError, newScoreArray) ->
|
console.log "Queue message created at: #{taskLogJSON.createdAt}, level session submitted at #{levelSession.submitDate}"
|
||||||
if updateError? then return errors.serverError res, "There was an error updating the scores.#{updateError}"
|
|
||||||
|
|
||||||
newScoresObject = _.indexBy newScoreArray, 'id'
|
if taskLogJSON.createdAt <= levelSession.submitDate
|
||||||
|
console.log "Task has been resubmitted!"
|
||||||
|
return sendResponseObject req, res, {"message":"The game has been resubmitted. Removing from queue..."}
|
||||||
|
|
||||||
addMatchToSessions clientResponseObject, newScoresObject, (err, data) ->
|
logTaskComputation clientResponseObject, taskLog, (logErr) ->
|
||||||
if err? then return errors.serverError res, "There was an error updating the sessions with the match! #{JSON.stringify err}"
|
if logErr? then return errors.serverError res, "There as a problem logging the task computation: #{logErr}"
|
||||||
|
|
||||||
originalSessionID = clientResponseObject.originalSessionID
|
updateSessions clientResponseObject, (updateError, newScoreArray) ->
|
||||||
originalSessionTeam = clientResponseObject.originalSessionTeam
|
if updateError? then return errors.serverError res, "There was an error updating the scores.#{updateError}"
|
||||||
originalSessionRank = parseInt clientResponseObject.originalSessionRank
|
|
||||||
|
|
||||||
determineIfSessionShouldContinueAndUpdateLog originalSessionID, originalSessionRank, (err, sessionShouldContinue) ->
|
newScoresObject = _.indexBy newScoreArray, 'id'
|
||||||
if err? then return errors.serverError res, "There was an error determining if the session should continue, #{err}"
|
|
||||||
|
|
||||||
if sessionShouldContinue
|
addMatchToSessions clientResponseObject, newScoresObject, (err, data) ->
|
||||||
opposingTeam = calculateOpposingTeam(originalSessionTeam)
|
if err? then return errors.serverError res, "There was an error updating the sessions with the match! #{JSON.stringify err}"
|
||||||
opponentID = _.pull(_.keys(newScoresObject), originalSessionID)
|
|
||||||
sessionNewScore = newScoresObject[originalSessionID].totalScore
|
|
||||||
opponentNewScore = newScoresObject[opponentID].totalScore
|
|
||||||
findNearestBetterSessionID originalSessionID, sessionNewScore, opponentNewScore, opponentID ,opposingTeam, (err, opponentSessionID) ->
|
|
||||||
if err? then return errors.serverError res, "There was an error finding the nearest sessionID!"
|
|
||||||
unless opponentSessionID then return sendResponseObject req, res, {"message":"There were no more games to rank(game is at top!"}
|
|
||||||
|
|
||||||
addPairwiseTaskToQueue [originalSessionID, opponentSessionID], (err, success) ->
|
originalSessionID = clientResponseObject.originalSessionID
|
||||||
if err? then return errors.serverError res, "There was an error sending the pairwise tasks to the queue!"
|
originalSessionTeam = clientResponseObject.originalSessionTeam
|
||||||
sendResponseObject req, res, {"message":"The scores were updated successfully and more games were sent to the queue!"}
|
originalSessionRank = parseInt clientResponseObject.originalSessionRank
|
||||||
else
|
|
||||||
console.log "Player lost, achieved rank #{originalSessionRank}"
|
determineIfSessionShouldContinueAndUpdateLog originalSessionID, originalSessionRank, (err, sessionShouldContinue) ->
|
||||||
sendResponseObject req, res, {"message":"The scores were updated successfully, person lost so no more games are being inserted!"}
|
if err? then return errors.serverError res, "There was an error determining if the session should continue, #{err}"
|
||||||
|
|
||||||
|
if sessionShouldContinue
|
||||||
|
opposingTeam = calculateOpposingTeam(originalSessionTeam)
|
||||||
|
opponentID = _.pull(_.keys(newScoresObject), originalSessionID)
|
||||||
|
sessionNewScore = newScoresObject[originalSessionID].totalScore
|
||||||
|
opponentNewScore = newScoresObject[opponentID].totalScore
|
||||||
|
findNearestBetterSessionID originalSessionID, sessionNewScore, opponentNewScore, opponentID ,opposingTeam, (err, opponentSessionID) ->
|
||||||
|
if err? then return errors.serverError res, "There was an error finding the nearest sessionID!"
|
||||||
|
unless opponentSessionID then return sendResponseObject req, res, {"message":"There were no more games to rank(game is at top!"}
|
||||||
|
|
||||||
|
addPairwiseTaskToQueue [originalSessionID, opponentSessionID], (err, success) ->
|
||||||
|
if err? then return errors.serverError res, "There was an error sending the pairwise tasks to the queue!"
|
||||||
|
sendResponseObject req, res, {"message":"The scores were updated successfully and more games were sent to the queue!"}
|
||||||
|
else
|
||||||
|
console.log "Player lost, achieved rank #{originalSessionRank}"
|
||||||
|
sendResponseObject req, res, {"message":"The scores were updated successfully, person lost so no more games are being inserted!"}
|
||||||
|
|
||||||
|
|
||||||
determineIfSessionShouldContinueAndUpdateLog = (sessionID, sessionRank, cb) ->
|
determineIfSessionShouldContinueAndUpdateLog = (sessionID, sessionRank, cb) ->
|
||||||
|
|
Loading…
Reference in a new issue