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(*args) ⇒ Object
- #execute_prepared(name, params = []) ⇒ Object
-
#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 prompts a worker to wake up after the current transaction commits.
Constructor Details
#initialize(thing = nil) ⇒ Base
Returns a new instance of Base.
9 10 11 |
# File 'lib/que/adapters/base.rb', line 9 def initialize(thing = nil) @statement_mutex = Mutex.new 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.
17 18 19 |
# File 'lib/que/adapters/base.rb', line 17 def checkout(&block) raise NotImplementedError end |
#execute(*args) ⇒ Object
28 29 30 |
# File 'lib/que/adapters/base.rb', line 28 def execute(*args) checkout { |conn| conn.async_exec(*args) } end |
#execute_prepared(name, params = []) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/que/adapters/base.rb', line 32 def execute_prepared(name, params = []) checkout do |conn| unless statements_prepared(conn)[name] conn.prepare("que_#{name}", SQL[name]) statements_prepared(conn)[name] = true end conn.exec_prepared("que_#{name}", params) end end |
#wake_worker_after_commit ⇒ Object
Called after a job is queued in async mode, to prompts a worker to wake up after the current transaction commits. Not all adapters will implement this.
24 25 26 |
# File 'lib/que/adapters/base.rb', line 24 def wake_worker_after_commit false end |