Class: SpeakingApps::MessageQueue
- Inherits:
-
Object
- Object
- SpeakingApps::MessageQueue
- Defined in:
- lib/speaking_apps/message_queue.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#remote_queue ⇒ Object
Returns the value of attribute remote_queue.
Instance Method Summary collapse
- #add(message, *attr) ⇒ Object
-
#environment_valid? ⇒ Boolean
:nodoc#.
-
#initialize(environment = nil) ⇒ MessageQueue
constructor
A new instance of MessageQueue.
- #ping ⇒ Object
- #store_in_remote_service_queue(message_with_options = {}) ⇒ Object
Constructor Details
#initialize(environment = nil) ⇒ MessageQueue
Returns a new instance of MessageQueue.
10 11 12 |
# File 'lib/speaking_apps/message_queue.rb', line 10 def initialize(environment = nil) @environment = environment end |
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
8 9 10 |
# File 'lib/speaking_apps/message_queue.rb', line 8 def environment @environment end |
#remote_queue ⇒ Object
Returns the value of attribute remote_queue.
7 8 9 |
# File 'lib/speaking_apps/message_queue.rb', line 7 def remote_queue @remote_queue end |
Instance Method Details
#add(message, *attr) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/speaking_apps/message_queue.rb', line 14 def add(, *attr) if environment_valid? store_in_remote_service_queue({ :message => , :tags => attr, :environment => @environment, :token => SpeakingApps::Config.token, :host => SpeakingApps::Config.host, :port => SpeakingApps::Config.port }) end end |
#environment_valid? ⇒ Boolean
:nodoc#
53 54 55 |
# File 'lib/speaking_apps/message_queue.rb', line 53 def environment_valid? #:nodoc# @environment.nil? || ::SpeakingApps::Config.environments.include?(@environment) end |
#ping ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/speaking_apps/message_queue.rb', line 27 def ping begin Timeout::timeout(2) do hub_url = URI.parse('http://127.0.0.1:28128/ping') response = Net::HTTP.start(hub_url.host, hub_url.port) { |http| http.get(hub_url.path) } return response.body == 'pong' end rescue => error return false end end |
#store_in_remote_service_queue(message_with_options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/speaking_apps/message_queue.rb', line 39 def store_in_remote_service_queue( = {}) # begin Timeout::timeout(2) do hub_url = URI.parse('http://127.0.0.1:28128/messages') response = Net::HTTP.start(hub_url.host, hub_url.port) do |http| http.post(hub_url.path, .to_json) end return response == Net::HTTPCreated end # rescue => error # return false # end end |