Class: Capistrano::DataPlaneApi::Deploy::ServerStats

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/data_plane_api/deploy/server_stats.rb

Overview

Represents the stats of a deployment to a particular server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server_name, backend_name, state: :pending, admin_state: 'unknown', operational_state: 'unknown') ⇒ ServerStats

: (String, String, Symbol, String, String) -> void



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/capistrano/data_plane_api/deploy/server_stats.rb', line 34

def initialize(
  server_name,
  backend_name,
  state: :pending,
  admin_state: 'unknown',
  operational_state: 'unknown'
)
  @server_name = server_name
  @backend_name = backend_name
  @state = state
  @admin_state = admin_state
  @operational_state = operational_state
  @seconds = T.let(nil, T.nilable(Integer))
end

Instance Attribute Details

#admin_stateObject

: String



28
29
30
# File 'lib/capistrano/data_plane_api/deploy/server_stats.rb', line 28

def admin_state
  @admin_state
end

#backend_nameObject

: String



25
26
27
# File 'lib/capistrano/data_plane_api/deploy/server_stats.rb', line 25

def backend_name
  @backend_name
end

#end_timeObject

: Time?



19
20
21
# File 'lib/capistrano/data_plane_api/deploy/server_stats.rb', line 19

def end_time
  @end_time
end

#operational_stateObject

: String



31
32
33
# File 'lib/capistrano/data_plane_api/deploy/server_stats.rb', line 31

def operational_state
  @operational_state
end

#server_nameObject

: String



22
23
24
# File 'lib/capistrano/data_plane_api/deploy/server_stats.rb', line 22

def server_name
  @server_name
end

#start_timeObject

: Time?



16
17
18
# File 'lib/capistrano/data_plane_api/deploy/server_stats.rb', line 16

def start_time
  @start_time
end

#stateObject

‘nil` when the deployment hasn’t begun

`true` when it has finished successfully, `false` when it has failed

: Symbol



13
14
15
# File 'lib/capistrano/data_plane_api/deploy/server_stats.rb', line 13

def state
  @state
end

Instance Method Details

#secondsObject

How much time has the deployment taken

: -> Integer?



65
66
67
# File 'lib/capistrano/data_plane_api/deploy/server_stats.rb', line 65

def seconds
  @seconds ||= Helper.seconds_since(T.must(@start_time), to: T.must(@end_time))
end

#to_sObject

: -> String



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/capistrano/data_plane_api/deploy/server_stats.rb', line 50

def to_s
  time_string =
    case @state
    when :pending then 'skipped'
    when :failed  then "failed after #{Helper.humanize_time(T.must(seconds))}"
    when :success then "took #{Helper.humanize_time(T.must(seconds))}"
    when :info    then "at #{Time.now}"
    end

  "  #{state_emoji} #{server_title} #{time_string}#{haproxy_states}"
end