diff --git a/lib/que/active_record/connection.rb b/lib/que/active_record/connection.rb index aafeb878..9ecefd35 100644 --- a/lib/que/active_record/connection.rb +++ b/lib/que/active_record/connection.rb @@ -42,7 +42,12 @@ def call(job) # 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. - ::ActiveRecord::Base.clear_active_connections! unless job.class.resolve_que_setting(:run_synchronously) + 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 end end diff --git a/spec/que/active_record/connection_spec.rb b/spec/que/active_record/connection_spec.rb index 21458d92..60a2d57b 100644 --- a/spec/que/active_record/connection_spec.rb +++ b/spec/que/active_record/connection_spec.rb @@ -39,7 +39,11 @@ class SecondDatabaseModel < ActiveRecord::Base establish_connection(QUE_URL) end - SecondDatabaseModel.clear_active_connections! + if ::ActiveRecord.version >= Gem::Version.new('7.1') + SecondDatabaseModel.connection_handler.clear_active_connections!(:all) + else + SecondDatabaseModel.clear_active_connections! + end refute SecondDatabaseModel.connection_handler.active_connections? class SecondDatabaseModelJob < Que::Job