Module: Eye::Process::Child

Included in:
Eye::Process
Defined in:
lib/eye/process/child.rb

Instance Method Summary collapse

Instance Method Details

#add_childsObject



3
4
5
# File 'lib/eye/process/child.rb', line 3

def add_childs
  add_or_update_childs
end

#add_or_update_childsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/eye/process/child.rb', line 7

def add_or_update_childs
  return unless self[:monitor_children]

  return unless self.up?

  unless self.pid
    warn 'Cant add childs, because no pid'
    return
  end

  now_childs = Eye::SystemResources.childs(self.pid)
  new_childs = []
  exist_childs = []

  now_childs.each do |child_pid|
    if self.childs[child_pid]
      exist_childs << child_pid
    else
      new_childs << child_pid
    end
  end

  removed_childs = self.childs.keys - now_childs

  if new_childs.present?
    new_childs.each do |child_pid|
      self.childs[child_pid] = Eye::ChildProcess.new(child_pid, self[:monitor_children], logger.prefix)
    end
  end

  if removed_childs.present?
    removed_childs.each{|child_pid| remove_child(child_pid) }
  end

  h = {:new => new_childs.size, :removed => removed_childs.size, :exists => exist_childs.size }
  debug "childs info: #{ h.inspect }"

  h
end

#remove_child(child_pid) ⇒ Object



53
54
55
56
# File 'lib/eye/process/child.rb', line 53

def remove_child(child_pid)
  child = self.childs.delete(child_pid)
  child.destroy if child && child.alive?
end

#remove_childsObject



47
48
49
50
51
# File 'lib/eye/process/child.rb', line 47

def remove_childs
  if childs.present?
    childs.keys.each{|child_pid| remove_child(child_pid) }
  end
end