Class: HerokuVector::Worker

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/heroku_vector/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

included

Constructor Details

#initialize(options = {}) ⇒ Worker

Returns a new instance of Worker.



9
10
11
12
# File 'lib/heroku_vector/worker.rb', line 9

def initialize(options={})
  @options = options
  @dyno_scalers = []
end

Instance Attribute Details

#dyno_scalersObject

Returns the value of attribute dyno_scalers.



7
8
9
# File 'lib/heroku_vector/worker.rb', line 7

def dyno_scalers
  @dyno_scalers
end

#engineObject

Returns the value of attribute engine.



7
8
9
# File 'lib/heroku_vector/worker.rb', line 7

def engine
  @engine
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/heroku_vector/worker.rb', line 7

def options
  @options
end

Instance Method Details

#load_dyno_scalersObject



39
40
41
42
43
44
45
46
# File 'lib/heroku_vector/worker.rb', line 39

def load_dyno_scalers
  HerokuVector.dyno_scalers.each do |scaler_def|
    name, options = scaler_def
    logger.info "Loading Scaler: #{name}, #{options.inspect}"

    @dyno_scalers << DynoScaler.new(name, options)
  end
end

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/heroku_vector/worker.rb', line 14

def run
  if options[:config]
    if File.exist?(options[:config])
      logger.info "Loading config from '#{options[:config]}'"
      load options[:config]
    else
      logger.fatal "No config found at '#{options[:config]}'"
      logger.info "You can copy config.rb.example => config.rb to get started"
      logger.info "OR run heroku_vector -c /path/to/your/config.rb"
      logger.info "Just Starting? Test your Source config with sampler mode: heroku_vector -s"
      exit 1
    end
  end

  load_dyno_scalers

  EM.run do
    dyno_scalers.each do |scaler|
      EM::PeriodicTimer.new(scaler.period) do
        scaler.run
      end
    end
  end
end