mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-25 00:28:31 -05:00
46 lines
2 KiB
CoffeeScript
46 lines
2 KiB
CoffeeScript
config = require '../../server_config'
|
|
log = require 'winston'
|
|
mongoose = require 'mongoose'
|
|
async = require 'async'
|
|
errors = require '../commons/errors'
|
|
aws = require 'aws-sdk'
|
|
db = require './../routes/db'
|
|
queues = require '../commons/queue'
|
|
LevelSession = require '../levels/sessions/LevelSession'
|
|
Level = require '../levels/Level'
|
|
User = require '../users/User'
|
|
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
|
|
queues.initializeQueueClient ->
|
|
queues.queueClient.registerQueue 'scoring', {}, (error, data) ->
|
|
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!'
|
|
|
|
module.exports.messagesInQueueCount = (req, res) ->
|
|
scoringUtils.scoringTaskQueue.totalMessagesInQueue (err, count) ->
|
|
if err? then return errors.serverError res, "There was an issue finding the Mongoose count:#{err}"
|
|
response = String(count)
|
|
res.send(response)
|
|
res.end()
|
|
|
|
module.exports.addPairwiseTaskToQueueFromRequest = (req, res) ->
|
|
taskPair = req.body.sessions
|
|
scoringUtils.addPairwiseTaskToQueue req.body.sessions, (err, success) ->
|
|
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
|