From 3af0dfb4aed2409db61b85a123bb634a1264f7d1 Mon Sep 17 00:00:00 2001 From: David Dollar Date: Thu, 2 Feb 2012 17:26:25 -0500 Subject: [PATCH] bring back single process starting --- lib/foreman/cli.rb | 5 +++-- lib/foreman/engine.rb | 2 +- spec/foreman/cli_spec.rb | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/foreman/cli.rb b/lib/foreman/cli.rb index eb7cd2a..4f21a34 100644 --- a/lib/foreman/cli.rb +++ b/lib/foreman/cli.rb @@ -10,7 +10,7 @@ class Foreman::CLI < Thor class_option :procfile, :type => :string, :aliases => "-f", :desc => "Default: Procfile" - desc "start", "Start the application" + desc "start [PROCESS]", "Start the application (or a specific PROCESS)" class_option :procfile, :type => :string, :aliases => "-f", :desc => "Default: Procfile" class_option :app_root, :type => :string, :aliases => "-d", :desc => "Default: Procfile directory" @@ -27,8 +27,9 @@ class Foreman::CLI < Thor end end - def start + def start(process=nil) check_procfile! + engine.options[:concurrency] = "#{process}=1" if process engine.start end diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index 093bf71..9adef78 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -23,7 +23,7 @@ class Foreman::Engine def initialize(procfile, options={}) @procfile = Foreman::Procfile.new(procfile) @directory = options[:app_root] || File.expand_path(File.dirname(procfile)) - @options = options + @options = options.dup @environment = read_environment_files(options[:env]) @output_mutex = Mutex.new end diff --git a/spec/foreman/cli_spec.rb b/spec/foreman/cli_spec.rb index a18d982..100e020 100644 --- a/spec/foreman/cli_spec.rb +++ b/spec/foreman/cli_spec.rb @@ -3,6 +3,8 @@ require "foreman/cli" describe "Foreman::CLI", :fakefs do subject { Foreman::CLI.new } + let(:engine) { subject.send(:engine) } + let(:entries) { engine.procfile.entries.inject({}) { |h,e| h.update(e.name => e) } } describe "start" do describe "with a non-existent Procfile" do @@ -22,6 +24,15 @@ describe "Foreman::CLI", :fakefs do mock.instance_of(Foreman::Engine).start subject.start end + + it "can run a single process" do + dont_allow(subject).error + stub(engine).watch_for_output + stub(engine).watch_for_termination + mock(entries["alpha"]).spawn(1, is_a(IO), engine.directory, {}, 5000) { [] } + mock(entries["bravo"]).spawn(0, is_a(IO), engine.directory, {}, 5100) { [] } + subject.start("alpha") + end end end