Class: CloudFormation::Bridge::Poller
- Inherits:
-
Object
- Object
- CloudFormation::Bridge::Poller
- Defined in:
- lib/cloud_formation/bridge/poller.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
Instance Method Summary collapse
-
#initialize(queue_name, executor = CloudFormation::Bridge::Executor.new, logger = Logger.new(STDOUT)) ⇒ Poller
constructor
A new instance of Poller.
- #poll ⇒ Object
- #queue ⇒ Object
- #sqs ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #visible_messages ⇒ Object
Constructor Details
#initialize(queue_name, executor = CloudFormation::Bridge::Executor.new, logger = Logger.new(STDOUT)) ⇒ Poller
Returns a new instance of Poller.
12 13 14 15 16 |
# File 'lib/cloud_formation/bridge/poller.rb', line 12 def initialize(queue_name, executor = CloudFormation::Bridge::Executor.new, logger = Logger.new(STDOUT)) @queue_name = queue_name @executor = executor @logger = logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/cloud_formation/bridge/poller.rb', line 10 def logger @logger end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
10 11 12 |
# File 'lib/cloud_formation/bridge/poller.rb', line 10 def running @running end |
Instance Method Details
#poll ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cloud_formation/bridge/poller.rb', line 29 def poll = queue. return unless begin logger.info("Received message #{message.id} - #{message.body}") body = JSON.parse(.body) request = CloudFormation::Bridge::Request.new(JSON.parse(body["Message"])) @executor.execute(request) .delete logger.info("Processed message #{message.id}") rescue => ex logger.info("Failed to process message #{message.id} - #{ex.message}") ExceptionNotifier.report_exception(ex, message: .body, handle: .handle, id: .id, queue: @queue_name, ) end end |
#queue ⇒ Object
57 58 59 |
# File 'lib/cloud_formation/bridge/poller.rb', line 57 def queue @queue ||= sqs.queues.named(@queue_name) end |
#sqs ⇒ Object
61 62 63 |
# File 'lib/cloud_formation/bridge/poller.rb', line 61 def sqs @sqs ||= AWS::SQS.new end |
#start ⇒ Object
18 19 20 21 22 23 |
# File 'lib/cloud_formation/bridge/poller.rb', line 18 def start @running = true while @running poll end end |
#stop ⇒ Object
25 26 27 |
# File 'lib/cloud_formation/bridge/poller.rb', line 25 def stop @running = false end |
#visible_messages ⇒ Object
53 54 55 |
# File 'lib/cloud_formation/bridge/poller.rb', line 53 def queue. end |