Class: Bosh::Cli::EventLogRenderer
Defined Under Namespace
Classes: InvalidEvent, Task
Instance Attribute Summary collapse
#time_adjustment
Instance Method Summary
collapse
create_for_log_type
Constructor Details
Returns a new instance of EventLogRenderer.
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/cli/event_log_renderer.rb', line 26
def initialize
@lock = Monitor.new
@events_count = 0
@seen_stages = Set.new
@out = Bosh::Cli::Config.output || $stdout
@out.sync = true
@buffer = StringIO.new
@progress_bars = {}
@pos = 0
@time_adjustment = 0
end
|
Instance Attribute Details
#current_stage ⇒ Object
Returns the value of attribute current_stage.
22
23
24
|
# File 'lib/cli/event_log_renderer.rb', line 22
def current_stage
@current_stage
end
|
#events_count ⇒ Object
Returns the value of attribute events_count.
23
24
25
|
# File 'lib/cli/event_log_renderer.rb', line 23
def events_count
@events_count
end
|
#finished_at ⇒ Object
Returns the value of attribute finished_at.
24
25
26
|
# File 'lib/cli/event_log_renderer.rb', line 24
def finished_at
@finished_at
end
|
#started_at ⇒ Object
Returns the value of attribute started_at.
24
25
26
|
# File 'lib/cli/event_log_renderer.rb', line 24
def started_at
@started_at
end
|
Instance Method Details
#add_error(event) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/cli/event_log_renderer.rb', line 116
def add_error(event)
error = event["error"] || {}
code = error["code"]
message = error["message"]
error = "Error"
error += " #{code}" if code
error += ": #{message}" if message
@buffer.puts("\n" + error.red)
end
|
#add_event(event_line) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/cli/event_log_renderer.rb', line 44
def add_event(event_line)
event = parse_event(event_line)
@lock.synchronize do
if event["error"]
done_with_stage if @current_stage
add_error(event)
return
end
tags = event["tags"].is_a?(Array) ? event["tags"] : []
= event["stage"]
if tags.size > 0
+= " " + tags.sort.join(", ").green
end
unless @seen_stages.include?()
done_with_stage if @current_stage
begin_stage(event, )
end
if @current_stage ==
append_event(event)
end
end
rescue InvalidEvent => e
end
|
#add_output(output) ⇒ Object
38
39
40
41
42
|
# File 'lib/cli/event_log_renderer.rb', line 38
def add_output(output)
output.to_s.split("\n").each do |line|
add_event(line)
end
end
|
#begin_stage(event, header) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/cli/event_log_renderer.rb', line 84
def begin_stage(event, )
@current_stage =
@seen_stages << @current_stage
@stage_start_time = Time.at(event["time"]) rescue Time.now
@local_start_time = adjusted_time(@stage_start_time)
@tasks = {}
@done_tasks = []
@eta = nil
@stage_has_error = false @tasks_batch_size = 0
@batches_count = 0
@running_avg = 0
end
|
155
156
157
158
|
# File 'lib/cli/event_log_renderer.rb', line 155
def duration
return unless duration_known?
@finished_at - @started_at
end
|
#duration_known? ⇒ Boolean
151
152
153
|
# File 'lib/cli/event_log_renderer.rb', line 151
def duration_known?
@started_at && @finished_at
end
|
#finish(state) ⇒ Object
141
142
143
144
145
146
147
148
149
|
# File 'lib/cli/event_log_renderer.rb', line 141
def finish(state)
return if @events_count == 0
@lock.synchronize do
@done = true
done_with_stage(state)
render
end
end
|
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/cli/event_log_renderer.rb', line 129
def refresh
@lock.synchronize do
if @in_progress
progress_bar.label = time_with_eta(Time.now - @local_start_time, @eta)
progress_bar.refresh
end
render
end
end
|
106
107
108
109
110
111
112
113
114
|
# File 'lib/cli/event_log_renderer.rb', line 106
def render
@lock.synchronize do
@buffer.seek(@pos)
output = @buffer.read
@out.print output
@pos = @buffer.tell
output
end
end
|