Class: Whacamole::HerokuWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/whacamole/heroku_wrapper.rb

Constant Summary collapse

RESTART_RATE_LIMIT =
30*60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_name, api_token, dynos) ⇒ HerokuWrapper

Returns a new instance of HerokuWrapper.



11
12
13
14
15
# File 'lib/whacamole/heroku_wrapper.rb', line 11

def initialize(app_name, api_token, dynos)
  self.app_name = app_name
  self.api_token = api_token
  self.dynos = dynos
end

Instance Attribute Details

#api_tokenObject

Returns the value of attribute api_token.



7
8
9
# File 'lib/whacamole/heroku_wrapper.rb', line 7

def api_token
  @api_token
end

#app_nameObject

Returns the value of attribute app_name.



7
8
9
# File 'lib/whacamole/heroku_wrapper.rb', line 7

def app_name
  @app_name
end

#dynosObject

Returns the value of attribute dynos.



7
8
9
# File 'lib/whacamole/heroku_wrapper.rb', line 7

def dynos
  @dynos
end

Instance Method Details

#authorizationObject



28
29
30
# File 'lib/whacamole/heroku_wrapper.rb', line 28

def authorization
  "Basic " + Base64.encode64(":#{api_token}").gsub("\n", '')
end

#create_log_sessionObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/whacamole/heroku_wrapper.rb', line 17

def create_log_session
  uri = URI(log_sessions_url)
  req = Net::HTTP::Post.new(uri.path)
  req['Authorization'] = authorization
  req['Content-type'] = content_type
  req['Accept'] = accept
  req.set_form_data({'tail' => true})
  res = Net::HTTP.start(uri.host, uri.port, :use_ssl => (uri.scheme == "https")) {|http| http.request(req)}
  JSON.parse(res.body)['logplex_url']
end

#recently_restarted?(process) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/whacamole/heroku_wrapper.rb', line 47

def recently_restarted?(process)
  restarts[process] > (Time.now - RESTART_RATE_LIMIT)
end

#restart(process) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/whacamole/heroku_wrapper.rb', line 32

def restart(process)
  return false if recently_restarted?(process)

  uri = URI(dyno_url(process))
  req = Net::HTTP::Delete.new(uri.path)
  req['Authorization'] = authorization
  req['Content-type'] = content_type
  req['Accept'] = accept
  res = Net::HTTP.start(uri.host, uri.port, :use_ssl => (uri.scheme == "https")) {|http| http.request(req)}

  restarts[process] = Time.now

  true
end