codecombat/server/queues/scoring.coffee

47 lines
2 KiB
CoffeeScript
Raw Normal View History

2014-02-05 12:39:14 -05:00
config = require '../../server_config'
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'
LevelSession = require '../models/LevelSession'
Level = require '../models/Level'
User = require '../models/User'
TaskLog = require './../models/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
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}"
scoringUtils.scoringTaskQueue = data
#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) ->
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
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}"
scoringUtils.sendResponseObject res, {message: 'All task pairs were succesfully sent to the queue'}
module.exports.getTwoGames = getTwoGames
module.exports.recordTwoGames = recordTwoGames
module.exports.createNewTask = createNewTask
module.exports.dispatchTaskToConsumer = dispatchTaskToConsumer
module.exports.processTaskResult = processTaskResult