Sha256: 63f2332be1ceb713d19c6271a694f2078bf27ad38427c965b892e23c1203929b

Contents?: true

Size: 785 Bytes

Versions: 2

Compression:

Stored size: 785 Bytes

Contents

class Heroku::Scalr::Runner
  SIGNALS = %w[HUP INT TERM] & Signal.list.keys

  attr_reader :config

  # @param [String] config_path configuration file location
  def initialize(config_path)
    @config = Heroku::Scalr::Config.new(config_path)
  end

  # @return [Timers] recurring timers
  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

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

    loop { timers.wait }
  end

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

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
heroku-scalr-0.3.0 lib/heroku/scalr/runner.rb
heroku-scalr-0.2.4 lib/heroku/scalr/runner.rb