Class: Bluepill::Group

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Group

Returns a new instance of Group.



6
7
8
9
10
# File 'lib/bluepill/group.rb', line 6

def initialize(name, options = {})
  self.name = name
  self.processes = []
  self.logger = options[:logger]
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/bluepill/group.rb', line 3

def logger
  @logger
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/bluepill/group.rb', line 3

def name
  @name
end

#process_loggerObject

Returns the value of attribute process_logger.



4
5
6
# File 'lib/bluepill/group.rb', line 4

def process_logger
  @process_logger
end

#processesObject

Returns the value of attribute processes.



3
4
5
# File 'lib/bluepill/group.rb', line 3

def processes
  @processes
end

Instance Method Details

#add_process(process) ⇒ Object



12
13
14
15
# File 'lib/bluepill/group.rb', line 12

def add_process(process)
  process.logger = logger.prefix_with(process.name)
  processes << process
end

#determine_initial_stateObject



21
22
23
# File 'lib/bluepill/group.rb', line 21

def determine_initial_state
  processes.each(&:determine_initial_state)
end

#status(process_name = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bluepill/group.rb', line 50

def status(process_name = nil)
  lines = []
  if process_name.nil?
    prefix = name ? '  ' : ''
    lines << "#{name}:" if name

    processes.each do |process|
      lines << format('%s%s(pid:%s): %s', prefix, process.name, process.actual_pid, process.state)
      next unless process.monitor_children?
      process.children.each do |child|
        lines << format('  %s%s: %s', prefix, child.name, child.state)
      end
    end

  else
    processes.each do |process|
      next if process_name != process.name
      lines << format('%s%s(pid:%s): %s', prefix, process.name, process.actual_pid, process.state)
      lines << process.statistics.to_s
    end
  end
  lines << ''
end

#tickObject



17
18
19
# File 'lib/bluepill/group.rb', line 17

def tick
  processes.each(&:tick)
end