Class: RailsParallel::Runner::Child

Inherits:
Object
  • Object
show all
Includes:
Forks
Defined in:
lib/rails_parallel/runner/child.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Forks

#before_exit, #check_status, #fork_and_run, #wait_any, #wait_for

Constructor Details

#initialize(number, schema, collector) ⇒ Child

Returns a new instance of Child.



11
12
13
14
15
16
17
# File 'lib/rails_parallel/runner/child.rb', line 11

def initialize(number, schema, collector)
  @number = number
  @schema = schema
  @collector = collector
  @buffer = ''
  @state  = :waiting
end

Instance Attribute Details

#last_suiteObject (readonly)

Returns the value of attribute last_suite.



9
10
11
# File 'lib/rails_parallel/runner/child.rb', line 9

def last_suite
  @last_suite
end

#last_timeObject (readonly)

Returns the value of attribute last_time.



9
10
11
# File 'lib/rails_parallel/runner/child.rb', line 9

def last_time
  @last_time
end

#numberObject (readonly)

Returns the value of attribute number.



9
10
11
# File 'lib/rails_parallel/runner/child.rb', line 9

def number
  @number
end

#pidObject (readonly)

Returns the value of attribute pid.



9
10
11
# File 'lib/rails_parallel/runner/child.rb', line 9

def pid
  @pid
end

#socketObject (readonly)

Returns the value of attribute socket.



9
10
11
# File 'lib/rails_parallel/runner/child.rb', line 9

def socket
  @socket
end

Instance Method Details

#closeObject



43
44
45
# File 'lib/rails_parallel/runner/child.rb', line 43

def close
  @socket.close
end

#finishObject



39
40
41
# File 'lib/rails_parallel/runner/child.rb', line 39

def finish
  @socket << :finish
end

#killObject



47
48
49
50
# File 'lib/rails_parallel/runner/child.rb', line 47

def kill
  Process.kill('KILL', @pid)
  close rescue nil
end

#launchObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rails_parallel/runner/child.rb', line 19

def launch
  parent_socket, child_socket = ObjectSocket.pair

  @pid = fork_and_run do
    parent_socket.close
    @socket = child_socket
    main_loop
  end

  child_socket.close
  @socket = parent_socket
  @socket.nonblock = true
end

#pollObject



56
57
58
59
60
# File 'lib/rails_parallel/runner/child.rb', line 56

def poll
  output = []
  @socket.each_object { |obj| output << obj }
  output
end

#run_suite(name) ⇒ Object



33
34
35
36
37
# File 'lib/rails_parallel/runner/child.rb', line 33

def run_suite(name)
  @last_suite = name
  @last_time  = Time.now
  @socket << name
end