mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Put in configuration, aws-sdk, subclassing Queue
This commit is contained in:
parent
a62427fe34
commit
2373d97137
2 changed files with 66 additions and 2 deletions
|
@ -3,11 +3,15 @@ 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 = ->
|
||||
|
@ -15,3 +19,58 @@ module.exports.connectToRemoteQueue = ->
|
|||
|
||||
module.exports.connectToLocalQueue = ->
|
||||
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()
|
||||
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
Loading…
Reference in a new issue