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

Inherits:
Object
  • Object
show all
Includes:
DependencyHandleable, Parser, Runnable
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, NullJob

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser

#parse_job

Methods included from Runnable

#add_config, #add_decoration, #add_destinations, #add_lookup, #add_sources, #assemble_control, #lookups_to_memoized_methods, #parse_job_segments, #show_me_decoration, #sources, #tell_me_decoration, #transform

Methods included from Reportable

#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

Methods included from DependencyHandleable

#check_requirements, #destinations, #file_config, #handle_requirements, #prep_file, #setup_file_for, #setup_files, #setup_files_for, #setup_source_for, #sources

Constructor Details

#initialize(files:, transformer:) ⇒ BaseJob

Returns a new instance of BaseJob.

Parameters:

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

Since:

  • 2.2.0



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kiba/extend/jobs/base_job.rb', line 18

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



14
15
16
# File 'lib/kiba/extend/jobs/base_job.rb', line 14

def files
  @files
end

#outrowsObject (readonly)

Since:

  • 2.2.0



14
15
16
# File 'lib/kiba/extend/jobs/base_job.rb', line 14

def outrows
  @outrows
end

#srcrowsObject (readonly)

Since:

  • 2.2.0



14
15
16
# File 'lib/kiba/extend/jobs/base_job.rb', line 14

def srcrows
  @srcrows
end

#transformerObject (readonly)

Since:

  • 2.2.0



14
15
16
# File 'lib/kiba/extend/jobs/base_job.rb', line 14

def transformer
  @transformer
end

Instance Method Details

#contextObject

Since:

  • 2.2.0



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

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

#controlObject

Since:

  • 2.2.0



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

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

#runObject

Since:

  • 2.2.0



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/kiba/extend/jobs/base_job.rb', line 36

def run
  report_run_start # defined in Reportable

  %i[source lookup].each do |type|
    handle_requirements(type) # defined in DependencyHandleable
  end

  assemble_control # defined in Runnable
  Kiba.run(control)
  set_row_count_instance_variables
  report_run_end # defined in Reportable
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