Class: RenuoBinCheck::MasterThread

Inherits:
Object
  • Object
show all
Defined in:
lib/renuo_bin_check/master_thread.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(printer) ⇒ MasterThread

Returns a new instance of MasterThread.



7
8
9
10
11
# File 'lib/renuo_bin_check/master_thread.rb', line 7

def initialize(printer)
  @threads = []
  @results = []
  @printer = printer
end

Instance Attribute Details

#printerObject (readonly)

Returns the value of attribute printer.



5
6
7
# File 'lib/renuo_bin_check/master_thread.rb', line 5

def printer
  @printer
end

#threadsObject (readonly)

Returns the value of attribute threads.



5
6
7
# File 'lib/renuo_bin_check/master_thread.rb', line 5

def threads
  @threads
end

Instance Method Details

#add_thread(script_config) ⇒ Object



13
14
15
16
17
18
# File 'lib/renuo_bin_check/master_thread.rb', line 13

def add_thread(script_config)
  threads << Thread.new do
    servant = ServantThread.new(script_config)
    Thread.current[:result] = servant.run
  end
end

#finalizeObject



20
21
22
23
24
25
26
27
28
# File 'lib/renuo_bin_check/master_thread.rb', line 20

def finalize
  waiter = ThreadsWait.new(threads)
  until waiter.empty?
    result = waiter.next_wait[:result]
    @results << result
    exit_with_error(result) if result.exit_code == 1
  end
  exit_with_success
end