Class: TjScaleRuby::Configuration

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

Overview

Reads Heroku / scaling settings from environment variables.

Constant Summary collapse

DEFAULT_INTERVAL_SECONDS =
20
JOB_BACKENDS =
%w[auto delayed_job sidekiq].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = ENV) ⇒ Configuration

Returns a new instance of Configuration.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tj_scale_ruby/configuration.rb', line 12

def initialize(env = ENV)
  @monitor_process = normalize_process(env["TJ_SCALE_MONITOR_PROCESS"]) || "worker"
  @job_backend = normalize_job_backend(env["TJ_SCALE_JOB_BACKEND"])
  @sidekiq_queues = parse_list(env["TJ_SCALE_SIDEKIQ_QUEUES"])
  @interval_seconds = parse_positive_int(env["TJ_SCALE_INTERVAL_SECONDS"], DEFAULT_INTERVAL_SECONDS)
  @target_app = nonempty_string(env["TJ_SCALE_TARGET_APP"])
  @heroku_app_name = nonempty_string(env["HEROKU_APP_NAME"])
  @target_process = normalize_process(env["TJ_SCALE_TARGET_PROCESS"]) || @monitor_process
  @min_priority = env["TJ_MIN_PRIORITY"].to_i
  @max_priority = env["TJ_MAX_PRIORITY"].to_i
end

Instance Attribute Details

#interval_secondsObject (readonly)

Returns the value of attribute interval_seconds.



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

def interval_seconds
  @interval_seconds
end

#job_backendObject (readonly)

Returns the value of attribute job_backend.



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

def job_backend
  @job_backend
end

#max_priorityObject (readonly)

Returns the value of attribute max_priority.



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

def max_priority
  @max_priority
end

#min_priorityObject (readonly)

Returns the value of attribute min_priority.



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

def min_priority
  @min_priority
end

#monitor_processObject (readonly)

Returns the value of attribute monitor_process.



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

def monitor_process
  @monitor_process
end

#sidekiq_queuesObject (readonly)

Returns the value of attribute sidekiq_queues.



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

def sidekiq_queues
  @sidekiq_queues
end

Instance Method Details

#target_appObject

Heroku app name the scaler should act on (defaults to HEROKU_APP_NAME when unset).



25
26
27
# File 'lib/tj_scale_ruby/configuration.rb', line 25

def target_app
  @target_app || @heroku_app_name
end

#target_processObject

Process type to scale on that app: “web” or “worker”.



30
31
32
# File 'lib/tj_scale_ruby/configuration.rb', line 30

def target_process
  @target_process
end