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

#initializeDeploymentStats

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

#backendCapistrano::DataPlaneApi::Configuration::Backend?

Returns Configuration data of a particular HAProxy backend.

Returns:



12
13
14
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 12

def backend
  @backend
end

#end_timeTime?

Returns:

  • (Time, nil)


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

def end_time
  @end_time
end

#server_statsHash{String => Deploy::ServerStats}

Returns:



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

def server_stats
  @server_stats
end

#start_timeTime?

Returns:

  • (Time, nil)


15
16
17
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 15

def start_time
  @start_time
end

#successBoolean

Returns:

  • (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

Parameters:

  • key (String)

Returns:



36
37
38
# File 'lib/capistrano/data_plane_api/deploy/deployment_stats.rb', line 36

def [](key)
  @server_stats[key]
end

#[]=(key, val) ⇒ Object

Parameters:



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

#secondsInteger?

Returns How much time has the deployment taken.

Returns:

  • (Integer, nil)

    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_sString

Returns:

  • (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