Class: GoodJob::Adapter::InlineBuffer
- Inherits:
-
Object
- Object
- GoodJob::Adapter::InlineBuffer
- Defined in:
- lib/good_job/adapter/inline_buffer.rb
Overview
The InlineBuffer is integrated into the Adapter and captures jobs that have been enqueued inline. The purpose is allow job records to be persisted, in a locked state, while within a transaction, and then execute the jobs after the transaction has been committed to ensure that the jobs do not run within a transaction.
Class Attribute Summary collapse
-
.current_buffer ⇒ GoodJob::Adapter::InlineBuffer?
Current buffer of jobs to be enqueued.
Class Method Summary collapse
-
.capture { ... } ⇒ Proc
This block should be used to wrap the transaction that could enqueue jobs.
- .defer? ⇒ Boolean
-
.perform_now_or_defer(&block) ⇒ Object
Used within the adapter to wrap inline job execution.
Instance Method Summary collapse
- #defer(callable) ⇒ Object
-
#initialize ⇒ InlineBuffer
constructor
A new instance of InlineBuffer.
- #to_proc ⇒ Object
Constructor Details
#initialize ⇒ InlineBuffer
Returns a new instance of InlineBuffer.
58 59 60 |
# File 'lib/good_job/adapter/inline_buffer.rb', line 58 def initialize @callables = [] end |
Class Attribute Details
.current_buffer ⇒ GoodJob::Adapter::InlineBuffer?
Current buffer of jobs to be enqueued.
18 |
# File 'lib/good_job/adapter/inline_buffer.rb', line 18 thread_mattr_accessor :current_buffer |
Class Method Details
.capture { ... } ⇒ Proc
This block should be used to wrap the transaction that could enqueue jobs.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/good_job/adapter/inline_buffer.rb', line 30 def self.capture if current_buffer yield return proc {} end begin self.current_buffer = new yield current_buffer.to_proc ensure self.current_buffer = nil end end |
.defer? ⇒ Boolean
54 55 56 |
# File 'lib/good_job/adapter/inline_buffer.rb', line 54 def self.defer? current_buffer.present? end |
.perform_now_or_defer(&block) ⇒ Object
Used within the adapter to wrap inline job execution
46 47 48 49 50 51 52 |
# File 'lib/good_job/adapter/inline_buffer.rb', line 46 def self.perform_now_or_defer(&block) if defer? current_buffer.defer(block) else yield end end |
Instance Method Details
#defer(callable) ⇒ Object
62 63 64 |
# File 'lib/good_job/adapter/inline_buffer.rb', line 62 def defer(callable) @callables << callable end |
#to_proc ⇒ Object
66 67 68 69 70 |
# File 'lib/good_job/adapter/inline_buffer.rb', line 66 def to_proc proc do @callables.map(&:call) end end |