Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/que/active_record/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ 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!
::ActiveRecord::Base.clear_active_connections! unless job.class.resolve_que_setting(:run_synchronously)
end
end
end
Expand Down
12 changes: 10 additions & 2 deletions spec/que/active_record/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
describe Que::ActiveRecord::Connection::JobMiddleware do
before do
Que.connection = ::ActiveRecord
end

it "should clear connections to secondary DBs between jobs" do
class SecondDatabaseModel < ActiveRecord::Base
establish_connection(QUE_URL)
end
Expand All @@ -49,10 +47,20 @@ def run(*args)
SecondDatabaseModel.connection.execute("SELECT 1")
end
end
end

it "should clear connections to secondary DBs between jobs" do
SecondDatabaseModelJob.run

refute SecondDatabaseModel.connection_handler.active_connections?
end


it "shouldn't clear connections to secondary DBs between jobs if run_synchronously is enabled " do
Que::Job.run_synchronously = true
SecondDatabaseModelJob.run

assert SecondDatabaseModel.connection_handler.active_connections?
end
end
end