Class: Jefe
- Inherits:
-
Object
- Object
- Jefe
- Defined in:
- lib/jefe.rb
Defined Under Namespace
Classes: CLI, ColorPrinter, EM
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Attribute Summary collapse
-
#backend ⇒ Object
Returns the value of attribute backend.
-
#printer ⇒ Object
Returns the value of attribute printer.
-
#process_types ⇒ Object
Returns the value of attribute process_types.
Instance Method Summary collapse
- #add_process_type(name, command) ⇒ Object
-
#initialize ⇒ Jefe
constructor
A new instance of Jefe.
- #load(file) ⇒ Object
- #start(concurrency, port) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ Jefe
Returns a new instance of Jefe.
7 8 9 |
# File 'lib/jefe.rb', line 7 def initialize @process_types = {} end |
Instance Attribute Details
#backend ⇒ Object
Returns the value of attribute backend.
10 11 12 |
# File 'lib/jefe.rb', line 10 def backend @backend end |
#printer ⇒ Object
Returns the value of attribute printer.
10 11 12 |
# File 'lib/jefe.rb', line 10 def printer @printer end |
#process_types ⇒ Object
Returns the value of attribute process_types.
10 11 12 |
# File 'lib/jefe.rb', line 10 def process_types @process_types end |
Instance Method Details
#add_process_type(name, command) ⇒ Object
18 19 20 |
# File 'lib/jefe.rb', line 18 def add_process_type name, command @process_types[name] = command end |
#load(file) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/jefe.rb', line 11 def load file file.split("\n").each do |line| if line =~ /^([A-Za-z0-9_]+):\s*(.+)$/ add_process_type $1, $2 end end end |
#start(concurrency, port) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jefe.rb', line 22 def start concurrency, port processes = [] concurrency.each do |(name, num)| num.times do |i| env = { "PORT" => (port + i) } command = self.process_types[name].gsub(/\$(\w+)/) { env[$1] || ENV[$1] } processes.push ["#{name}.#{i}", command] end port += 100 end self.printer.out "system", "starting" self.backend.start do |b| processes.each do |(name, command)| self.printer.out name, "starting #{command}" b.add name, command end end end |
#stop ⇒ Object
43 44 45 46 |
# File 'lib/jefe.rb', line 43 def stop self.printer.out "system", "stopping" self.backend.stop end |