From 571fb180df150496f877323e85c0f7ea633b6fa7 Mon Sep 17 00:00:00 2001 From: Isaac Seymour Date: Wed, 22 Apr 2020 12:05:40 +0100 Subject: [PATCH] Cherry pick [chanks/que#166][166] This should help with using a secondary database connection pool inside Que jobs. Original issue is [chanks/que#166][166] [166]: https://github.com/que-rb/que/issues/166 --- lib/que/adapters/active_record.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/que/adapters/active_record.rb b/lib/que/adapters/active_record.rb index b210da26..9b4333f2 100644 --- a/lib/que/adapters/active_record.rb +++ b/lib/que/adapters/active_record.rb @@ -63,7 +63,13 @@ def add_to_transaction private def checkout_activerecord_adapter(&block) - ::ActiveRecord::Base.connection_pool.with_connection(&block) + if defined?(::Rails.application.executor) + ::Rails.application.executor.wrap do + ::ActiveRecord::Base.connection_pool.with_connection(&block) + end + else + ::ActiveRecord::Base.connection_pool.with_connection(&block) + end end end end