Skip to content

Commit

Permalink
Add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgi committed Jan 4, 2024
1 parent b7e32f0 commit e675fee
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/que/active_record/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
module Que
module ActiveRecord
class << self
# Use Rails' executor (if present) to make sure that the connection
# we're using isn't taken from us while the block runs. See
# https://github.com/que-rb/que/issues/166#issuecomment-274218910
def wrap_in_rails_executor(&block)
if defined?(::Rails.application.executor)
::Rails.application.executor.wrap(&block)
Expand All @@ -21,6 +18,9 @@ class << self

# Check out a PG::Connection object from ActiveRecord's pool.
def checkout
# Use Rails' executor (if present) to make sure that the connection
# we're using isn't taken from us while the block runs. See
# https://github.com/que-rb/que/issues/166#issuecomment-274218910
Que::ActiveRecord.wrap_in_rails_executor do
::ActiveRecord::Base.connection_pool.with_connection do |conn|
yield conn.raw_connection
Expand All @@ -32,6 +32,9 @@ def checkout
module JobMiddleware
class << self
def call(job)
# Use Rails' executor (if present) to make sure that the connection
# used by the job isn't returned to the pool prematurely. See
# https://github.com/que-rb/que/issues/411
Que::ActiveRecord.wrap_in_rails_executor do
yield
end
Expand Down

0 comments on commit e675fee

Please sign in to comment.