Put in configuration, aws-sdk, subclassing Queue

This commit is contained in:
Michael Schmatz 2014-01-22 18:29:02 -08:00
parent a62427fe34
commit 2373d97137
2 changed files with 66 additions and 2 deletions

View file

@ -3,15 +3,74 @@ winston = require 'winston'
mongoose = require 'mongoose'
async = require 'async'
errors = require './errors'
aws = require 'aws-sdk'
testing = '--unittest' in process.argv
queueInstance = undefined
module.exports.connect = ->
return
queueInstance = generateQueueInstance()
queueInstance.connect()
module.exports.connectToRemoteQueue = ->
return
module.exports.connectToLocalQueue = ->
return
return
generateQueueInstance = ->
if config.isProduction
return new RemoteQueue()
else
return new LocalQueue()
class Queue
constructor: ->
@configure()
configure: ->
return
connect: ->
throw new Error("Subclasses must override this method")
class RemoteQueue extends Queue
constructor: ->
super()
@sqs = @generateSQSInstance()
@testConnection()
configure: ->
super()
awsConfigurationObject =
accessKeyId: config.queue.accessKeyId
secretAccessKey: config.queue.secretAccessKey
region: config.queue.region
aws.config.update remoteConfigurationObject
generateSQSInstance: ->
return new aws.SQS()
testConnection: ->
@sqs.listQueues {}, (err, data) ->
if err?
winston.error "Error connecting to SQS, reason: #{err}"
throw new Error("Couldn't connect to SQS.")
else
winston.info "Connected to SQS!"
class LocalQueue extends Queue
constructor: ()->
super()
configure: () ->
super()

View file

@ -29,6 +29,11 @@ config.mail.password = process.env.COCO_MAIL_SERVICE_PASSWORD || "";
config.mail.mailchimpAPIKey = process.env.COCO_MAILCHIMP_API_KEY || '';
config.mail.sendwithusAPIKey = process.env.COCO_SENDWITHUS_API_KEY || '';
config.queue = {};
config.queue.accessKeyId = process.env.AWS_ACCESS_KEY_ID || '';
config.queue.secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY || '';
config.queue.region = 'us-east-1';
config.salt = process.env.COCO_SALT || 'pepper';
config.cookie_secret = process.env.COCO_COOKIE_SECRET || 'chips ahoy';