Class: HerokuVector::Engine::Heroku
- Inherits:
-
Object
- Object
- HerokuVector::Engine::Heroku
- Includes:
- Helper
- Defined in:
- lib/heroku_vector/engine/heroku.rb
Defined Under Namespace
Classes: CacheEntry
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#heroku ⇒ Object
Returns the value of attribute heroku.
Instance Method Summary collapse
- #assert_heroku_api_success(response) ⇒ Object
- #count_for_dyno_name(dyno_name) ⇒ Object
- #get_dyno_types ⇒ Object
- #get_dynos_by_name ⇒ Object
- #get_dynos_by_name_cached ⇒ Object
-
#initialize(options = {}) ⇒ Heroku
constructor
A new instance of Heroku.
- #scale_dynos(dyno_name, count) ⇒ Object
Methods included from Helper
Constructor Details
#initialize(options = {}) ⇒ Heroku
Returns a new instance of Heroku.
11 12 13 14 15 16 |
# File 'lib/heroku_vector/engine/heroku.rb', line 11 def initialize(={}) = { app: HerokuVector.heroku_app_name }.merge() @app = [:app] @heroku = ::Heroku::API.new end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
9 10 11 |
# File 'lib/heroku_vector/engine/heroku.rb', line 9 def app @app end |
#heroku ⇒ Object
Returns the value of attribute heroku.
9 10 11 |
# File 'lib/heroku_vector/engine/heroku.rb', line 9 def heroku @heroku end |
Instance Method Details
#assert_heroku_api_success(response) ⇒ Object
58 59 60 61 |
# File 'lib/heroku_vector/engine/heroku.rb', line 58 def assert_heroku_api_success(response) raise 'Invalid Heroku API Response' unless response raise "Error #{response.status} from Heroku API" unless response.status == 200 end |
#count_for_dyno_name(dyno_name) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/heroku_vector/engine/heroku.rb', line 43 def count_for_dyno_name(dyno_name) dyno = get_dynos_by_name_cached[dyno_name] return 0 unless dyno dyno['quantity'] || 0 end |
#get_dyno_types ⇒ Object
37 38 39 40 41 |
# File 'lib/heroku_vector/engine/heroku.rb', line 37 def get_dyno_types response = heroku.get_dyno_types(app) assert_heroku_api_success(response) response.body end |
#get_dynos_by_name ⇒ Object
32 33 34 35 |
# File 'lib/heroku_vector/engine/heroku.rb', line 32 def get_dynos_by_name dyno_types = get_dyno_types dyno_types.index_by {|dyno| dyno["name"] } end |
#get_dynos_by_name_cached ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/heroku_vector/engine/heroku.rb', line 18 def get_dynos_by_name_cached if @dynos_by_name && @dynos_by_name.expires_at > Time.now return @dynos_by_name.data end @dynos_by_name = begin expires_at = Time.now + 60 # 1 min from now CacheEntry.new(get_dynos_by_name, expires_at) rescue nil end @dynos_by_name.data end |
#scale_dynos(dyno_name, count) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/heroku_vector/engine/heroku.rb', line 50 def scale_dynos(dyno_name, count) response = heroku.post_ps_scale(app, dyno_name, count) assert_heroku_api_success(response) logger.info "Heroku.scale_dynos(#{dyno_name}, #{count})" response.body end |