Class: EbxDeliver::AwsSqsReader

Inherits:
Object
  • Object
show all
Defined in:
lib/ebx_deliver/aws_sqs_reader.rb

Instance Method Summary collapse

Constructor Details

#initializeAwsSqsReader

Returns a new instance of AwsSqsReader.



4
5
6
7
8
# File 'lib/ebx_deliver/aws_sqs_reader.rb', line 4

def initialize
  # TODO pull name from settings
  @queue = AWS.sqs.queues.named('write-development-sqs')
  @db = AWS::DynamoDB.new
end

Instance Method Details

#connect!Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ebx_deliver/aws_sqs_reader.rb', line 19

def connect!
  # TODO remove poll to avoid autodelete
  @queue.poll do |notification|
    msg = JSON.parse(JSON.parse(notification.body)['Message'])
    puts "MSG Received #{msg}"

    response = @db.client.send(msg['method'], msg['args'])
    puts "RESPONSE #{response.data}"

    response_pool.publish({
      request_id: msg['request_id'],
      response: response.http_response
    }.to_json)

    notification.delete
  end
end

#response_poolObject

TODO Fix



11
12
13
14
15
16
17
# File 'lib/ebx_deliver/aws_sqs_reader.rb', line 11

def response_pool
  r = AWS.config.region
  AWS.config(region: 'us-west-2')
  @command_notifications ||= AWS.sns.topics.create('read-development-sns')
ensure
  AWS.config(region: r)
end