Permalink
Browse files

Rework RailsParallel bootup and schema load.

We now unconditionally load the main schema.  This prevents situations
where the app loads with one database and then operates on another,
which confuses ActiveRecord column discovery.

To keep things streamlined, schema generation has been moved to the
Rake module's "launch" method.  The RP runner is launched, and as soon
as Rake gets the signal that the runner is starting, it generates and
sends the schema.  With luck, the schema is ready and sent by the time
the runner needs it.
  • Loading branch information...
1 parent b7aec2c commit 58d24d9bc918feff8899290ef196d0fdd850733c @wisq committed Nov 8, 2011
Showing with 41 additions and 29 deletions.
  1. +1 −1 bin/rails_parallel_worker
  2. +10 −14 lib/rails_parallel/rake.rb
  3. +28 −12 lib/rails_parallel/runner.rb
  4. +2 −2 lib/rails_parallel/runner/parent.rb
@@ -13,7 +13,7 @@ begin
require 'rails_parallel/object_socket'
socket = ObjectSocket.new(IO.for_fd(ARGV.first.to_i))
- socket << :started
+ socket << :starting
rp_master_status 'loading Rails'
puts 'RP: Loading Rails.'
View
@@ -61,26 +61,22 @@ def launch
c_socket.close
@socket = my_socket
- expect(:started)
+ @socket.each_object do |obj|
+ case obj
+ when :starting
+ @socket << schema_file
+ when :started
+ break
+ end
+ end
end
def run(name, ruby_opts, files)
- options = parse_options(ruby_opts)
- schema = schema_file
-
- case @socket.next_object
- when :schema_needed
- @socket << schema
- expect(:started)
- expect(:ready)
- when :ready
- # success
- end
+ expect(:ready)
@socket << {
:name => name,
- :schema => schema,
- :options => options,
+ :options => parse_options(ruby_opts),
:files => files.to_a
}
@@ -28,21 +28,37 @@ def run
private
+ RESTART = 'RP_RESTARTED'
+
def prepare
- $LOAD_PATH << 'test'
- require 'test_helper'
- rescue Mysql2::Error => e
- puts "RP: Test environment failed to load: #{e.message} (#{e.class})"
- @socket << :schema_needed
+ restart = false
+ begin
+ puts "RP: Loading test environment."
+ $LOAD_PATH << 'test'
+ require 'test_helper'
+ rescue Mysql2::Error => e
+ raise e if ENV[RESTART]
+ puts "RP: Test environment failed to load: #{e.message} (#{e.class})"
+ restart = true
+ end
schema_file = @socket.next_object
- puts "RP: Loading #{Rails.env} schema ..."
- Schema.new(schema_file).load_main_db
+ @schema = Schema.new(schema_file)
+
+ unless ENV[RESTART]
+ puts "RP: Loading test schema."
+ @schema.load_main_db
+ end
+
+ if restart
+ puts 'RP: Restarting ...'
+ puts
+ ENV[RESTART] = '1'
+ exec(@script, *ARGV)
+ raise "exec failed"
+ end
- puts 'RP: Restarting ...'
- puts
- exec(@script, *ARGV)
- raise "exec failed"
+ @socket << :started
end
def status(msg)
@@ -55,7 +71,7 @@ def ready
end
def run_suite(params)
- parent = Parent.new(params)
+ parent = Parent.new(@schema, params)
status "running #{parent.name}"
parent.run
end
@@ -24,9 +24,9 @@ class Parent
attr_reader :name
- def initialize(params)
+ def initialize(schema, params)
+ @schema = schema
@name = params[:name]
- @schema = Schema.new(params[:schema])
@options = params[:options]
@files = params[:files]
@max_children = number_of_workers

0 comments on commit 58d24d9

Please sign in to comment.