Module: RocketJob::Sliced

Defined in:
lib/rocket_job/sliced.rb,
lib/rocket_job/sliced/input.rb,
lib/rocket_job/sliced/slice.rb,
lib/rocket_job/sliced/output.rb,
lib/rocket_job/sliced/slices.rb,
lib/rocket_job/sliced/writer/input.rb,
lib/rocket_job/sliced/writer/output.rb,
lib/rocket_job/sliced/encrypted_slice.rb,
lib/rocket_job/sliced/compressed_slice.rb,
lib/rocket_job/sliced/bzip2_output_slice.rb

Defined Under Namespace

Modules: Writer Classes: BZip2OutputSlice, CompressedSlice, EncryptedSlice, Input, Output, Slice, Slices

Class Method Summary collapse

Class Method Details

.factory(type, category, job) ⇒ Object

Returns [RocketJob::Sliced::Slices] for the relevant type and category.

Supports compress and encrypt with [true|false|Hash] values. When [Hash] they must specify whether the apply to the input or output collection types.

Example, compress both input and output collections:

class MyJob < RocketJob::Job
  include RocketJob::Batch
  self.compress = true
end

Example, compress just the output collections:

class MyJob < RocketJob::Job
  include RocketJob::Batch
  self.compress = {output: true}
end

To use the specialized BZip output compressor, and the regular compressor for the input collections:

class MyJob < RocketJob::Job
  include RocketJob::Batch
  self.compress = {output: :bzip2, input: true}
end

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rocket_job/sliced.rb', line 39

def self.factory(type, category, job)
  raise(ArgumentError, "Unknown type: #{type.inspect}") unless %i[input output].include?(type)

  collection_name = "rocket_job.#{type}s.#{job.id}"
  collection_name << ".#{category}" unless category == :main

  args               = {collection_name: collection_name, slice_size: job.slice_size}
  klass              = slice_class(type, job)
  args[:slice_class] = klass if klass

  if type == :input
    RocketJob::Sliced::Input.new(args)
  else
    RocketJob::Sliced::Output.new(args)
  end
end