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:
1 parent
de62d0655e
commit
48f764e347
2 files changed
+21
-14
No files matched your search
+20
-13
@@ -15,6 +15,9 @@ class Foreman::Engine
|
|||||||
attr_reader :directory
|
attr_reader :directory
|
||||||
attr_reader :options
|
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
|
COLORS = %w( cyan yellow green magenta red blue intense_cyan intense_yellow
|
||||||
intense_green intense_magenta intense_red, intense_blue )
|
intense_green intense_magenta intense_red, intense_blue )
|
||||||
|
|
||||||
@@ -36,12 +39,28 @@ class Foreman::Engine
|
|||||||
trap("INT") { puts "SIGINT received"; terminate_gracefully }
|
trap("INT") { puts "SIGINT received"; terminate_gracefully }
|
||||||
|
|
||||||
assign_colors
|
assign_colors
|
||||||
spawn_processes
|
start ALL_PROCESSES
|
||||||
watch_for_output
|
watch_for_output
|
||||||
watch_for_termination
|
watch_for_termination
|
||||||
terminate_gracefully
|
terminate_gracefully
|
||||||
end
|
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')
|
def stop(name, signal='SIGTERM')
|
||||||
running_processes.each do |pid, process|
|
running_processes.each do |pid, process|
|
||||||
unless name.nil?
|
unless name.nil?
|
||||||
@@ -77,18 +96,6 @@ class Foreman::Engine
|
|||||||
|
|
||||||
private ######################################################################
|
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
|
def base_port
|
||||||
options[:port] || 5000
|
options[:port] || 5000
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ describe "Foreman::Engine", :fakefs do
|
|||||||
stub(Process).fork
|
stub(Process).fork
|
||||||
any_instance_of(Foreman::Engine) do |engine|
|
any_instance_of(Foreman::Engine) do |engine|
|
||||||
stub(engine).info
|
stub(engine).info
|
||||||
stub(engine).spawn_processes
|
stub(engine).start
|
||||||
stub(engine).watch_for_termination
|
stub(engine).watch_for_termination
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in new issue
Block a user