Module: Que::ActiveRecord::Connection::JobMiddleware

Defined in:
lib/que/active_record/connection.rb

Class Method Summary collapse

Class Method Details

.call(job) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/que/active_record/connection.rb', line 32

def call(job)
  yield

  # ActiveRecord will check out connections to the current thread when
  # queries are executed and not return them to the pool until
  # explicitly requested to. I'm not wild about this API design, and
  # it doesn't pose a problem for the typical case of workers using a
  # single PG connection (since we ensure that connection is checked
  # in and checked out responsibly), but since ActiveRecord supports
  # connections to multiple databases, it's easy for people using that
  # 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!
end