Class: Que::Adapters::Base
- Inherits:
-
Object
- Object
- Que::Adapters::Base
- Defined in:
- lib/que/adapters/base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#checkout(&block) ⇒ Object
The only method that adapters really need to implement.
-
#cleanup! ⇒ Object
Called after Que has returned its connection to whatever pool it’s using.
- #execute(command, params = []) ⇒ Object
- #in_transaction? ⇒ Boolean
-
#initialize(thing = nil) ⇒ Base
constructor
A new instance of Base.
-
#wake_worker_after_commit ⇒ Object
Called after a job is queued in async mode, to prompt a worker to wake up after the current transaction commits.
Constructor Details
#initialize(thing = nil) ⇒ Base
Returns a new instance of Base.
14 15 16 |
# File 'lib/que/adapters/base.rb', line 14 def initialize(thing = nil) @prepared_statements = {} end |
Instance Method Details
#checkout(&block) ⇒ Object
The only method that adapters really need to implement. Should lock a PG::Connection (or something that acts like a PG::Connection) so that no other threads are using it and yield it to the block. Should also be re-entrant.
22 23 24 |
# File 'lib/que/adapters/base.rb', line 22 def checkout(&block) raise NotImplementedError end |
#cleanup! ⇒ Object
Called after Que has returned its connection to whatever pool it’s using.
28 29 |
# File 'lib/que/adapters/base.rb', line 28 def cleanup! end |
#execute(command, params = []) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/que/adapters/base.rb', line 38 def execute(command, params = []) params = params.map do |param| case param # The pg gem unfortunately doesn't convert fractions of time instances, so cast them to a string. when Time then param.strftime("%Y-%m-%d %H:%M:%S.%6N %z") when Array, Hash then JSON_MODULE.dump(param) else param end end cast_result \ case command when Symbol then execute_prepared(command, params) when String then execute_sql(command, params) end end |
#in_transaction? ⇒ Boolean
55 56 57 |
# File 'lib/que/adapters/base.rb', line 55 def in_transaction? checkout { |conn| conn.transaction_status != ::PG::PQTRANS_IDLE } end |
#wake_worker_after_commit ⇒ Object
Called after a job is queued in async mode, to prompt a worker to wake up after the current transaction commits. Not all adapters will implement this.
34 35 36 |
# File 'lib/que/adapters/base.rb', line 34 def wake_worker_after_commit false end |