Class: Mnogootex::Job::Logger

Inherits:
Thread
  • Object
show all
Defined in:
lib/mnogootex/job/logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spinner:, processor:, runners:, porters:) ⇒ Logger

Returns a new instance of Logger.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mnogootex/job/logger.rb', line 8

def initialize(spinner:, processor:, runners:, porters:)
  super do
    while runners.any?(&:alive?)
      self.class.print_status(runners: runners, spinner: spinner)
      sleep 0.02 # 50 fps
    end
    self.class.print_status(runners: runners, spinner: spinner)
    puts
    self.class.print_outcome(runners: runners, porters: porters, processor: processor)
  end
end

Class Method Details



30
31
32
33
34
35
36
37
# File 'lib/mnogootex/job/logger.rb', line 30

def print_outcome(runners:, porters:, processor:)
  puts 'Outcome:'
  porters.zip(runners).each do |porter, runner|
    outcome_icon = runner.successful? ? '✔'.green : '✘'.red
    puts "  #{outcome_icon} #{porter.hid}"
    puts processor.call(runner.log_lines) unless runner.successful?
  end
end


21
22
23
24
25
26
27
28
# File 'lib/mnogootex/job/logger.rb', line 21

def print_status(runners:, spinner:)
  spinners_frames = []
  runners.each do |runner|
    spinner_frame = spinner[runner.count_lines % spinner.size]
    spinners_frames << colour_by_state(spinner_frame, runner)
  end
  print "Runners: #{spinners_frames.join}\r"
end