Module: Kiba::Extend::Jobs::Runner

Includes:
Reporter
Included in:
BaseJob
Defined in:
lib/kiba/extend/jobs/runner.rb

Overview

The methods that need to be mixed in to a Job to make it run

These methods are intended to be agnostic of the job segment/step logic, which is why they are separated out into a module

Since:

  • 2.2.0

Defined Under Namespace

Classes: MissingDependencyError

Instance Method Summary collapse

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

Instance Method Details

#add_configObject

This stuff does not get handled by parsing source code

Since:

  • 2.2.0



46
47
48
49
50
# File 'lib/kiba/extend/jobs/runner.rb', line 46

def add_config
  return if config.empty?

  control.config.merge(config)
end

#add_decorationObject

Since:

  • 2.2.0



23
24
25
26
# File 'lib/kiba/extend/jobs/runner.rb', line 23

def add_decoration
  show_me_decoration
  tell_me_decoration
end

#add_destinationsObject

Since:

  • 2.2.0



52
53
54
# File 'lib/kiba/extend/jobs/runner.rb', line 52

def add_destinations
  context.instance_eval(destinations)
end

#add_lookup(config) ⇒ Object

Add lookup tables to the context as methods memoized to instance variables

Since:

  • 2.2.0



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kiba/extend/jobs/runner.rb', line 30

def add_lookup(config)
  key_as_iv = "@#{config.key}".to_sym

  context.define_singleton_method(config.key) do
    if instance_variable_defined?(key_as_iv)
      instance_variable_get(key_as_iv)
    else
      instance_variable_set(
        key_as_iv,
        Lookup.csv_to_hash(**config.args.compact)
      )
    end
  end
end

#add_sourcesObject

Since:

  • 2.2.0



56
57
58
# File 'lib/kiba/extend/jobs/runner.rb', line 56

def add_sources
  context.instance_eval(sources)
end

#assemble_controlObject

Since:

  • 2.2.0



60
61
62
63
64
65
66
67
68
# File 'lib/kiba/extend/jobs/runner.rb', line 60

def assemble_control
  lookups_to_memoized_methods if @files[:lookup]
  parse_job_segments
  add_config
  add_sources
  add_destinations
  add_decoration
  control
end

#check_requirementsObject

Since:

  • 2.2.0



70
71
72
73
74
75
76
77
# File 'lib/kiba/extend/jobs/runner.rb', line 70

def check_requirements
  [@files[:source], @files[:lookup]].compact.flatten.each do |data|
    next unless data.path
    next if File.exist?(data.path)

    fail MissingDependencyError.new(data.key, data.path)
  end
end

#destinationsObject

Since:

  • 2.2.0



79
80
81
82
83
# File 'lib/kiba/extend/jobs/runner.rb', line 79

def destinations
  @files[:destination].map { |config| file_config(config) }
    .map { |src| "destination #{src[:klass]}, **#{src[:args]}" }
    .join("\n")
end

#file_config(config) ⇒ Object

Since:

  • 2.2.0



85
86
87
# File 'lib/kiba/extend/jobs/runner.rb', line 85

def file_config(config)
  {klass: config.klass, args: config.args}
end

#handle_requirementsObject

Since:

  • 2.2.0



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/kiba/extend/jobs/runner.rb', line 89

def handle_requirements
  [@files[:source], @files[:lookup]].compact
    .flatten
    .compact
    .each do |registered|
      next unless registered.required

      registered.required.call
    end

  check_requirements
rescue MissingDependencyError => err
  puts "JOB FAILED: DEPENDENCY ERROR IN: #{err.calling_job}"
  err.info
  exit
end

#lookups_to_memoized_methodsObject

Since:

  • 2.2.0



106
107
108
109
110
# File 'lib/kiba/extend/jobs/runner.rb', line 106

def lookups_to_memoized_methods
  @files[:lookup].each do |config|
    add_lookup(config)
  end
end

#parse_job_segmentsObject

The parts that get generated by parsing of Kiba code blocks

Since:

  • 2.2.0



113
114
115
# File 'lib/kiba/extend/jobs/runner.rb', line 113

def parse_job_segments
  parse_job(control, context, [pre_process, transform, post_process])
end

#show_me_decorationObject

Since:

  • 2.2.0



117
118
119
120
121
122
# File 'lib/kiba/extend/jobs/runner.rb', line 117

def show_me_decoration
  return unless Kiba::Extend.job_show_me

  extend ShowMeJob
  decorate
end

#sourcesObject

Since:

  • 2.2.0



124
125
126
127
128
# File 'lib/kiba/extend/jobs/runner.rb', line 124

def sources
  @files[:source].map { |config| file_config(config) }
    .map { |src| "source #{src[:klass]}, **#{src[:args]}" }
    .join("\n")
end

#tell_me_decorationObject

Since:

  • 2.2.0



130
131
132
133
134
135
# File 'lib/kiba/extend/jobs/runner.rb', line 130

def tell_me_decoration
  return unless Kiba::Extend.job_tell_me

  extend TellMeJob
  decorate
end

#transformObject

Since:

  • 2.2.0



137
138
139
# File 'lib/kiba/extend/jobs/runner.rb', line 137

def transform
  [initial_transforms, @transformer, final_transforms].flatten
end