Class: Workpile::Parent

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

Instance Method Summary collapse

Constructor Details

#initializeParent

Returns a new instance of Parent.



50
51
52
53
54
# File 'lib/workpile.rb', line 50

def initialize
  @service = Service.new
  DRb.start_service('druby://127.0.0.1:0',@service)
  @threads = []
end

Instance Method Details

#abortObject



74
75
76
77
78
79
80
81
# File 'lib/workpile.rb', line 74

def abort
  @abort = true
  @threads.each do |th|
    if not th.join(5)
      @service.kill_boot_children
    end
  end
end

#kill_working_childrenObject



70
71
72
# File 'lib/workpile.rb', line 70

def kill_working_children
  @service.kill_working_children
end

#request(obj) ⇒ Object



56
57
58
# File 'lib/workpile.rb', line 56

def request(obj)
  @service.push obj
end

#spawn_children(n, cmd) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/workpile.rb', line 60

def spawn_children(n, cmd)
  n.times.map do |index|
    @threads << Thread.new do
      while !@abort 
        system("#{cmd} #{DRb.uri} #{index}")
      end
    end
  end
end