module Que::ActiveRecord::Connection
Private Class Methods
checkout() { |raw_connection| ... }
click to toggle source
Check out a PG::Connection object from ActiveRecord’s pool.
# File lib/que/active_record/connection.rb, line 10 def checkout wrap_in_rails_executor do ::ActiveRecord::Base.connection_pool.with_connection do |conn| yield conn.raw_connection end end end
wrap_in_rails_executor() { || ... }
click to toggle source
Use Rails’ executor (if present) to make sure that the connection we’re using isn’t taken from us while the block runs. See github.com/que-rb/que/issues/166#issuecomment-274218910
# File lib/que/active_record/connection.rb, line 21 def wrap_in_rails_executor(&block) if defined?(::Rails.application.executor) ::Rails.application.executor.wrap(&block) else yield end end