Class: Kiba::Extend::Jobs::BaseJob Abstract

Inherits:
Object
  • Object
show all
Includes:
Parser, Runner
Defined in:
lib/kiba/extend/jobs/base_job.rb

Overview

This class is abstract.

Abstract definition of Job and job interface

Since:

  • 2.2.0

Direct Known Subclasses

Job, JsonToCsvJob, MarcJob

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser

#parse_job

Methods included from Runner

#add_config, #add_decoration, #add_destinations, #add_lookup, #add_sources, #assemble_control, #check_requirements, #destinations, #file_config, #handle_requirements, #lookups_to_memoized_methods, #parse_job_segments, #show_me_decoration, #sources, #tell_me_decoration, #transform

Methods included from Reporter

#desc_and_tags, #get_duration, #minimal_end, #minimal_start, #normal_end, #normal_start, #put_file_details, #report_run_end, #report_run_start, #row_report, #start_and_def, #start_label, #tags, #verbose_end, #verbose_start

Constructor Details

#initialize(files:, transformer:) ⇒ BaseJob

Returns a new instance of BaseJob.

Parameters:

  • files (Hash)
  • transformer (Kiba::Control)

Since:

  • 2.2.0



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kiba/extend/jobs/base_job.rb', line 23

def initialize(files:, transformer:)
  @destination_key = files[:destination].is_a?(Symbol) ?
    files[:destination] :
    files[:destination].first

  if caller(2, 5).join(" ")["block in handle_requirements"]
    @dependency = true
  end
  extend DependencyJob if @dependency

  @files = setup_files(files.transform_values { |v| [v].flatten })
  @transformer = transformer
end

Instance Attribute Details

#filesObject (readonly)

Since:

  • 2.2.0



19
20
21
# File 'lib/kiba/extend/jobs/base_job.rb', line 19

def files
  @files
end

#outrowsObject (readonly)

Since:

  • 2.2.0



19
20
21
# File 'lib/kiba/extend/jobs/base_job.rb', line 19

def outrows
  @outrows
end

#srcrowsObject (readonly)

Since:

  • 2.2.0



19
20
21
# File 'lib/kiba/extend/jobs/base_job.rb', line 19

def srcrows
  @srcrows
end

#transformerObject (readonly)

Since:

  • 2.2.0



19
20
21
# File 'lib/kiba/extend/jobs/base_job.rb', line 19

def transformer
  @transformer
end

Instance Method Details

#contextObject

Since:

  • 2.2.0



39
# File 'lib/kiba/extend/jobs/base_job.rb', line 39

def context = @context ||= Kiba::Context.new(control)

#controlObject

Since:

  • 2.2.0



37
# File 'lib/kiba/extend/jobs/base_job.rb', line 37

def control = @control ||= Kiba::Control.new

#runObject

Since:

  • 2.2.0



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/kiba/extend/jobs/base_job.rb', line 41

def run
  report_run_start # defined in Reporter
  # defined in Runner
  %i[source lookup].each do |type|
    handle_requirements(type)
  end
  assemble_control # defined in Runner
  Kiba.run(control)
  set_row_count_instance_variables
  report_run_end # defined in Reporter
rescue => err
  puts "JOB FAILED: TRANSFORM ERROR IN: #{job_data.creator}"
  puts "#{err.class.name}: #{err.message}"
  puts "AT:"
  puts err.backtrace.first(10)
  exit
end