Class: OpsWorks::Deployment

Inherits:
Resource show all
Defined in:
lib/opsworks/deployment.rb

Constant Summary collapse

TIMEOUT =
300
POLL_INTERVAL =
5
API_LIMIT =
25

Instance Attribute Summary collapse

Attributes inherited from Resource

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

account, #initialize

Constructor Details

This class inherits a constructor from OpsWorks::Resource

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



3
4
5
# File 'lib/opsworks/deployment.rb', line 3

def app_id
  @app_id
end

#commandObject

Returns the value of attribute command.



3
4
5
# File 'lib/opsworks/deployment.rb', line 3

def command
  @command
end

#created_atObject

Returns the value of attribute created_at.



3
4
5
# File 'lib/opsworks/deployment.rb', line 3

def created_at
  @created_at
end

#custom_jsonObject

Returns the value of attribute custom_json.



3
4
5
# File 'lib/opsworks/deployment.rb', line 3

def custom_json
  @custom_json
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/opsworks/deployment.rb', line 3

def id
  @id
end

#statusObject

Returns the value of attribute status.



3
4
5
# File 'lib/opsworks/deployment.rb', line 3

def status
  @status
end

Class Method Details

.from_collection_response(client, response) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/opsworks/deployment.rb', line 34

def self.from_collection_response(client, response)
  response.data[:deployments].map do |deployment|
    hash = deployment.to_h
    new(
      client,
      id: hash[:deployment_id],
      command: hash[:command],
      created_at: hash[:created_at],
      status: hash[:status],
      custom_json: hash[:custom_json],
      app_id: hash[:app_id]
    )
  end
end

.from_response(client, response) ⇒ Object



49
50
51
# File 'lib/opsworks/deployment.rb', line 49

def self.from_response(client, response)
  new(client, id: response[:deployment_id])
end

.wait(deployments, timeout = TIMEOUT) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/opsworks/deployment.rb', line 9

def self.wait(deployments, timeout = TIMEOUT)
  start_time = Time.now
  timeout ||= TIMEOUT
  while deployments.any?(&:running?)
    return if Time.now - start_time > timeout
    sleep POLL_INTERVAL
    updates = []
    running_deployments = deployments.select(&:running?)
    groups = running_deployments.group_by { |d| d.client.config.region }

    groups.each do |region, region_deployments|
      client = Aws::OpsWorks::Client.new(region: region)
      region_deployments.map(&:id).each_slice(API_LIMIT) do |slice|
        response = client.describe_deployments(deployment_ids: slice)
        updates += from_collection_response(client, response)
      end
    end

    running_deployments.each do |deployment|
      update = updates.find { |u| u.id == deployment.id }
      deployment.status = update.status
    end
  end
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/opsworks/deployment.rb', line 61

def failed?
  status == 'failed'
end

#running?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/opsworks/deployment.rb', line 53

def running?
  status.nil? || status == 'running'
end

#success?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/opsworks/deployment.rb', line 57

def success?
  status == 'successful'
end