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.
- #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.
11 12 13 |
# File 'lib/que/adapters/base.rb', line 11 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.
19 20 21 |
# File 'lib/que/adapters/base.rb', line 19 def checkout(&block) raise NotImplementedError end |
#execute(command, params = []) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/que/adapters/base.rb', line 30 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
47 48 49 |
# File 'lib/que/adapters/base.rb', line 47 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.
26 27 28 |
# File 'lib/que/adapters/base.rb', line 26 def wake_worker_after_commit false end |