Module: Cognizant::Process::Children

Included in:
Cognizant::Process
Defined in:
lib/cognizant/process/children.rb

Instance Method Summary collapse

Instance Method Details

#create_child_process(child_pid) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cognizant/process/children.rb', line 23

def create_child_process(child_pid)
  name = "<child(pid:#{child_pid})>"
  attributes = @child_process_attributes.merge({ name: name, autostart: false }) # We do not have control over child process' lifecycle, so avoid even attempting to maintain its state with autostart.

  child = Cognizant::Process.new(nil, attributes, &@child_process_block)
  child.instance_variable_set(:@application, @application)
  # TODO: Reset pidfile?
  child.write_pid(child_pid)
  @children << child
  child.monitor
end

#refresh_children!Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cognizant/process/children.rb', line 4

def refresh_children!
  # First prune the list of dead children.
  @children.delete_if do |child|
    !child.process_running?
  end

  # Add new found children to the list.
  new_children_pids = Cognizant::System.get_children(@process_pid) - @children.map(&:cached_pid)

  unless new_children_pids.empty?
    Log[self].info "Existing children: #{@children.collect{ |c| c.cached_pid }.join(",")}. Got new children: #{new_children_pids.inspect} for #{@process_pid}."
  end

  # Construct a new process wrapper for each new found children.
  new_children_pids.each do |child_pid|
    create_child_process(child_pid)
  end
end