Class: RuboCop::Cop::Sidekiq::DatabaseConnectionLeak
- Defined in:
- lib/rubocop/cop/sidekiq/database_connection_leak.rb
Overview
Checks for explicit ActiveRecord connection usage in Sidekiq jobs.
Constant Summary collapse
- MSG =
'Avoid using ActiveRecord::Base.connection directly in jobs. Use connection_pool.with_connection.'
Instance Method Summary collapse
Methods included from Sidekiq::Language
#active_job_class?, #perform_call?, #sidekiq_include?, #sidekiq_options_call?
Instance Method Details
#on_def(node) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubocop/cop/sidekiq/database_connection_leak.rb', line 18 def on_def(node) return unless node.method?(:perform) return unless in_sidekiq_job?(node) node.each_descendant(:send) do |send| receiver = send.receiver next unless receiver&.const_name == 'ActiveRecord::Base' next unless send.method?(:connection) add_offense(send) end end |