Module: HerokuResqueAutoscaler

Defined in:
lib/heroku_resque_autoscaler.rb,
lib/heroku_resque_autoscaler/scaler.rb,
lib/heroku_resque_autoscaler/version.rb,
lib/heroku_resque_autoscaler/configuration.rb

Defined Under Namespace

Modules: Scaler Classes: Configuration

Constant Summary collapse

DEFAULT_WORKER_SCALE =
[
  { :workers => 1, :job_count => 1 },
  { :workers => 2, :job_count => 15 },
  { :workers => 3, :job_count => 25 },
  { :workers => 4, :job_count => 40 },
  { :workers => 5, :job_count => 60 }
]
VERSION =
"0.2.0"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.configurationObject

The configuration object.

See Also:



24
25
26
# File 'lib/heroku_resque_autoscaler.rb', line 24

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Call this method to modify defaults in your initializers.

Examples:

HerokuResqueAutoscaler.configure do |config|
  config.heroku_api_key  = ENV["HEROKU_API_KEY"]
  config.heroku_app_name = ENV["HEROKU_APP_NAME"]
end

Yields:



35
36
37
# File 'lib/heroku_resque_autoscaler.rb', line 35

def configure
  yield(configuration)
end

Instance Method Details

#after_enqueue_scale_up(*args) ⇒ Object



40
41
42
43
44
45
# File 'lib/heroku_resque_autoscaler.rb', line 40

def after_enqueue_scale_up(*args)
  desired_workers = num_desired_heroku_workers
  if Scaler.workers < desired_workers
    Scaler.workers = desired_workers
  end
end

#after_perform_scale_down(*args) ⇒ Object



47
48
49
50
# File 'lib/heroku_resque_autoscaler.rb', line 47

def after_perform_scale_down(*args)
  # Scale everything down if we have no pending jobs and one working job (this one)
  Scaler.workers = 0 if Scaler.job_count.zero? && Scaler.working_job_count == 1
end

#num_desired_heroku_workers(*args) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/heroku_resque_autoscaler.rb', line 52

def num_desired_heroku_workers(*args)
  worker_scale.reverse_each do |scale_info|
    if Scaler.job_count >= scale_info[:job_count]
      return scale_info[:workers]
    end
  end

  0
end