Method: Vines::Storage::Sql.with_connection
- Defined in:
- lib/vines/storage/sql.rb
.with_connection(method, args = {}) ⇒ Object
Wrap the method with ActiveRecord connection pool logic, so we properly return connections to the pool when we’re finished with them. This also defers the original method by pushing it onto the EM thread pool because ActiveRecord uses blocking IO.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vines/storage/sql.rb', line 30 def self.with_connection(method, args={}) deferrable = args.key?(:defer) ? args[:defer] : true old = instance_method(method) define_method method do |*args| ActiveRecord::Base.connection_pool.with_connection do old.bind(self).call(*args) end end defer(method) if deferrable end |