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 ⇒ Object
Configuration data of a particular HAProxy backend.
-
#end_time ⇒ Object
: Time?.
-
#server_stats ⇒ Object
: Hash[String, Deploy::ServerStats].
-
#start_time ⇒ Object
: Time?.
-
#state ⇒ Object
: Symbol.
Instance Method Summary collapse
-
#[](key) ⇒ Object
: (String) -> Deploy::ServerStats.
-
#[]=(key, val) ⇒ Object
: (String, Deploy::ServerStats) -> void.
-
#create_stats_for(servers) ⇒ Object
: (Array | Configuration::Server) -> void.
-
#initialize ⇒ DeploymentStats
constructor
: -> void.
-
#seconds ⇒ Object
How much time has the deployment taken : -> Integer?.
-
#to_s ⇒ Object
: -> String.
Constructor Details
#initialize ⇒ DeploymentStats
: -> void
29 30 31 32 33 34 35 36 37 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 29 def initialize @backend = nil @start_time = nil @end_time = nil @state = T.let(:pending, Symbol) @server_stats = T.let({}, T::Hash[String, Deploy::ServerStats]) @seconds = T.let(nil, T.nilable(Integer)) @update_states_in_stats = T.let(false, T::Boolean) end |
Instance Attribute Details
#backend ⇒ Object
Configuration data of a particular HAProxy backend
: Capistrano::DataPlaneApi::Configuration::Backend?
14 15 16 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 14 def backend @backend end |
#end_time ⇒ Object
: Time?
20 21 22 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 20 def end_time @end_time end |
#server_stats ⇒ Object
: Hash[String, Deploy::ServerStats]
23 24 25 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 23 def server_stats @server_stats end |
#start_time ⇒ Object
: Time?
17 18 19 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 17 def start_time @start_time end |
#state ⇒ Object
: Symbol
26 27 28 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 26 def state @state end |
Instance Method Details
#[](key) ⇒ Object
: (String) -> Deploy::ServerStats
40 41 42 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 40 def [](key) @server_stats.fetch(key) end |
#[]=(key, val) ⇒ Object
: (String, Deploy::ServerStats) -> void
45 46 47 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 45 def []=(key, val) @server_stats[key] = val end |
#create_stats_for(servers) ⇒ Object
: (Array | Configuration::Server) -> void
50 51 52 53 54 55 56 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 50 def create_stats_for(servers) servers = *servers servers.each do |server| @server_stats[server.name] = ServerStats.new(server.name, T.must(@backend&.name)) end end |
#seconds ⇒ Object
How much time has the deployment taken : -> Integer?
85 86 87 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 85 def seconds @seconds ||= Helper.seconds_since(T.must(@start_time), to: T.must(@end_time)) end |
#to_s ⇒ Object
: -> String
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 59 def to_s update_states_in_stats time_string = COLORS.bold.yellow ::Time.now.to_s if state == :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(T.must(@backend))}\n" result << " #{time_sentence} #{Helper.humanize_time(T.must(seconds))}\n" @server_stats.each_value do |stats| result << "\n#{stats}" end result end |