Class: Trusty::IronIo::QueueProcessor
- Inherits:
-
Object
- Object
- Trusty::IronIo::QueueProcessor
- Includes:
- Errors::ExceptionHandlers
- Defined in:
- lib/trusty/iron_io/queue_processor.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#queue_name ⇒ Object
readonly
Returns the value of attribute queue_name.
Class Method Summary collapse
-
.run(queue_name, *args, &block) ⇒ Object
helper method forwards to “run” instance method.
Instance Method Summary collapse
- #default_options ⇒ Object
-
#initialize(queue_name) ⇒ QueueProcessor
constructor
A new instance of QueueProcessor.
- #queue ⇒ Object
- #run(options = {}, &block) ⇒ Object
- #webhook_url ⇒ Object
Methods included from Errors::ExceptionHandlers
#notify_exception, #try_with_data
Constructor Details
#initialize(queue_name) ⇒ QueueProcessor
Returns a new instance of QueueProcessor.
16 17 18 19 |
# File 'lib/trusty/iron_io/queue_processor.rb', line 16 def initialize(queue_name) @queue_name = queue_name @client = IronMQ::Client.new(:token => ENV['IRON_TOKEN'], :project_id => ENV['IRON_PROJECT_ID']) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
14 15 16 |
# File 'lib/trusty/iron_io/queue_processor.rb', line 14 def client @client end |
#queue_name ⇒ Object (readonly)
Returns the value of attribute queue_name.
14 15 16 |
# File 'lib/trusty/iron_io/queue_processor.rb', line 14 def queue_name @queue_name end |
Class Method Details
.run(queue_name, *args, &block) ⇒ Object
helper method forwards to “run” instance method
10 11 12 |
# File 'lib/trusty/iron_io/queue_processor.rb', line 10 def self.run(queue_name, *args, &block) new(queue_name).run(*args, &block) end |
Instance Method Details
#default_options ⇒ Object
21 22 23 |
# File 'lib/trusty/iron_io/queue_processor.rb', line 21 def { :timeout => 30, :break_if_nil => true } end |
#queue ⇒ Object
25 26 27 |
# File 'lib/trusty/iron_io/queue_processor.rb', line 25 def queue @queue ||= client.queue(queue_name) end |
#run(options = {}, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/trusty/iron_io/queue_processor.rb', line 29 def run( = {}, &block) = .merge() queue.poll() do ||#, :break_if_nil => true do |message| # parse body for better data formatting begin body = JSON.parse .body rescue JSON::ParserError => ex body = .body end try_with_data :message_id => .id, :body => body do block.call(, queue) end end end |
#webhook_url ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/trusty/iron_io/queue_processor.rb', line 47 def webhook_url url_template = 'https://mq-aws-us-east-1.iron.io/1/projects/%{project_id}/queues/%{queue_name}/messages/webhook?oauth=%{token}' url_template % { project_id: ENV['IRON_TOKEN'], token: ENV['IRON_PROJECT_ID'], queue_name: queue_name } end |