Skip to content

Commit

Permalink
Fix deprecation warning in rails 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathonMA committed Dec 3, 2023
1 parent bcec606 commit 5a85229
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/que.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ def connection=(conn)
if conn.to_s == 'ActiveRecord'
# Load and setup AR compatibility.
require_relative 'que/active_record/connection'
m = Que::ActiveRecord::Connection::JobMiddleware
m =
if ::ActiveRecord.gem_version >= Gem::Version.new('7.1')
Que::ActiveRecord::Connection::JobMiddlewareRails71
else
Que::ActiveRecord::Connection::JobMiddleware
end
job_middleware << m unless job_middleware.include?(m)
Que::ActiveRecord::Connection.method(:checkout)
else
Expand Down
10 changes: 10 additions & 0 deletions lib/que/active_record/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ def call(job)
end
end
end

module JobMiddlewareRails71
class << self
def call(job)
yield

::ActiveRecord::Base.connection_handler.clear_active_connections!(:all) unless job.class.resolve_que_setting(:run_synchronously)
end
end
end
end
end
end

0 comments on commit 5a85229

Please sign in to comment.