mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Fixed queue bug and wrote tests
This commit is contained in:
parent
6f2461c8be
commit
45634e9413
2 changed files with 14 additions and 7 deletions
|
@ -99,7 +99,7 @@ class MongoQueueClient
|
|||
|
||||
###Public API###
|
||||
registerQueue: (queueName, options, callback) ->
|
||||
newQueue = new MongoQueue queueName,options,this
|
||||
newQueue = new MongoQueue queueName,options,@messageModel
|
||||
callback(null, newQueue)
|
||||
###Public API###
|
||||
|
||||
|
@ -107,7 +107,7 @@ class MongoQueueClient
|
|||
@databaseAddress = db.generateDatabaseAddress()
|
||||
@mongoDatabaseName = config.mongoQueue.queueDatabaseName;
|
||||
|
||||
createMongoConnection: ->
|
||||
createMongoConnection: ->
|
||||
@mongooseConnection = mongoose.createConnection "mongodb://#{@databaseAddress}/#{@mongoDatabaseName}"
|
||||
@mongooseConnection.on 'error', ->
|
||||
winston.error "There was an error connecting to the queue in MongoDB"
|
||||
|
@ -126,7 +126,10 @@ class MongoQueueClient
|
|||
|
||||
|
||||
class MongoQueue extends events.EventEmitter
|
||||
constructor: (@queueName, options, @Message) ->
|
||||
constructor: (queueName, options, messageModel) ->
|
||||
@Message = messageModel
|
||||
@queueName = queueName
|
||||
|
||||
|
||||
subscribe: (eventName, callback) -> @on eventName, callback
|
||||
unsubscribe: (eventName, callback) -> @removeListener eventName, callback
|
||||
|
@ -156,7 +159,6 @@ class MongoQueue extends events.EventEmitter
|
|||
processing: false
|
||||
queue: @queueName
|
||||
scheduledVisibilityTime: Date.now() + (delaySeconds * 1000)
|
||||
|
||||
messageToSend.save (err,data) =>
|
||||
if err? then @emit 'error',err,data else @emit 'sent',err, data
|
||||
callback? err,data
|
||||
|
|
|
@ -16,10 +16,15 @@ describe 'Queue', ->
|
|||
beforeEach ->
|
||||
config.isProduction = false
|
||||
mongoQueueClient = queues.generateQueueClient()
|
||||
config.isProduction = true
|
||||
sqsQueueClient = queues.generateQueueClient()
|
||||
|
||||
it 'should generate the correct type of queue', ->
|
||||
mongoQueueClient.registerQueue "TestQueue", {}, (err, data) ->
|
||||
expect(data.constructor.name).toEqual 'MongoQueue'
|
||||
|
||||
describe 'sendMessage', ->
|
||||
mongoQueueClient = queues.generateQueueClient()
|
||||
testQueue = null
|
||||
it 'should send and retrieve a message', (done) ->
|
||||
mongoQueueClient.registerQueue "TestQueue", {}, (err, data) ->
|
||||
testQueue = data
|
||||
testQueue.sendMessage {"Body":"WOOOO"} ,0, (err2, data2) ->
|
||||
done()
|
Loading…
Reference in a new issue