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
- #args ⇒ Object
-
#backend ⇒ Object
Configuration data of a particular HAProxy backend.
- #end_time ⇒ Object
- #server_stats ⇒ Object
- #start_time ⇒ Object
- #state ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #create_stats_for(servers) ⇒ Object
-
#initialize(args) ⇒ DeploymentStats
constructor
A new instance of DeploymentStats.
-
#seconds ⇒ Object
How much time has the deployment taken.
- #to_s ⇒ Object
Constructor Details
#initialize(args) ⇒ DeploymentStats
Returns a new instance of DeploymentStats.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 32 def initialize(args) @args = args @backend = nil @start_time = nil @end_time = nil @state = :pending #: Symbol @server_stats = {} #: Hash[String, Deploy::ServerStats] @seconds = nil #: Integer? @update_states_in_stats = false #: bool end |
Instance Attribute Details
#args ⇒ Object
17 18 19 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 17 def args @args end |
#backend ⇒ Object
Configuration data of a particular HAProxy backend
14 15 16 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 14 def backend @backend end |
#end_time ⇒ Object
23 24 25 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 23 def end_time @end_time end |
#server_stats ⇒ Object
26 27 28 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 26 def server_stats @server_stats end |
#start_time ⇒ Object
20 21 22 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 20 def start_time @start_time end |
#state ⇒ Object
29 30 31 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 29 def state @state end |
Instance Method Details
#[](key) ⇒ Object
44 45 46 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 44 def [](key) @server_stats.fetch(key) end |
#[]=(key, val) ⇒ Object
49 50 51 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 49 def []=(key, val) @server_stats[key] = val end |
#create_stats_for(servers) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 54 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
89 90 91 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 89 def seconds @seconds ||= Helper.seconds_since(T.must(@start_time), to: T.must(@end_time)) end |
#to_s ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 63 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 |