Class: Capistrano::DataPlaneApi::Deploy::DeploymentStats
- Inherits:
-
Object
- Object
- Capistrano::DataPlaneApi::Deploy::DeploymentStats
- Defined in:
- lib/capistrano/data_plane_api/deploy/deployment_stats.rb
Overview
Represents a collection of deployment stats for particular servers.
Instance Attribute Summary collapse
-
#backend ⇒ Capistrano::DataPlaneApi::Configuration::Backend?
Configuration data of a particular HAProxy backend.
- #end_time ⇒ Time?
- #server_stats ⇒ Hash{String => Deploy::ServerStats}
- #start_time ⇒ Time?
- #success ⇒ Boolean
Instance Method Summary collapse
- #[](key) ⇒ Deploy::ServerStats
- #[]=(key, val) ⇒ Object
- #create_stats_for(servers) ⇒ void
-
#initialize ⇒ DeploymentStats
constructor
A new instance of DeploymentStats.
-
#seconds ⇒ Integer?
How much time has the deployment taken.
- #to_s ⇒ String
Constructor Details
#initialize ⇒ DeploymentStats
Returns a new instance of DeploymentStats.
26 27 28 29 30 31 32 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 26 def initialize @backend = nil @start_time = nil @end_time = nil @success = true @server_stats = {} end |
Instance Attribute Details
#backend ⇒ Capistrano::DataPlaneApi::Configuration::Backend?
Returns Configuration data of a particular HAProxy backend.
12 13 14 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 12 def backend @backend end |
#end_time ⇒ Time?
18 19 20 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 18 def end_time @end_time end |
#server_stats ⇒ Hash{String => Deploy::ServerStats}
21 22 23 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 21 def server_stats @server_stats end |
#start_time ⇒ Time?
15 16 17 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 15 def start_time @start_time end |
#success ⇒ Boolean
24 25 26 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 24 def success @success end |
Instance Method Details
#[](key) ⇒ Deploy::ServerStats
36 37 38 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 36 def [](key) @server_stats[key] end |
#[]=(key, val) ⇒ Object
42 43 44 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 42 def []=(key, val) @server_stats[key] = val end |
#create_stats_for(servers) ⇒ void
This method returns an undefined value.
48 49 50 51 52 53 54 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 48 def create_stats_for(servers) servers = *servers servers.each do |server| @server_stats[server.name] = ServerStats.new(server.name, @backend.name) end end |
#seconds ⇒ Integer?
Returns How much time has the deployment taken.
82 83 84 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 82 def seconds @seconds ||= Helper.seconds_since(@start_time, to: @end_time) end |
#to_s ⇒ String
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 57 def to_s update_states_in_stats time_string = COLORS.bold.yellow ::Time.now.to_s if success state = COLORS.bold.green 'Successful' time_sentence = 'took' else state = COLORS.bold.red 'Failed' time_sentence = 'failed after' end result = ::String.new result << "\n#{time_string}\n\n" result << "#{state} deployment to #{::Capistrano::DataPlaneApi.humanize_backend_name(@backend)}\n" result << " #{time_sentence} #{Helper.humanize_time(seconds)}\n" @server_stats.each_value do |stats| result << "\n#{stats}" end result end |