Class: Heroku::Scalr::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/heroku/scalr/runner.rb

Constant Summary collapse

SIGNALS =
%w[HUP INT TERM] & Signal.list.keys

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path) ⇒ Runner

Returns a new instance of Runner.

Parameters:

  • config_path (String)

    configuration file location



7
8
9
# File 'lib/heroku/scalr/runner.rb', line 7

def initialize(config_path)
  @config = Heroku::Scalr::Config.new(config_path)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/heroku/scalr/runner.rb', line 4

def config
  @config
end

Instance Method Details

#run!Object

Start the runner



22
23
24
25
26
27
28
29
# File 'lib/heroku/scalr/runner.rb', line 22

def run!
  SIGNALS.each do |sig|
    Signal.trap(sig) { stop! }
  end
  Signal.trap("USR1") { Heroku::Scalr.logger.reopen }

  loop { timers.wait }
end

#stop!Object

Stop execution



32
33
34
35
# File 'lib/heroku/scalr/runner.rb', line 32

def stop!
  Heroku::Scalr.logger.info "Exiting ..."
  exit(0)
end

#timersTimers

Returns recurring timers.

Returns:

  • (Timers)

    recurring timers



12
13
14
15
16
17
18
19
# File 'lib/heroku/scalr/runner.rb', line 12

def timers
  @timers ||= Timers.new.tap do |t|
    config.apps.each do |app|
      app.log :info, "monitoring every #{app.interval}s"
      t.every(app.interval) { app.scale! }
    end
  end
end