2014-02-05 12:39:14 -05:00
|
|
|
config = require '../../server_config'
|
2014-02-10 16:18:39 -05:00
|
|
|
log = require 'winston'
|
2014-02-05 12:39:14 -05:00
|
|
|
mongoose = require 'mongoose'
|
|
|
|
async = require 'async'
|
|
|
|
errors = require '../commons/errors'
|
|
|
|
aws = require 'aws-sdk'
|
2014-02-06 16:25:11 -05:00
|
|
|
db = require './../routes/db'
|
2014-02-05 12:39:14 -05:00
|
|
|
queues = require '../commons/queue'
|
2014-02-05 18:07:15 -05:00
|
|
|
LevelSession = require '../levels/sessions/LevelSession'
|
2014-03-07 21:16:48 -05:00
|
|
|
Level = require '../levels/Level'
|
2014-03-20 18:40:02 -04:00
|
|
|
User = require '../users/User'
|
2015-08-13 14:17:38 -04:00
|
|
|
TaskLog = require './scoring/ScoringTask'
|
|
|
|
scoringUtils = require './scoring/scoringUtils'
|
|
|
|
getTwoGames = require './scoring/getTwoGames'
|
|
|
|
recordTwoGames = require './scoring/recordTwoGames'
|
|
|
|
createNewTask = require './scoring/createNewTask'
|
|
|
|
dispatchTaskToConsumer = require './scoring/dispatchTaskToConsumer'
|
|
|
|
processTaskResult = require './scoring/processTaskResult'
|
|
|
|
|
|
|
|
module.exports.setup = (app) ->
|
|
|
|
# Connect to scoring queue
|
2014-02-06 17:32:35 -05:00
|
|
|
queues.initializeQueueClient ->
|
2014-06-30 22:16:26 -04:00
|
|
|
queues.queueClient.registerQueue 'scoring', {}, (error, data) ->
|
2014-07-13 11:18:55 -04:00
|
|
|
if error? then throw new Error "There was an error registering the scoring queue: #{error}"
|
2015-08-13 14:17:38 -04:00
|
|
|
scoringUtils.scoringTaskQueue = data
|
2014-11-25 12:28:42 -05:00
|
|
|
#log.info 'Connected to scoring task queue!'
|
2014-03-20 18:40:02 -04:00
|
|
|
|
2014-03-15 12:20:13 -04:00
|
|
|
module.exports.messagesInQueueCount = (req, res) ->
|
2015-08-13 14:17:38 -04:00
|
|
|
scoringUtils.scoringTaskQueue.totalMessagesInQueue (err, count) ->
|
2014-03-15 12:20:13 -04:00
|
|
|
if err? then return errors.serverError res, "There was an issue finding the Mongoose count:#{err}"
|
2014-03-15 12:40:58 -04:00
|
|
|
response = String(count)
|
2014-03-15 12:20:13 -04:00
|
|
|
res.send(response)
|
|
|
|
res.end()
|
|
|
|
|
2014-02-26 15:14:02 -05:00
|
|
|
module.exports.addPairwiseTaskToQueueFromRequest = (req, res) ->
|
2014-02-24 10:50:43 -05:00
|
|
|
taskPair = req.body.sessions
|
2015-08-13 14:17:38 -04:00
|
|
|
scoringUtils.addPairwiseTaskToQueue req.body.sessions, (err, success) ->
|
2014-02-26 15:14:02 -05:00
|
|
|
if err? then return errors.serverError res, "There was an error adding pairwise tasks: #{err}"
|
2015-08-15 08:38:47 -04:00
|
|
|
scoringUtils.sendResponseObject res, {message: 'All task pairs were succesfully sent to the queue'}
|
2014-05-19 17:59:43 -04:00
|
|
|
|
2015-02-11 23:24:12 -05:00
|
|
|
|
2015-08-13 14:17:38 -04:00
|
|
|
module.exports.getTwoGames = getTwoGames
|
|
|
|
module.exports.recordTwoGames = recordTwoGames
|
|
|
|
module.exports.createNewTask = createNewTask
|
|
|
|
module.exports.dispatchTaskToConsumer = dispatchTaskToConsumer
|
|
|
|
module.exports.processTaskResult = processTaskResult
|