Skip to content

Commit

Permalink
Backward compatibility with activerecord < 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgi committed Dec 5, 2023
1 parent 5b1ff2c commit dcdbe94
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.connection_handler.clear_active_connections!(:all) 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.connection_handler.clear_active_connections!(:all)
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 dcdbe94

Please sign in to comment.