Class: Autoscaler::HerokuPlatformScaler
- Inherits:
-
Object
- Object
- Autoscaler::HerokuPlatformScaler
- Defined in:
- lib/autoscaler/heroku_platform_scaler.rb
Overview
Wraps the Heroku Platform API to provide just the interface that we need for scaling.
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#exception_handler ⇒ Object
writeonly
Callable object which responds to exceptions during api calls #.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#counter_cache=(cache) ⇒ Object
Object which supports #counter and #counter= Defaults to CounterCacheMemory.
-
#initialize(type = 'worker', token = ENV['AUTOSCALER_HEROKU_ACCESS_TOKEN'], app = ENV['AUTOSCALER_HEROKU_APP']) ⇒ HerokuPlatformScaler
constructor
A new instance of HerokuPlatformScaler.
-
#workers ⇒ Numeric
Read the current worker count (value may be cached).
-
#workers=(n) ⇒ Object
Set the number of workers (noop if workers the same).
Constructor Details
#initialize(type = 'worker', token = ENV['AUTOSCALER_HEROKU_ACCESS_TOKEN'], app = ENV['AUTOSCALER_HEROKU_APP']) ⇒ HerokuPlatformScaler
Returns a new instance of HerokuPlatformScaler.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/autoscaler/heroku_platform_scaler.rb', line 10 def initialize( type = 'worker', token = ENV['AUTOSCALER_HEROKU_ACCESS_TOKEN'], app = ENV['AUTOSCALER_HEROKU_APP']) if (token.nil? && ENV['HEROKU_ACCESS_TOKEN']) warn "Autoscaler: ENV AUTOSCALER_HEROKU_ACCESS_TOKEN is now preferred, HEROKU_ACCESS_TOKEN may be removed in a future release" token = ENV['HEROKU_ACCESS_TOKEN'] end if (app.nil? && ENV['HEROKU_APP']) warn "Autoscaler: ENV AUTOSCALER_HEROKU_APP is now preferred, HEROKU_APP may be removed in a future release" app = ENV['HEROKU_APP'] end @client = PlatformAPI.connect_oauth(token) @type = type @app = app @workers = CounterCacheMemory.new end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
30 31 32 |
# File 'lib/autoscaler/heroku_platform_scaler.rb', line 30 def app @app end |
#exception_handler=(value) ⇒ Object
Callable object which responds to exceptions during api calls #
60 61 62 |
# File 'lib/autoscaler/heroku_platform_scaler.rb', line 60 def exception_handler=(value) @exception_handler = value end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
31 32 33 |
# File 'lib/autoscaler/heroku_platform_scaler.rb', line 31 def type @type end |
Instance Method Details
#counter_cache=(cache) ⇒ Object
Object which supports #counter and #counter= Defaults to CounterCacheMemory
64 65 66 |
# File 'lib/autoscaler/heroku_platform_scaler.rb', line 64 def counter_cache=(cache) @workers = cache end |
#workers ⇒ Numeric
Read the current worker count (value may be cached)
35 36 37 |
# File 'lib/autoscaler/heroku_platform_scaler.rb', line 35 def workers @workers.counter {@workers.counter = heroku_get_workers} end |
#workers=(n) ⇒ Object
Set the number of workers (noop if workers the same)
41 42 43 44 45 46 47 48 49 |
# File 'lib/autoscaler/heroku_platform_scaler.rb', line 41 def workers=(n) unknown = false current = @workers.counter{unknown = true; 1} if n != current || unknown p "Scaling #{type} to #{n}" heroku_set_workers(n) @workers.counter = n end end |