Class: RocketJob::Sliced::Writer::Output
- Defined in:
- lib/rocket_job/sliced/writer/output.rb
Overview
Internal class for writing categorized results into output slices
Instance Attribute Summary
Attributes inherited from Null
#append, #categorized_records, #input_slice, #job
Class Method Summary collapse
-
.collect(job, **args) ⇒ Object
Collect output results and write to output collections iff job is collecting output Notes: Partial slices are saved when an exception is raised inside the block.
Instance Method Summary collapse
-
#<<(result) ⇒ Object
Writes the supplied result, RocketJob::Batch::Result or RocketJob::Batch::Results to the relevant collections.
-
#close ⇒ Object
Write categorized results to their relevant collections.
Methods inherited from Null
Constructor Details
This class inherits a constructor from RocketJob::Sliced::Writer::Null
Class Method Details
.collect(job, **args) ⇒ Object
Collect output results and write to output collections iff job is collecting output Notes:
Partial slices are saved when an exception is raised inside the block
30 31 32 33 34 35 |
# File 'lib/rocket_job/sliced/writer/output.rb', line 30 def self.collect(job, **args) writer = job.output_categories.present? ? new(job, **args) : Null.new(job, **args) yield(writer) ensure writer&.close end |
Instance Method Details
#<<(result) ⇒ Object
Writes the supplied result, RocketJob::Batch::Result or RocketJob::Batch::Results to the relevant collections
39 40 41 42 43 44 45 |
# File 'lib/rocket_job/sliced/writer/output.rb', line 39 def <<(result) if result.is_a?(RocketJob::Batch::Results) result.each { |single| extract_categorized_result(single) } else extract_categorized_result(result) end end |
#close ⇒ Object
Write categorized results to their relevant collections
48 49 50 51 52 53 |
# File 'lib/rocket_job/sliced/writer/output.rb', line 48 def close categorized_records.each_pair do |category, results| collection = job.output(category) append ? collection.append(results, input_slice) : collection.insert(results, input_slice) end end |