Class: OpsWorks::Deployment
- Defined in:
- lib/opsworks/deployment.rb
Constant Summary collapse
- TIMEOUT =
300- POLL_INTERVAL =
5- API_LIMIT =
25
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
-
.from_collection_response(response) ⇒ Object
rubocop:enble MethodLength.
- .from_response(response) ⇒ Object
-
.wait(deployments, timeout = TIMEOUT) ⇒ Object
rubocop:disable MethodLength.
Instance Method Summary collapse
Methods inherited from Resource
Constructor Details
This class inherits a constructor from OpsWorks::Resource
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/opsworks/deployment.rb', line 5 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/opsworks/deployment.rb', line 5 def id @id end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/opsworks/deployment.rb', line 5 def status @status end |
Class Method Details
.from_collection_response(response) ⇒ Object
rubocop:enble MethodLength
34 35 36 37 38 39 40 41 42 |
# File 'lib/opsworks/deployment.rb', line 34 def self.from_collection_response(response) response.data[:deployments].map do |hash| new( id: hash[:deployment_id], created_at: hash[:created_at], status: hash[:status] ) end end |
.from_response(response) ⇒ Object
44 45 46 |
# File 'lib/opsworks/deployment.rb', line 44 def self.from_response(response) new(id: response[:deployment_id]) end |
.wait(deployments, timeout = TIMEOUT) ⇒ Object
rubocop:disable MethodLength
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/opsworks/deployment.rb', line 12 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?) running_deployments.map(&:id).each_slice(API_LIMIT) do |slice| response = client.describe_deployments( deployment_ids: slice ) updates += from_collection_response(response) 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
65 66 67 |
# File 'lib/opsworks/deployment.rb', line 65 def failed? status == 'failed' end |
#running? ⇒ Boolean
57 58 59 |
# File 'lib/opsworks/deployment.rb', line 57 def running? status.nil? || status == 'running' end |
#success? ⇒ Boolean
61 62 63 |
# File 'lib/opsworks/deployment.rb', line 61 def success? status == 'successful' end |
#wait ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/opsworks/deployment.rb', line 48 def wait while deployment.running? sleep POLL_INTERVAL response = client.describe_deployments(deployment_ids: [id]) update = from_collection_response(response).first deployment.status = update.status end end |