oop_rails_server 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5efc04e1524d7817cd6199a48cc343b9282a49d1
4
- data.tar.gz: 57deb64381f3d70a18b9864b0ca40def8972ad59
3
+ metadata.gz: 64166a5f8c1b10c4954ae6fbee47d79fee0c1065
4
+ data.tar.gz: b9e67fb02b818e4d65a5189a91096d82f33733e9
5
5
  SHA512:
6
- metadata.gz: 8c5f65df9dbc007b2431e4a5ac3175650ca46232baf93c33820f39e321e2ee268c6e08f62b0b9f77dde947d1768808cf13e9fcc46614fba08ef3ee24cf078ac8
7
- data.tar.gz: 40ecaeba3c9683b7fc55f9b2bbbb4caa7efb1abda0bd273fa4bf22150c77390396e83e2b159488000a810ad04aa59217603e730161e6fda306d0932c9081e3b2
6
+ metadata.gz: 06e6d7d246ddb75ed3e6866505f34f2714c7ad8b94bb8d79899eb916c514dbd877bbd82b8fa8bc27959733e4abeed60edebb0ce19058a558350fbbb0a61bdaa1
7
+ data.tar.gz: c362495d9d4b97c349dd60d87c7953d55b61c8eff112f3166fd793a76067e77452e42d56a6b90d8cd95d86cf96916022e7f2649550ccb50859b5489a288a0e5d
data/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # `oop_rails_server` Releases
2
2
 
3
+ ## 0.0.12, 4 October 2015
4
+
5
+ * Much better error output if the Rails server fails to start up, and willingness to keep trying if it returns an
6
+ error 500 instead of 200 -- occasionally this can happen immediately after startup, on some platforms.
7
+
3
8
  ## 0.0.11, 4 October 2015
4
9
 
5
10
  * Bump up the timeout we use for verifying that the server has started up properly. Travis CI with JRuby sometimes
@@ -153,6 +153,23 @@ module OopRailsServer
153
153
  end
154
154
  end
155
155
 
156
+ def raise_startup_failed_error!(elapsed_time, exception)
157
+ last_lines = server_logfile = nil
158
+ if File.exist?(server_output_file) && File.readable?(server_output_file)
159
+ server_logfile = server_output_file
160
+ File::Tail::Logfile.open(server_output_file, :break_if_eof => true) do |f|
161
+ f.extend(File::Tail)
162
+ last_lines ||= [ ]
163
+ begin
164
+ f.tail(100) { |l| last_lines << l }
165
+ rescue File::Tail::BreakException
166
+ # ok
167
+ end
168
+ end
169
+ end
170
+
171
+ raise FailedStartupError.new(elapsed_time, exception, server_logfile, last_lines)
172
+ end
156
173
 
157
174
  def setup_directories!
158
175
  return if @directories_setup
@@ -268,7 +285,7 @@ EOS
268
285
 
269
286
  def start_server!
270
287
  output = server_output_file
271
- cmd = "rails server -p #{port} > '#{output}' 2>&1"
288
+ cmd = "bundle exec rails server -p #{port} > '#{output}' 2>&1"
272
289
  safe_system(cmd, "starting 'rails server' on port #{port}", :background => true)
273
290
 
274
291
  server_pid_file = File.join(rails_root, 'tmp', 'pids', 'server.pid')
@@ -301,9 +318,9 @@ EOS
301
318
  end
302
319
 
303
320
  class FailedStartupError < StandardError
304
- attr_reader :timeout, :verify_exception, :server_logfile, :last_lines
321
+ attr_reader :timeout, :verify_exception_or_message, :server_logfile, :last_lines
305
322
 
306
- def initialize(timeout, verify_exception, server_logfile, last_lines)
323
+ def initialize(timeout, verify_exception_or_message, server_logfile, last_lines)
307
324
  message = %{The out-of-process Rails server failed to start up properly and start responding to requests,
308
325
  even after #{timeout.round} seconds. This typically means you've added code that prevents it from
309
326
  even starting up -- most likely, a syntax error in a class or other error that stops it
@@ -328,7 +345,7 @@ The last #{last_lines.length} lines of this log are:
328
345
  super(message)
329
346
 
330
347
  @timeout = timeout
331
- @verify_exception = verify_exception
348
+ @verify_exception_or_message = verify_exception_or_message
332
349
  @server_logfile = server_logfile
333
350
  @last_lines = last_lines
334
351
  end
@@ -342,39 +359,28 @@ The last #{last_lines.length} lines of this log are:
342
359
 
343
360
  data = nil
344
361
  start_time = Time.now
345
- while (! data)
362
+ last_exception = nil
363
+
364
+ while Time.now < (start_time + SERVER_VERIFY_TIMEOUT)
365
+ sleep 0.1
346
366
  begin
347
367
  data = Net::HTTP.get_response(uri)
348
368
  rescue Errno::ECONNREFUSED, EOFError => e
349
- if Time.now > (start_time + SERVER_VERIFY_TIMEOUT)
350
- last_lines = server_logfile = nil
351
- if File.exist?(server_output_file) && File.readable?(server_output_file)
352
- server_logfile = server_output_file
353
- File::Tail::Logfile.open(server_output_file, :break_if_eof => true) do |f|
354
- f.extend(File::Tail)
355
- last_lines ||= [ ]
356
- begin
357
- f.tail(100) { |l| last_lines << l }
358
- rescue File::Tail::BreakException
359
- # ok
360
- end
361
- end
362
- end
363
-
364
- raise FailedStartupError.new(Time.now - start_time, e, server_logfile, last_lines)
365
- end
366
- # keep waiting
367
- sleep 0.1
369
+ last_exception = e
368
370
  end
371
+
372
+ $stderr.puts "TRYING..."
373
+ break if data && data.code && data.code.to_s == '200'
369
374
  end
370
375
 
371
- unless data.code.to_s == '200'
372
- raise "'#{server_verify_url}' returned #{data.code.inspect}, not 200"
376
+ unless data && data.code && data.code.to_s == '200'
377
+ raise_startup_failed_error!(Time.now - start_time, last_exception || "'#{server_verify_url}' returned #{data.code.inspect}, not 200")
373
378
  end
379
+
374
380
  result = data.body.strip
375
381
 
376
382
  unless result =~ /^Rails\s+version\s*:\s*(\d+\.\d+\.\d+)\s*\n+\s*Ruby\s+version\s*:\s*(\d+\..*?)\s*\n+\s*Ruby\s+engine:\s*(.*?)\s*\n?$/mi
377
- raise "'#{server_verify_url}' returned: #{result.inspect}"
383
+ raise_startup_failed_error!(Time.now - start_time, "'#{server_verify_url}' returned: #{result.inspect}")
378
384
  end
379
385
  actual_version = $1
380
386
  ruby_version = $2
@@ -1,3 +1,3 @@
1
1
  module OopRailsServer
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oop_rails_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Geweke