Module: GoodJob::Bulk
- Defined in:
- lib/good_job/bulk.rb
Defined Under Namespace
Classes: Buffer
Constant Summary collapse
- Error =
Class.new(StandardError)
Class Attribute Summary collapse
-
.current_buffer ⇒ GoodJob::Bulk::Buffer?
Current buffer of jobs to be enqueued.
Class Method Summary collapse
-
.capture(active_jobs = nil, queue_adapter: nil, &block) ⇒ nil, Array<ActiveJob::Base>
Capture jobs to a buffer.
-
.enqueue(active_jobs = nil, &block) ⇒ Array<ActiveJob::Base>
Capture jobs to a buffer and enqueue them all at once; or enqueue the current buffer.
-
.unbuffer ⇒ void
Temporarily unset the current buffer; used to enqueue buffered jobs.
Class Attribute Details
.current_buffer ⇒ GoodJob::Bulk::Buffer?
Current buffer of jobs to be enqueued.
13 |
# File 'lib/good_job/bulk.rb', line 13 thread_mattr_accessor :current_buffer |
Class Method Details
.capture(active_jobs = nil, queue_adapter: nil, &block) ⇒ nil, Array<ActiveJob::Base>
Capture jobs to a buffer. Pass either a block, or specific Active Jobs to be buffered.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/good_job/bulk.rb', line 19 def self.capture(active_jobs = nil, queue_adapter: nil, &block) raise(ArgumentError, "Use either the block form or the argument form, not both") if block && active_jobs if block buffer = Buffer.new buffer.capture(&block) buffer.active_jobs elsif current_buffer current_buffer&.add(active_jobs, queue_adapter: queue_adapter) end end |
.enqueue(active_jobs = nil, &block) ⇒ Array<ActiveJob::Base>
Capture jobs to a buffer and enqueue them all at once; or enqueue the current buffer.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/good_job/bulk.rb', line 34 def self.enqueue(active_jobs = nil, &block) raise(ArgumentError, "Use either the block form or the argument form, not both") if block && active_jobs buffer = Buffer.new if block buffer.capture(&block) buffer.enqueue buffer.active_jobs elsif active_jobs.present? buffer.add(active_jobs) buffer.enqueue buffer.active_jobs elsif current_buffer.present? current_buffer.enqueue current_buffer.active_jobs end end |
.unbuffer ⇒ void
This method returns an undefined value.
Temporarily unset the current buffer; used to enqueue buffered jobs.
54 55 56 57 58 59 60 |
# File 'lib/good_job/bulk.rb', line 54 def self.unbuffer original_buffer = current_buffer self.current_buffer = nil yield ensure self.current_buffer = original_buffer end |