Added scoring and queue modules

This commit is contained in:
Michael Schmatz 2014-02-05 09:39:14 -08:00
parent 7f5b3e5f75
commit 5c328d09f5
7 changed files with 47 additions and 79 deletions

View file

@ -20,9 +20,6 @@ module.exports = class CocoRouter extends Backbone.Router
'db/*path': 'routeToServer'
'file/*path': 'routeToServer'
#multiplayer routes
'scoring/queue': 'routeToServer'
'play/level/:levelID/leaderboard/:teamID/:startRank/:endRank': 'getPaginatedLevelRank'
'play/level/:levelID/player/:playerID': 'getPlayerLevelInfo'

View file

@ -1,10 +1,10 @@
config = require '../server_config'
config = require '../../server_config'
winston = require 'winston'
mongoose = require 'mongoose'
async = require 'async'
errors = require './commons/errors'
errors = require './errors'
aws = require 'aws-sdk'
db = require './routes/db'
db = require './../routes/db'
mongoose = require 'mongoose'
events = require 'events'

View file

@ -1,27 +0,0 @@
config = require '../server_config'
winston = require 'winston'
mongoose = require 'mongoose'
async = require 'async'
errors = require './commons/errors'
aws = require 'aws-sdk'
db = require './routes/db'
mongoose = require 'mongoose'
events = require 'events'
queues = require 'queue'
module.exports.connectToScoringQueue = -> queues.initializeScoringTaskQueue() unless queues.scoringTaskQueue?
module.exports.setupRoutes = (app) ->
return
module.exports.setupRoutes = (app) ->
app.all '/multiplayer/*', (req, res) ->
unless scoringTaskQueue?
errors.custom res, 503, "Currently initializing scoring queue"
return

View file

@ -1,45 +0,0 @@
queues = require './queue'
config = require '../server_config.js'
winston = require 'winston'
describe 'Queue', ->
describe 'construction interface', ->
it 'should construct a MongoQueueClient if not in production', ->
config.isProduction = false
queue = queues.generateQueueClient()
expect(queue.constructor.name).toEqual 'MongoQueueClient'
it 'should construct an SQSQueueClient if in production', ->
config.isProduction = true
queue = queues.generateQueueClient()
expect(queue.constructor.name).toEqual 'SQSQueueClient'
describe 'registerQueue', ->
mongoQueueClient = null
sqsQueueClient = null
beforeEach ->
config.isProduction = false
mongoQueueClient = queues.generateQueueClient()
it 'should generate the correct type of queue', (done) ->
mongoQueueClient.registerQueue "TestQueue", {}, (err, data) ->
expect(data.constructor.name).toEqual 'MongoQueue'
done()
describe 'messages', ->
mongoQueueClient = queues.generateQueueClient()
testQueue = null
messageIdToDelete = null
it 'should send a message', (done) ->
mongoQueueClient.registerQueue "TestQueue", {}, (err, data) ->
testQueue = data
testQueue.sendMessage {"Body":"This is a test message"} ,0, (err2, data2) ->
done()
it 'should receieve a message', (done) ->
testQueue.receieveMessage (err,data) ->
winston.info "Data body is #{data.Body}"
expect(data.Body).toBe "This is a test message"
messageIdToDelete = data._id
done()
it 'should delete a message', (done) ->
expect(true).toBeTruthy()
done()

View file

@ -0,0 +1,41 @@
config = require '../../server_config'
winston = require 'winston'
mongoose = require 'mongoose'
async = require 'async'
errors = require '../commons/errors'
aws = require 'aws-sdk'
db = require './db'
mongoose = require 'mongoose'
events = require 'events'
queues = require '../commons/queue'
module.exports.connectToScoringQueue = -> queues.initializeScoringTaskQueue() unless queues.scoringTaskQueue?
module.exports.setupRoutes = (app) ->
app.get '/scoring/queue', (req,res) ->
#must also include the
queues.scoringTaskQueue.receieveMessage (err, data) ->
#once the data is recieved
levelAndUserCodeMapResponse = {}
sendResponseObject req,res,levelAndUserCodeMapResponse
app.post '/scoring/queue', (req, res) ->
clientResponseObject = req.body
res.end("You posted an object to score!")
sendResponseObject = (req,res,object) ->
res.setHeader('Content-Type', 'application/json')
res.send(object)
res.end()
constructTaskObject = (data, callback) ->
#task includes session ID,

View file

@ -1,7 +1,7 @@
config = require '../server_config'
sendwithusAPI = require 'sendwithus'
swuAPIKey = config.mail.sendwithusAPIKey
queues = require './queue'
queues = require './commons/queue'
module.exports.setupQueue = -> queues.initializeSendwithusQueue() unless queues.sendwithusQueue?

View file

@ -14,6 +14,7 @@ sprites = require './server/routes/sprites'
contact = require './server/routes/contact'
languages = require './server/routes/languages'
mail = require './server/routes/mail'
scoring = require './server/routes/scoring'
config = require './server_config'
@ -94,6 +95,7 @@ exports.setupRoutes = (app) ->
folder.setupRoutes app
languages.setupRoutes app
mail.setupRoutes app
scoring.setupRoutes app
setupFacebookCrossDomainCommunicationRoute app
setupFallbackRouteToIndex app