Class: DynoScaler::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/dyno_scaler/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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

#applicationString

Default is nil when HEROKU_APP environment variable is not set, otherwise defaults to its value.

Parameters:

  • the (String)

    name of the Heroku application used when scaling workers

Returns:

  • (String)

    default: nil



53
54
55
# File 'lib/dyno_scaler/configuration.rb', line 53

def application
  @application
end

#enabledBoolean Also known as: enabled?

Default is false when HEROKU_API_KEY environment variable is not set, otherwise defaults to true.

Parameters:

  • whether (Boolean)

    to enable scaling or not

Returns:

  • (Boolean)

    default: false



44
45
46
# File 'lib/dyno_scaler/configuration.rb', line 44

def enabled
  @enabled
end

#job_worker_ratioHash

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
}

Parameters:

  • with (Hash)

    job worker ratio

Returns:

  • (Hash)

    default to { 1 => 1, 2 => 25, 3 => 50, 4 => 75, 5 => 100 }



36
37
38
# File 'lib/dyno_scaler/configuration.rb', line 36

def job_worker_ratio
  @job_worker_ratio
end

#loggerLogger

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)`.

Parameters:

  • the (Logger)

    logger to be used

Returns:

  • (Logger)

    default: nil



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_workersFixnum

Contains the max amount of workers that are allowed to run concurrently

Returns:

  • (Fixnum)

    default: 1



9
10
11
# File 'lib/dyno_scaler/configuration.rb', line 9

def max_workers
  @max_workers
end

#min_workersFixnum

Contains the min amount of workers that should always be running

Returns:

  • (Fixnum)

    default: 0



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