Module: Kernel

Defined in:
lib/resque/plugins/safe_fork.rb

Instance Method Summary collapse

Instance Method Details

#safe_fork(count = 1) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/resque/plugins/safe_fork.rb', line 5

def safe_fork(count = 1)
  if Object.const_defined?('ActiveRecord') && ActiveRecord.const_defined?('Base')
    ActiveRecord::Base.lock_optimistically = false
    ActiveRecord::Base.connection_pool.disconnect!
  end  
  
  count.times do |i|
    fork do
      Resque.redis.connect_to_server if Object.const_defined?('Resque')
      yield(i) if block_given?
      exit!
    end
  end
  Process.waitall
end