module Que::ActiveRecord::Connection::JobMiddleware
def call(job)
def call(job) yield # ActiveRecord will check out connections to the current thread when # queries are executed and not return them to the pool until # explicitly requested to. I'm not wild about this API design, and # it doesn't pose a problem for the typical case of workers using a # single PG connection (since we ensure that connection is checked # in and checked out responsibly), but since ActiveRecord supports # connections to multiple databases, it's easy for people using that # feature to unknowingly leak connections to other databases. So, # take the additional step of telling ActiveRecord to check in all # of the current thread's connections after each job is run. return if job.class.resolve_que_setting(:run_synchronously) if ::ActiveRecord.version >= Gem::Version.new('7.1') ::ActiveRecord::Base.connection_handler.clear_active_connections!(:all) else ::ActiveRecord::Base.clear_active_connections! end end