houdini/lib/parallel_ar.rb

17 lines
327 B
Ruby
Raw Normal View History

require 'parallel'
module ParallelAr
def self.reduce(arr, accum, &block)
Parallel.each(arr, in_threads: 8) do |elem|
ActiveRecord::Base.connection_pool.with_connection do
ActiveRecord::Base.transaction do
accum = block.call(accum, elem)
end
end
end
return accum
end
end