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:, mode: :run) ⇒ BaseJob

Returns a new instance of BaseJob.

Parameters:

  • files (Hash)
  • transformer (Kiba::Control)
  • mode (:run, :setup, :info) (defaults to: :run)

    :info mode sets up files only. :setup mode sets up files and handles requirements, including running any necessary jobs to create sources and/or lookups needed by the job. :run does all of the above and runs the job. Since 4.0.0

Since:

  • 2.2.0



27
28
29
30
31
32
33
34
35
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 27

def initialize(files:, transformer:, mode: :run)
  @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)

  unless mode == :info
    report_run_start # defined in Reporter
    handle_requirements # defined in Runner
    @control = Kiba::Control.new
    @context = Kiba::Context.new(control)
    @transformer = transformer
    assemble_control # defined in Runner
  end

  if mode == :run
    run
    set_row_count_instance_variables
    report_run_end # defined in Reporter
  end
end

Instance Attribute Details

#contextObject (readonly)

Since:

  • 2.2.0



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

def context
  @context
end

#controlObject (readonly)

Since:

  • 2.2.0



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

def control
  @control
end

#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

#runObject

Since:

  • 2.2.0



55
56
57
58
59
60
61
62
63
# File 'lib/kiba/extend/jobs/base_job.rb', line 55

def run
  Kiba.run(control)
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