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_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 |
# 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_rows = 0 end |
Instance Method Details
#advance(member, status:, success: true, mark: nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/kettle/family/workflow_progress.rb', line 73 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_member(member, success:, status:) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/kettle/family/workflow_progress.rb', line 102 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
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/kettle/family/workflow_progress.rb', line 138 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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kettle/family/workflow_progress.rb', line 42 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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/kettle/family/workflow_progress.rb', line 57 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
115 116 117 118 119 120 121 122 123 |
# File 'lib/kettle/family/workflow_progress.rb', line 115 def stop return unless @enabled synchronize do next if @stopped @stopped = true end end |
#summary(message) ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'lib/kettle/family/workflow_progress.rb', line 129 def summary() return unless @enabled synchronize do @io.puts unless @tty write_line() end end |
#tty? ⇒ Boolean
125 126 127 |
# File 'lib/kettle/family/workflow_progress.rb', line 125 def tty? @tty end |
#update(member, status:, mark: nil) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/kettle/family/workflow_progress.rb', line 88 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 |