lib/heroku/scalr/app.rb in heroku-scalr-0.2.3 vs lib/heroku/scalr/app.rb in heroku-scalr-0.2.4
- old
+ new
@@ -10,11 +10,11 @@
ping_high: 500,
metric: :ping,
min_frequency: 60
}.freeze
- attr_reader :name, :url, :api, :interval, :min_dynos, :max_dynos,
+ attr_reader :name, :url, :api_key, :interval, :min_dynos, :max_dynos,
:metric, :wait_low, :wait_high, :ping_low, :ping_high,
:min_frequency, :last_scaled_at
# @param [String] name Heroku app name
# @param [Hash] opts options
@@ -39,13 +39,12 @@
fail("no API key given") unless opts[:api_key]
fail("min_dynos must be at least 1") unless opts[:min_dynos] >= 1
fail("max_dynos must be at least 1") unless opts[:max_dynos] >= 1
fail("interval must be at least 10") unless opts[:interval] >= 10
- @url = opts[:url] || "http://#{@name}.herokuapp.com/robots.txt"
- @api = Heroku::API.new api_key: opts[:api_key]
-
+ @url = opts[:url] || "http://#{@name}.herokuapp.com/robots.txt"
+ @api_key = opts[:api_key]
@interval = opts[:interval].to_i
@min_dynos = opts[:min_dynos].to_i
@max_dynos = opts[:max_dynos].to_i
@wait_low = opts[:wait_low].to_i
@wait_high = opts[:wait_high].to_i
@@ -57,12 +56,13 @@
end
# Scales the app
def scale!
scale_at = next_scale_attempt
- if Time.now < scale_at
- log :debug, "skip scaling, next attempt in #{(scale_at - Time.now).to_i}s"
+ now = Time.now
+ if now < scale_at
+ log :debug, "skip check, next attempt in #{(scale_at - now).to_i}s"
return
end
do_scale(metric.by)
rescue => e
@@ -87,9 +87,10 @@
end
def do_scale(by)
return if by.zero?
+ api = Heroku::API.new(api_key: api_key)
info = api.get_app(name)
unless info.status == 200
log :warn, "error fetching app info, responded with #{info.status}"
return
end
\ No newline at end of file