Class: Que::Adapters::ActiveRecord
- Defined in:
- lib/que/adapters/active_record.rb
Defined Under Namespace
Classes: TransactionCallback
Instance Method Summary collapse
Methods inherited from Base
#execute, #in_transaction?, #initialize
Constructor Details
This class inherits a constructor from Que::Adapters::Base
Instance Method Details
#checkout ⇒ Object
6 7 8 |
# File 'lib/que/adapters/active_record.rb', line 6 def checkout checkout_activerecord_adapter { |conn| yield conn.raw_connection } end |
#cleanup! ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/que/adapters/active_record.rb', line 19 def cleanup! # ActiveRecord will check out connections to the current thread when # queries are executed and not return them to the pool until # explicitly requested to. The wisdom of this API is questionable, 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 between jobs. ::ActiveRecord::Base.clear_active_connections! end |
#wake_worker_after_commit ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/que/adapters/active_record.rb', line 10 def wake_worker_after_commit # Works with ActiveRecord 3.2 and 4 (possibly earlier, didn't check) if in_transaction? checkout_activerecord_adapter { |adapter| adapter.add_transaction_record(TransactionCallback.new) } else Que.wake! end end |