Class: DynoBattery
- Inherits:
-
Object
- Object
- DynoBattery
- Defined in:
- lib/dynobattery.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #get_dynos ⇒ Object
-
#initialize(app) ⇒ DynoBattery
constructor
A new instance of DynoBattery.
Constructor Details
#initialize(app) ⇒ DynoBattery
Returns a new instance of DynoBattery.
2 3 4 |
# File 'lib/dynobattery.rb', line 2 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dynobattery.rb', line 6 def call(env) uri = URI.parse("http://dyno-battery.heroku.com/") http = Net::HTTP.new(uri.host, uri.port) http.open_timeout = 3 http.read_timeout = 3 start = Time.now status, headers, response = @app.call(env) stop = Time.now if stop.min == 40 get_dynos http.post("/heroku","name=#{DYNO_DOMAIN}&date=#{start.to_s}&time=#{"%10.6f" % (stop - start)}&dyno=#{@dynos}") else http.post("/heroku","name=#{DYNO_DOMAIN}&date=#{start.to_s}&time=#{"%10.6f" % (stop - start)}") end [status, headers, response] end |
#get_dynos ⇒ Object
24 25 26 27 |
# File 'lib/dynobattery.rb', line 24 def get_dynos heroku = Heroku::Client.new(DYNO_USER, DYNO_PASSWORD) @dynos = heroku.info(DYNO_DOMAIN)[:dynos] end |