Skip to content

Commit

Permalink
Merge branch 'pull_423'
Browse files Browse the repository at this point in the history
Cherry pick PR que-rb#423
  • Loading branch information
owst committed Jul 12, 2024
2 parents 80d6067 + dcdbe94 commit 6cca7c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/que/active_record/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion spec/que/active_record/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6cca7c7

Please sign in to comment.