Refactor #spawn_processes into #start(name)

When passed nil (aka ALL_PROCESSES) #start will start all processes in the
Procfile as per existing behavior
This commit is contained in:
R. Tyler Croy
2012-04-10 20:35:59 -07:00
parent de62d0655e
commit 48f764e347
2 changed files with 21 additions and 14 deletions
+20 -13
View File
@@ -15,6 +15,9 @@ class Foreman::Engine
attr_reader :directory
attr_reader :options
# This constant is here to make the invocations of #start and #stop methods
# clearer
ALL_PROCESSES = nil
COLORS = %w( cyan yellow green magenta red blue intense_cyan intense_yellow
intense_green intense_magenta intense_red, intense_blue )
@@ -36,12 +39,28 @@ class Foreman::Engine
trap("INT") { puts "SIGINT received"; terminate_gracefully }
assign_colors
spawn_processes
start ALL_PROCESSES
watch_for_output
watch_for_termination
terminate_gracefully
end
def start(name)
concurrency = Foreman::Utils.parse_concurrency(@options[:concurrency])
procfile.entries.each do |entry|
unless name == ALL_PROCESSES
next unless entry.name == name
end
reader, writer = (IO.method(:pipe).arity == 0 ? IO.pipe : IO.pipe("BINARY"))
entry.spawn(concurrency[entry.name], writer, @directory, @environment, port_for(entry, 1, base_port)).each do |process|
running_processes[process.pid] = process
readers[process] = reader
end
end
end
def stop(name, signal='SIGTERM')
running_processes.each do |pid, process|
unless name.nil?
@@ -77,18 +96,6 @@ class Foreman::Engine
private ######################################################################
def spawn_processes
concurrency = Foreman::Utils.parse_concurrency(@options[:concurrency])
procfile.entries.each do |entry|
reader, writer = (IO.method(:pipe).arity == 0 ? IO.pipe : IO.pipe("BINARY"))
entry.spawn(concurrency[entry.name], writer, @directory, @environment, port_for(entry, 1, base_port)).each do |process|
running_processes[process.pid] = process
readers[process] = reader
end
end
end
def base_port
options[:port] || 5000
end
+1 -1
View File
@@ -57,7 +57,7 @@ describe "Foreman::Engine", :fakefs do
stub(Process).fork
any_instance_of(Foreman::Engine) do |engine|
stub(engine).info
stub(engine).spawn_processes
stub(engine).start
stub(engine).watch_for_termination
end
end