Class: DynoScaler::Configuration
- Inherits:
-
Object
- Object
- DynoScaler::Configuration
- Defined in:
- lib/dyno_scaler/configuration.rb
Instance Attribute Summary collapse
-
#application ⇒ String
Default is nil when HEROKU_APP environment variable is not set, otherwise defaults to its value.
-
#enabled ⇒ Boolean
(also: #enabled?)
Default is false when HEROKU_API_KEY environment variable is not set, otherwise defaults to true.
-
#job_worker_ratio ⇒ Hash
Contains the ratio used to spawn more workers given a number of jobs.
-
#logger ⇒ Logger
The logger to be used to log message.
-
#max_workers ⇒ Fixnum
Contains the max amount of workers that are allowed to run concurrently.
-
#min_workers ⇒ Fixnum
Contains the min amount of workers that should always be running.
Instance Method Summary collapse
-
#async(&block) ⇒ Object
(also: #async?)
Returns the current configured async Proc or configures one.
-
#async=(value) ⇒ Object
When set to true it will use GirlFriday to asynchronous process the scaling, otherwise you may pass a Proc that will be called whenever scaling is needed.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/dyno_scaler/configuration.rb', line 55 def initialize self.max_workers = 1 self.min_workers = 0 self.enabled = !ENV['HEROKU_API_KEY'].nil? self.application = ENV['HEROKU_APP'] self.job_worker_ratio = { 1 => 1, 2 => 25, 3 => 50, 4 => 75, 5 => 100 } end |
Instance Attribute Details
#application ⇒ String
Default is nil when HEROKU_APP environment variable is not set, otherwise defaults to its value.
53 54 55 |
# File 'lib/dyno_scaler/configuration.rb', line 53 def application @application end |
#enabled ⇒ Boolean Also known as: enabled?
Default is false when HEROKU_API_KEY environment variable is not set, otherwise defaults to true.
44 45 46 |
# File 'lib/dyno_scaler/configuration.rb', line 44 def enabled @enabled end |
#job_worker_ratio ⇒ Hash
Contains the ratio used to spawn more workers given a number of jobs.
The given hash should have the number of workers as a key, and the number of queued jobs that are needed in order to spawn that number of workers as the value.
For example, if you wanted to spawn a second worker once 6 jobs are queued then spawn another third worker once 10 jobs are queued you could configure this option as:
config.job_worker_ratio = {
1 => 1,
2 => 6,
3 => 10
}
36 37 38 |
# File 'lib/dyno_scaler/configuration.rb', line 36 def job_worker_ratio @job_worker_ratio end |
#logger ⇒ Logger
The logger to be used to log message
When using Rails it will default to Rails.logger, otherwise it will be set a ‘Logger.new(STDERR)`.
94 95 96 |
# File 'lib/dyno_scaler/configuration.rb', line 94 def logger @logger ||= defined?(Rails) ? Rails.logger || Logger.new(STDERR) : Logger.new(STDERR) end |
#max_workers ⇒ Fixnum
Contains the max amount of workers that are allowed to run concurrently
9 10 11 |
# File 'lib/dyno_scaler/configuration.rb', line 9 def max_workers @max_workers end |
#min_workers ⇒ Fixnum
Contains the min amount of workers that should always be running
15 16 17 |
# File 'lib/dyno_scaler/configuration.rb', line 15 def min_workers @min_workers end |
Instance Method Details
#async(&block) ⇒ Object Also known as: async?
Returns the current configured async Proc or configures one.
71 72 73 74 |
# File 'lib/dyno_scaler/configuration.rb', line 71 def async(&block) @async = block if block_given? @async end |
#async=(value) ⇒ Object
When set to true it will use GirlFriday to asynchronous process the scaling, otherwise you may pass a Proc that will be called whenever scaling is needed.
Defaults to false, meaning that scaling is processed synchronously.
82 83 84 |
# File 'lib/dyno_scaler/configuration.rb', line 82 def async=(value) @async = value == true ? default_async_processor : value end |