Class: TidyReset::ApplicationManager

Inherits:
Object
  • Object
show all
Defined in:
lib/tidy_reset/application_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ApplicationManager

Returns a new instance of ApplicationManager.



7
8
9
10
11
# File 'lib/tidy_reset/application_manager.rb', line 7

def initialize(options)
  @name = options.fetch(:name)
  @token = options.fetch(:token)
  @heroku = PlatformAPI.connect_oauth(@token)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/tidy_reset/application_manager.rb', line 5

def name
  @name
end

#tokenObject

Returns the value of attribute token.



5
6
7
# File 'lib/tidy_reset/application_manager.rb', line 5

def token
  @token
end

Instance Method Details

#disable_maintenance_modeObject



17
18
19
# File 'lib/tidy_reset/application_manager.rb', line 17

def disable_maintenance_mode
  @heroku.app.update(@name, { maintenance: false })
end

#enable_maintenance_modeObject



13
14
15
# File 'lib/tidy_reset/application_manager.rb', line 13

def enable_maintenance_mode
  @heroku.app.update(@name, { maintenance: true })
end

#scale_dynos_to_configuration(dyno_config) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/tidy_reset/application_manager.rb', line 28

def scale_dynos_to_configuration(dyno_config)
  formation_list.keep_if do |formation| 
    dyno_config.keys.include?(formation['type']) 
  end.each do |formation|
    @heroku.formation.update(@name, formation['id'], { quantity: dyno_config[formation['type']] } )
  end
end

#shutdown_all_dynosObject



21
22
23
24
25
26
# File 'lib/tidy_reset/application_manager.rb', line 21

def shutdown_all_dynos
  live_formations = formation_list.select { |f| Integer(f['quantity']) > 0 }
  live_formations.each do |formation|
    @heroku.formation.update(@name, formation['id'], { quantity: 0 })
  end
end