Class: Kettle::Family::WorkflowProgress
- Inherits:
-
Object
- Object
- Kettle::Family::WorkflowProgress
- Defined in:
- lib/kettle/family/workflow_progress.rb
Constant Summary collapse
- MEMBER_WIDTH =
24- PROGRESS_WIDTH =
7- ELAPSED_WIDTH =
7- FORMAT =
"%<member>-#{MEMBER_WIDTH}.#{MEMBER_WIDTH}s %<progress>s %<duration>s %<events>s %<status>s"- EVENT_WIDTH =
20- MIN_STATUS_WIDTH =
12- DEFAULT_TERMINAL_WIDTH =
80- ELLIPSIS =
"..."
Instance Method Summary collapse
- #advance(member, status:, success: true, mark: nil) ⇒ Object
-
#finish ⇒ Object
Finish a TTY progress block before the caller prints a second report.
- #finish_member(member, success:, status:) ⇒ Object
-
#initialize(io:, label:, total:, jobs:, members: [], enabled: true, clock: nil, heading: nil) ⇒ WorkflowProgress
constructor
A new instance of WorkflowProgress.
- #notification(message) ⇒ Object
- #start ⇒ Object
- #start_member(member, total:, status:) ⇒ Object
- #stop ⇒ Object
- #summary(message) ⇒ Object
- #tty? ⇒ Boolean
- #update(member, status:, mark: nil) ⇒ Object
Constructor Details
#initialize(io:, label:, total:, jobs:, members: [], enabled: true, clock: nil, heading: nil) ⇒ WorkflowProgress
Returns a new instance of WorkflowProgress.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/kettle/family/workflow_progress.rb', line 18 def initialize(io:, label:, total:, jobs:, members: [], enabled: true, clock: nil, heading: nil) @io = io @label = label @total = total.to_i @jobs = jobs.to_i @heading = heading @clock = clock || lambda { Process.clock_gettime(Process::CLOCK_MONOTONIC) } @enabled = enabled && !!io @line_order = members.map(&:name) @started = false @stopped = false @member_totals = {} @member_counts = Hash.new(0) @member_started_at = {} @member_finished_elapsed = {} @member_events = Hash.new("") @member_statuses = Hash.new("") @notification = "" @mutex = Mutex.new @tty = @enabled && io.respond_to?(:tty?) && io.tty? @tty_rendered = false @tty_block_rows = 0 @tty_tape_rows = 0 end |
Instance Method Details
#advance(member, status:, success: true, mark: nil) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/kettle/family/workflow_progress.rb', line 74 def advance(member, status:, success: true, mark: nil) return unless @enabled synchronize do event_mark = mark || (success ? "." : "F") increment_member_count(member) if @tty append_event(member, event_mark) render(member, status: status) else write_line(non_tty_line(member, mark: event_mark, status: status)) end end end |
#finish ⇒ Object
Finish a TTY progress block before the caller prints a second report. The blank line keeps the final report physically separate from the redraw block instead of making the terminal cursor its first row.
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/kettle/family/workflow_progress.rb', line 129 def finish return unless @enabled synchronize do next if @stopped render_tty_block if @tty && @started && !@line_order.empty? write_line("") if @tty && @started @stopped = true end end |
#finish_member(member, success:, status:) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/kettle/family/workflow_progress.rb', line 103 def finish_member(member, success:, status:) return unless @enabled synchronize do @member_finished_elapsed[member.name] = elapsed_seconds(member) if @tty render(member, status: status) else write_line(non_tty_line(member, mark: success ? "done" : "failed", status: status)) end end end |
#notification(message) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/kettle/family/workflow_progress.rb', line 154 def notification() return unless @enabled synchronize do @notification = .to_s if @tty render_tty_block if @started && !@line_order.empty? elsif !@notification.empty? write_line("[notification] #{@notification}") end end end |
#start ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/kettle/family/workflow_progress.rb', line 43 def start return unless @enabled synchronize do next if @started write_line(@heading || "#{@label} #{@total} member#{plural(@total)} with #{@jobs} job#{plural(@jobs)}:") @started = true if @tty @line_order.each { |member_name| render_name(member_name, status: "") } render_tty_block unless @line_order.empty? end end end |
#start_member(member, total:, status:) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/kettle/family/workflow_progress.rb', line 58 def start_member(member, total:, status:) return unless @enabled synchronize do @member_totals[member.name] = total.to_i @member_counts[member.name] = 0 @member_started_at[member.name] ||= monotonic_now @member_finished_elapsed.delete(member.name) if @tty render(member, status: status) else write_line(non_tty_line(member, mark: ">", status: status)) end end end |
#stop ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/kettle/family/workflow_progress.rb', line 116 def stop return unless @enabled synchronize do next if @stopped @stopped = true end end |
#summary(message) ⇒ Object
145 146 147 148 149 150 151 152 |
# File 'lib/kettle/family/workflow_progress.rb', line 145 def summary() return unless @enabled synchronize do @io.puts unless @tty write_line() end end |
#tty? ⇒ Boolean
141 142 143 |
# File 'lib/kettle/family/workflow_progress.rb', line 141 def tty? @tty end |
#update(member, status:, mark: nil) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/kettle/family/workflow_progress.rb', line 89 def update(member, status:, mark: nil) return unless @enabled return if status.to_s.empty? synchronize do if @tty append_event(member, mark) if mark render(member, status: status) else write_line(non_tty_line(member, mark: mark || ">", status: status)) end end end |