From 671f6d6ffda5effc0fe2c72604f941d450a198e4 Mon Sep 17 00:00:00 2001 From: Michael Schmatz Date: Wed, 22 Jan 2014 23:48:47 -0800 Subject: [PATCH] Refactored and simplified --- server/queue.coffee | 50 ++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/server/queue.coffee b/server/queue.coffee index 5eb498bc4..c6e15a957 100644 --- a/server/queue.coffee +++ b/server/queue.coffee @@ -33,23 +33,32 @@ class AbstractQueue throw new Error "Subclasses must override the createSimulationQueue method" - - class RemoteQueue extends AbstractQueue constructor: (queueName) -> @configure() @sqs = @generateSQSInstance() @createSimulationQueueAndSetUrl queueName, (err, data) => - @sendMessage "This is a new test message",5, (error,data) -> - if err? - winston.error "#{JSON.stringify error}" @enterReceieveMessageForeverLoop() - - - configure: -> - aws.config.update @generateAWSConfigurationObject() + aws.config.update + accessKeyId: config.queue.accessKeyId + secretAccessKey: config.queue.secretAccessKey + region: config.queue.region + + generateSQSInstance: -> + new aws.SQS() + + createSimulationQueueAndSetUrl: (queueName, callback) -> + @sqs.createQueue {QueueName: queueName}, (err, data) => + if err? + throw new Error "Failed to create queue \"#{queueName}\"" + else + winston.info "Created queue, URL is #{data.QueueUrl}" + @queueUrl = data.QueueUrl + callback?(err,data) + + enterReceieveMessageForeverLoop: -> async.forever (asyncCallback) => @@ -62,20 +71,8 @@ class RemoteQueue extends AbstractQueue winston.info "Deleting message..." @deleteMessage data.Messages?[0].ReceiptHandle, -> winston.info "Deleted message!" - else - winston.info "No messages to receieve" asyncCallback(null) - createSimulationQueueAndSetUrl: (queueName, callback) -> - @sqs.createQueue {QueueName: queueName}, (err, data) => - if err? - throw new Error "Failed to create queue \"#{queueName}\"" - else - winston.info "Created queue, URL is #{data.QueueUrl}" - @queueUrl = data.QueueUrl - callback?(err,data) - - receiveMessage: (callback) -> @sqs.receiveMessage {QueueUrl: @queueUrl, WaitTimeSeconds: 20}, callback @@ -86,17 +83,6 @@ class RemoteQueue extends AbstractQueue @sqs.sendMessage {QueueUrl: @queueUrl, MessageBody: messageBody, DelaySeconds: delaySeconds}, callback - generateAWSConfigurationObject: -> - awsConfigurationObject = - accessKeyId: config.queue.accessKeyId - secretAccessKey: config.queue.secretAccessKey - region: config.queue.region - - - generateSQSInstance: -> - new aws.SQS() - - class LocalQueue extends AbstractQueue