2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/hydra/safe_fork.rb', line 2
def self.fork
begin
connection = ActiveRecord::Base.remove_connection if defined?(ActiveRecord)
child = Process.fork do
begin
begin
ActiveRecord::Base.establish_connection((connection || {}).merge({:allow_concurrency => true})) if defined?(ActiveRecord)
rescue ActiveRecord::AdapterNotSpecified
end
yield
ensure
ActiveRecord::Base.remove_connection if defined?(ActiveRecord)
end
end
ensure
begin
ActiveRecord::Base.establish_connection((connection || {}).merge({:allow_concurrency => true})) if defined?(ActiveRecord)
rescue ActiveRecord::AdapterNotSpecified
end
end
return child
end
|