Skip to content

Commit

Permalink
use global namespace when checking rails version to avoid conflicts i…
Browse files Browse the repository at this point in the history
…n gettext

git-svn-id: svn+ssh://rubyforge.org/var/svn/spawn/spawn@31 2aabfe31-cc40-457c-aec7-21ad9ce7fb7d
  • Loading branch information
tra committed Mar 9, 2009
1 parent fd63a9d commit bfedf74
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions README
Expand Up @@ -112,6 +112,7 @@ blog post on threading in rails.

Also thanks to all who have helped debug problems and suggest improvements including:
Ahmed Adam, Tristan Schneiter, Scott Haug, Andrew Garfield, Eugene Otto, Dan Sharp,
Olivier Ruffin
Garry Tan, Matt Jankowski (2.2.x fixes)
Tim Kadom, Mauricio Marcon Zaffari (passenger fixes)
<your name here>
Expand Down
4 changes: 2 additions & 2 deletions lib/patches.rb
@@ -1,7 +1,7 @@
# see activerecord/lib/active_record/connection_adaptors/abstract/connection_specification.rb
class ActiveRecord::Base
# reconnect without disconnecting
if Rails::VERSION::MAJOR == 2 && Rails::VERSION::MINOR >= 2
if Spawn::RAILS_2_2
def self.spawn_reconnect(klass=self)
@@connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
establish_connection
Expand All @@ -19,7 +19,7 @@ def self.spawn_reconnect(klass=self)
end

# this patch not needed on Rails 2.x and later
if ::Rails::VERSION::MAJOR == 1
if Spawn::RAILS_1_x
# monkey patch to fix threading problems,
# see: http://dev.rubyonrails.org/ticket/7579
def self.clear_reloadable_connections!
Expand Down
6 changes: 4 additions & 2 deletions lib/spawn.rb
@@ -1,4 +1,6 @@
module Spawn
RAILS_1_x = (::Rails::VERSION::MAJOR == 1)
RAILS_2_2 = (::Rails::VERSION::MAJOR > 2 || (::Rails::VERSION::MAJOR == 2 && ::Rails::VERSION::MINOR >= 2))

# default to forking (unless windows or jruby)
@@method = (RUBY_PLATFORM =~ /(win32|java)/) ? :thread : :fork
Expand Down Expand Up @@ -42,7 +44,7 @@ def spawn(options = {})
yield
elsif options[:method] == :thread || (options[:method] == nil && @@method == :thread)
# for versions before 2.2, check for allow_concurrency
if Rails::VERSION::MAJOR > 2 || (Rails::VERSION::MAJOR == 2 && Rails::VERSION::MINOR >= 2) || ActiveRecord::Base.allow_concurrency
if RAILS_2_2 || ActiveRecord::Base.allow_concurrency
thread_it(options) { yield }
else
@@logger.error("spawn(:method=>:thread) only allowed when allow_concurrency=true")
Expand Down Expand Up @@ -105,7 +107,7 @@ def fork_it(options)
ensure
begin
# to be safe, catch errors on closing the connnections too
if Rails::VERSION::MAJOR >= 2 && Rails::VERSION::MINOR >= 2
if RAILS_2_2
ActiveRecord::Base.connection_handler.clear_all_connections!
else
ActiveRecord::Base.connection.disconnect!
Expand Down

0 comments on commit bfedf74

Please sign in to comment.