Class: Escobar::Heroku::Dynos

Inherits:
Object
  • Object
show all
Defined in:
lib/escobar/heroku/dynos.rb

Overview

Class representing an app’s dyno state

Constant Summary collapse

ONE_OFF_TYPES =
%w{run scheduler}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, app_id) ⇒ Dynos

Returns a new instance of Dynos.



13
14
15
16
# File 'lib/escobar/heroku/dynos.rb', line 13

def initialize(client, app_id)
  @app_id = app_id
  @client = client
end

Instance Attribute Details

#app_idObject (readonly)

Returns the value of attribute app_id.



7
8
9
# File 'lib/escobar/heroku/dynos.rb', line 7

def app_id
  @app_id
end

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/escobar/heroku/dynos.rb', line 7

def client
  @client
end

#command_idObject

Returns the value of attribute command_id.



9
10
11
# File 'lib/escobar/heroku/dynos.rb', line 9

def command_id
  @command_id
end

#github_urlObject

Returns the value of attribute github_url.



10
11
12
# File 'lib/escobar/heroku/dynos.rb', line 10

def github_url
  @github_url
end

#pipeline_nameObject

Returns the value of attribute pipeline_name.



11
12
13
# File 'lib/escobar/heroku/dynos.rb', line 11

def pipeline_name
  @pipeline_name
end

Instance Method Details

#infoObject



18
19
20
# File 'lib/escobar/heroku/dynos.rb', line 18

def info
  @info ||= client.heroku.get("/apps/#{app_id}/dynos")
end

#newer_than?(epoch) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/escobar/heroku/dynos.rb', line 38

def newer_than?(epoch)
  non_one_off.all? do |dyno|
    epoch < Time.parse(dyno["created_at"]).utc
  end
end

#non_one_offObject



22
23
24
# File 'lib/escobar/heroku/dynos.rb', line 22

def non_one_off
  info.reject { |dyno| ONE_OFF_TYPES.include?(dyno["type"]) }
end

#running?(release_id) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/escobar/heroku/dynos.rb', line 26

def running?(release_id)
  non_one_off.all? do |dyno|
    dyno["release"]["id"] == release_id && dyno["state"] == "up"
  end
end

#running_at_least?(version) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/escobar/heroku/dynos.rb', line 32

def running_at_least?(version)
  non_one_off.all? do |dyno|
    dyno["release"]["version"] >= version && dyno["state"] == "up"
  end
end