Class: HerokuDroid
Constant Summary
Constants inherited from Droid
Instance Attribute Summary collapse
-
#extended_stats ⇒ Object
readonly
Returns the value of attribute extended_stats.
Instance Method Summary collapse
- #call_stats ⇒ Object
-
#initialize(name, opts = {}, &blk) ⇒ HerokuDroid
constructor
A new instance of HerokuDroid.
- #name ⇒ Object
- #ruby_path ⇒ Object
- #setup_ping_topic(droid) ⇒ Object
- #setup_standard_topics(droid) ⇒ Object
- #stats(&blk) ⇒ Object
Methods inherited from Droid
bunny, call, closing?, default_config, gen_queue, handle_error, log, #log, log=, name, name=, pop, publish, #publish, publish_to_ex, publish_to_q, reconnect_on_error, reply_to_q, reset_bunny, start, stop_safe, version, wait_for_tcp_port
Methods included from Droid::EMTimerUtils
included, #periodic_timer, #timer
Methods included from Droid::BackwardsCompatibleMethods
Methods included from Droid::QueueMethods
Constructor Details
#initialize(name, opts = {}, &blk) ⇒ HerokuDroid
Returns a new instance of HerokuDroid.
29 30 31 32 33 34 35 36 37 |
# File 'lib/droid/heroku.rb', line 29 def initialize(name, opts={}, &blk) @extended_stats = !(opts[:extended_stats] == false) super(name, opts) do |droid| setup_standard_topics(self) unless opts[:standard_topics] == false LocalStats.attach blk.call(self) end end |
Instance Attribute Details
#extended_stats ⇒ Object (readonly)
Returns the value of attribute extended_stats.
27 28 29 |
# File 'lib/droid/heroku.rb', line 27 def extended_stats @extended_stats end |
Instance Method Details
#call_stats ⇒ Object
46 47 48 |
# File 'lib/droid/heroku.rb', line 46 def call_stats @stats ? @stats.call : nil end |
#ruby_path ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/droid/heroku.rb', line 54 def ruby_path if File.exists?("/usr/ruby1.8.6/bin/ruby") "/usr/ruby1.8.6/bin" else "/usr/local/bin" end end |
#setup_ping_topic(droid) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/droid/heroku.rb', line 66 def setup_ping_topic(droid) require 'time' droid.listener('ping').subscribe do |req| Droid::Utilization.latency = (Time.now.to_f - req['departed_at']).abs end blk = Proc.new do |d| begin t1 = Time.now response = {}.merge(LocalStats.stats) estats = nil if self.extended_stats estats = droid.call_stats estats = { :notes => estats } unless estats.kind_of?(Hash) estats[:notes] ||= estats.map { |k, v| "#{v} #{k}" }.join(", ") estats.merge!(LocalStats.extended_stats) end response.merge!({ :extended_stats => estats, :droid_name => Droid.name, :latency => Droid::Utilization.latency, }) d.publish('pong', response.merge(:stat_collection => (Time.now - t1))) rescue Object => e log.error "Ping Block Error: #{e.class} -> #{e.}", :exception => e end end EM.add_timer(2) { blk.call(droid) } EM.add_periodic_timer(50 + (rand*15).to_i) { blk.call(droid) } end |
#setup_standard_topics(droid) ⇒ Object
62 63 64 |
# File 'lib/droid/heroku.rb', line 62 def setup_standard_topics(droid) setup_ping_topic(droid) end |