Class: HerokuScaleScheduler::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/heroku_scale_scheduler/client.rb

Instance Method Summary collapse

Instance Method Details

#configObject



5
6
7
8
# File 'lib/heroku_scale_scheduler/client.rb', line 5

def config
  path = Rails.root.join('config', 'heroku_ps.yml')
  @config ||= File.exists?(path) ? YAML.load_file(path) : {}
end

#run(type = :ps) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/heroku_scale_scheduler/client.rb', line 10

def run(type = :ps)
  client = Heroku::Client.new(*Heroku::Auth.read_credentials)
  run_at = (Time.now.strftime('%H%M').to_i / 10) * 10

  config.keys.each do |app|
    if type != :ps && qty = config[app][type.to_s][run_at]
      case type
      when :dynos then client.set_dynos(app, qty)
      when :workers then client.set_workers(app, qty)
      end
    else
      config[app].keys.each do |ps|
        if qty = config[app][ps][run_at]
          client.ps_scale(app, :type => ps, :qty => qty)
        end
      end
    end
  end
end