Sha256: 1906d9d08357942be78a1d0e0389dc9b7c4ebf113cf7ceb493725dcd40927087
Contents?: true
Size: 769 Bytes
Versions: 14
Compression:
Stored size: 769 Bytes
Contents
class SafeFork def self.fork begin # remove our connection so it doesn't get cloned ActiveRecord::Base.remove_connection if defined?(ActiveRecord) # fork a process child = Process.fork do begin # create a new connection and perform the action ActiveRecord::Base.establish_connection if defined?(ActiveRecord) yield ensure # make sure we remove the connection before we're done ActiveRecord::Base.remove_connection if defined?(ActiveRecord) end end ensure # make sure we re-establish the connection before returning to the main instance ActiveRecord::Base.establish_connection if defined?(ActiveRecord) end return child end end
Version data entries
14 entries across 14 versions & 1 rubygems