Module: Eye::Process::Children

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

Instance Method Summary collapse

Instance Method Details

#add_childrenObject



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

def add_children
  add_or_update_children
end

#add_or_update_childrenObject



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
46
47
48
# File 'lib/eye/process/children.rb', line 7

def add_or_update_children
  return unless self[:monitor_children]
  return unless self.up?
  return if @updating_children
  @updating_children = true

  unless self.pid
    warn "can't add children; pid not set"
    return
  end

  now_children = Eye::SystemResources.children(self.pid)
  new_children = []
  exist_children = []

  now_children.each do |child_pid|
    if self.children[child_pid]
      exist_children << child_pid
    else
      new_children << child_pid
    end
  end

  removed_children = self.children.keys - now_children

  if new_children.present?
    new_children.each do |child_pid|
      cfg = self[:monitor_children].try :update, notify: self[:notify]
      self.children[child_pid] = Eye::ChildProcess.new(child_pid, cfg, logger.prefix, current_actor)
    end
  end

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

  h = { new: new_children.size, removed: removed_children.size, exists: exist_children.size }
  debug { "children info: #{h.inspect}" }

  @updating_children = false
  h
end

#clear_child(child_pid) ⇒ Object



59
60
61
62
# File 'lib/eye/process/children.rb', line 59

def clear_child(child_pid)
  child = self.children.delete(child_pid)
  child.destroy if child && child.alive?
end

#remove_child(child_pid) ⇒ Object



55
56
57
# File 'lib/eye/process/children.rb', line 55

def remove_child(child_pid)
  clear_child(child_pid)
end

#remove_childrenObject



50
51
52
53
# File 'lib/eye/process/children.rb', line 50

def remove_children
  # here should .keys (not each_key), as it copy array of keys
  children.keys.each { |child_pid| clear_child(child_pid) }
end