Class: Taski::Execution::ParallelProgressDisplay
- Inherits:
-
Object
- Object
- Taski::Execution::ParallelProgressDisplay
- Defined in:
- lib/taski/execution/parallel_progress_display.rb
Defined Under Namespace
Classes: TaskProgress
Constant Summary collapse
- SPINNER_FRAMES =
%w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏].freeze
Instance Method Summary collapse
-
#initialize(output: $stdout) ⇒ ParallelProgressDisplay
constructor
A new instance of ParallelProgressDisplay.
- #register_task(task_class) ⇒ Object
- #render ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
-
#task_registered?(task_class) ⇒ Boolean
True if the task is registered.
-
#task_state(task_class) ⇒ Symbol
The task state.
- #update_task(task_class, state:, duration: nil, error: nil) ⇒ Object
Constructor Details
#initialize(output: $stdout) ⇒ ParallelProgressDisplay
Returns a new instance of ParallelProgressDisplay.
22 23 24 25 26 27 28 29 |
# File 'lib/taski/execution/parallel_progress_display.rb', line 22 def initialize(output: $stdout) @output = output @tasks = {} @monitor = Monitor.new @spinner_index = 0 @renderer_thread = nil @running = false end |
Instance Method Details
#register_task(task_class) ⇒ Object
32 33 34 35 36 |
# File 'lib/taski/execution/parallel_progress_display.rb', line 32 def register_task(task_class) @monitor.synchronize do @tasks[task_class] = TaskProgress.new end end |
#render ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/taski/execution/parallel_progress_display.rb', line 76 def render @monitor.synchronize do @tasks.each do |task_class, progress| line = format_task_line(task_class, progress) @output.puts line end end end |
#start ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/taski/execution/parallel_progress_display.rb', line 85 def start return if @running @running = true @renderer_thread = Thread.new do loop do break unless @running render_live sleep 0.1 end end end |
#stop ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/taski/execution/parallel_progress_display.rb', line 98 def stop return unless @running @running = false @renderer_thread&.join render_final end |
#task_registered?(task_class) ⇒ Boolean
Returns true if the task is registered.
40 41 42 43 44 |
# File 'lib/taski/execution/parallel_progress_display.rb', line 40 def task_registered?(task_class) @monitor.synchronize do @tasks.key?(task_class) end end |
#task_state(task_class) ⇒ Symbol
Returns The task state.
70 71 72 73 74 |
# File 'lib/taski/execution/parallel_progress_display.rb', line 70 def task_state(task_class) @monitor.synchronize do @tasks[task_class]&.state end end |
#update_task(task_class, state:, duration: nil, error: nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/taski/execution/parallel_progress_display.rb', line 50 def update_task(task_class, state:, duration: nil, error: nil) @monitor.synchronize do progress = @tasks[task_class] return unless progress progress.state = state progress.duration = duration if duration progress.error = error if error case state when :running progress.start_time = Time.now when :completed, :failed progress.end_time = Time.now end end end |