Class: Chronicle::ETL::Job

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/chronicle/etl/job.rb

Overview

A runner job

TODO: this can probably be merged with JobDefinition. Not clear where the boundaries are

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_definition) {|_self| ... } ⇒ Job

Returns a new instance of Job.

Yields:

  • (_self)

Yield Parameters:



28
29
30
31
32
33
34
35
36
37
# File 'lib/chronicle/etl/job.rb', line 28

def initialize(job_definition)
  @job_definition = job_definition
  @name = @job_definition.definition[:name]
  @extractor_options = @job_definition.extractor_options
  @transformer_options = @job_definition.transformer_options
  @loader_options = @job_definition.loader_options

  set_continuation if use_continuation?
  yield self if block_given?
end

Instance Attribute Details

#extractor_klassObject

Returns the value of attribute extractor_klass.



16
17
18
# File 'lib/chronicle/etl/job.rb', line 16

def extractor_klass
  @extractor_klass
end

#extractor_optionsObject

Returns the value of attribute extractor_options.



16
17
18
# File 'lib/chronicle/etl/job.rb', line 16

def extractor_options
  @extractor_options
end

#job_definitionObject

Returns the value of attribute job_definition.



16
17
18
# File 'lib/chronicle/etl/job.rb', line 16

def job_definition
  @job_definition
end

#loader_klassObject

Returns the value of attribute loader_klass.



16
17
18
# File 'lib/chronicle/etl/job.rb', line 16

def loader_klass
  @loader_klass
end

#loader_optionsObject

Returns the value of attribute loader_options.



16
17
18
# File 'lib/chronicle/etl/job.rb', line 16

def loader_options
  @loader_options
end

#nameObject Also known as: id

Returns the value of attribute name.



16
17
18
# File 'lib/chronicle/etl/job.rb', line 16

def name
  @name
end

#transformer_klassesObject

Returns the value of attribute transformer_klasses.



16
17
18
# File 'lib/chronicle/etl/job.rb', line 16

def transformer_klasses
  @transformer_klasses
end

#transformer_optionsObject

Returns the value of attribute transformer_options.



16
17
18
# File 'lib/chronicle/etl/job.rb', line 16

def transformer_options
  @transformer_options
end

Instance Method Details

#instantiate_extractorObject



39
40
41
42
# File 'lib/chronicle/etl/job.rb', line 39

def instantiate_extractor
  @extractor_klass = @job_definition.extractor_klass
  @extractor_klass.new(@extractor_options)
end

#instantiate_loaderObject



50
51
52
53
# File 'lib/chronicle/etl/job.rb', line 50

def instantiate_loader
  @loader_klass = @job_definition.loader_klass
  @loader_klass.new(@loader_options)
end

#instantiate_transformersObject



44
45
46
47
48
# File 'lib/chronicle/etl/job.rb', line 44

def instantiate_transformers
  @job_definition.transformer_klasses.each_with_index.map do |klass, i|
    klass.new(@transformer_options[i] || {})
  end
end

#save_log?Boolean

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/chronicle/etl/job.rb', line 55

def save_log?
  # TODO: this needs more nuance
  !id.nil?
end

#to_sObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/chronicle/etl/job.rb', line 60

def to_s
  output = "Job summary\n".upcase.bold
  # output = ""
  output += "#{name}:\n" if name
  output += "→ Extracting from #{@job_definition.extractor_klass.description}\n"
  output += options_to_s(@extractor_options)

  @job_definition.transformer_klasses.each do |klass|
    output += "→ Transforming #{klass.description}\n"
  end
  # TODO: transformer options
  output += "→ Loading to #{@job_definition.loader_klass.description}\n"
  output += options_to_s(@loader_options)
  output
end