Class: Capistrano::DataPlaneApi::Deploy::DeploymentStats

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ DeploymentStats

: (Args) -> void



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

#argsObject

: Args



17
18
19
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 17

def args
  @args
end

#backendObject

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_timeObject

: Time?



23
24
25
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 23

def end_time
  @end_time
end

#server_statsObject

: Hash[String, Deploy::ServerStats]



26
27
28
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 26

def server_stats
  @server_stats
end

#start_timeObject

: Time?



20
21
22
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 20

def start_time
  @start_time
end

#stateObject

: Symbol



29
30
31
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 29

def state
  @state
end

Instance Method Details

#[](key) ⇒ Object

: (String) -> Deploy::ServerStats



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

: (String, Deploy::ServerStats) -> void



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

: (Array | Configuration::Server) -> void



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

#secondsObject

How much time has the deployment taken : -> Integer?



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_sObject

: -> String



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