timeout
This commit is contained in:
parent
f27e753caa
commit
a7678ef54b
|
@ -5,13 +5,14 @@ Want to restart your Rails development server whilst you work? Now you can!
|
|||
watch(%r{^(config|lib)/.*})
|
||||
end
|
||||
|
||||
Five fun options!
|
||||
Lots of fun options!
|
||||
|
||||
* `:port` is the port number to run on (default `3000`)
|
||||
* `:environment` is the environment to use (default `development`)
|
||||
* `:start_on_start` will start the server when starting Guard (default `true`)
|
||||
* `:force_run` kills any process that's holding open the listen port before attempting to (re)start Rails (default `false`).
|
||||
* `:deamon` runs the server as a daemon, without any output to the terminal that ran `guard` (default `false`).
|
||||
* `:timeout` waits this number of seconds when restarting the Rails server before reporting there's a problem (default `20`).
|
||||
|
||||
This is super-alpha, but it works for me! Only really hand-tested in Mac OS X. Feel free to fork'n'fix for other
|
||||
OSes, and to add some more real tests.
|
||||
|
|
|
@ -13,7 +13,8 @@ module Guard
|
|||
:port => 3000,
|
||||
:environment => 'development',
|
||||
:start_on_start => true,
|
||||
:force_run => false
|
||||
:force_run => false,
|
||||
:timeout => 20
|
||||
}.merge(options)
|
||||
|
||||
@runner = RailsRunner.new(@options)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
module Guard
|
||||
class RailsRunner
|
||||
MAX_WAIT_COUNT = 10
|
||||
|
||||
attr_reader :options
|
||||
|
||||
def initialize(options)
|
||||
|
@ -10,11 +12,11 @@ module Guard
|
|||
kill_unmanaged_pid! if options[:force_run]
|
||||
run_rails_command!
|
||||
count = 0
|
||||
while !has_pid? && count < 10
|
||||
while !has_pid? && count < MAX_WAIT_COUNT
|
||||
wait_for_pid_action
|
||||
count += 1
|
||||
end
|
||||
!(count == 10)
|
||||
!(count == MAX_WAIT_COUNT)
|
||||
end
|
||||
|
||||
def stop
|
||||
|
@ -48,6 +50,10 @@ module Guard
|
|||
File.file?(pid_file) ? File.read(pid_file).to_i : nil
|
||||
end
|
||||
|
||||
def sleep_time
|
||||
options[:timeout].to_f / MAX_WAIT_COUNT.to_f
|
||||
end
|
||||
|
||||
private
|
||||
def run_rails_command!
|
||||
system build_rails_command
|
||||
|
@ -58,7 +64,7 @@ module Guard
|
|||
end
|
||||
|
||||
def wait_for_pid_action
|
||||
sleep 2
|
||||
sleep sleep_time
|
||||
end
|
||||
|
||||
def kill_unmanaged_pid!
|
||||
|
|
|
@ -86,7 +86,7 @@ describe Guard::RailsRunner do
|
|||
before do
|
||||
pid_stub.returns(false)
|
||||
kill_expectation.never
|
||||
runner.expects(:wait_for_pid_action).times(10)
|
||||
runner.expects(:wait_for_pid_action).times(Guard::RailsRunner::MAX_WAIT_COUNT)
|
||||
end
|
||||
|
||||
it "should act properly" do
|
||||
|
@ -94,4 +94,13 @@ describe Guard::RailsRunner do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#sleep_time' do
|
||||
let(:timeout) { 30 }
|
||||
let(:options) { default_options.merge(:timeout => timeout) }
|
||||
|
||||
it "should adjust the sleep time as necessary" do
|
||||
runner.sleep_time.should == (timeout.to_f / Guard::RailsRunner::MAX_WAIT_COUNT.to_f)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue