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
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_config ⇒ Object
This stuff does not get handled by parsing source code
47
48
49
50
51
|
# File 'lib/kiba/extend/jobs/runner.rb', line 47
def add_config
return if config.empty?
control.config.merge(config)
end
|
#add_decoration ⇒ Object
24
25
26
27
|
# File 'lib/kiba/extend/jobs/runner.rb', line 24
def add_decoration
show_me_decoration
tell_me_decoration
end
|
#add_destinations ⇒ Object
53
54
55
|
# File 'lib/kiba/extend/jobs/runner.rb', line 53
def add_destinations
context.instance_eval(destinations)
end
|
#add_lookup(config) ⇒ Object
Add lookup tables to the context as methods memoized to instance
variables
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/kiba/extend/jobs/runner.rb', line 31
def add_lookup(config)
key_as_iv = :"@#{config.key}"
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_sources ⇒ Object
57
58
59
|
# File 'lib/kiba/extend/jobs/runner.rb', line 57
def add_sources
context.instance_eval(sources)
end
|
#assemble_control ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/kiba/extend/jobs/runner.rb', line 61
def assemble_control
lookups_to_memoized_methods if @files[:lookup]
parse_job_segments
add_config
add_sources
add_destinations
add_decoration
control
end
|
#check_requirements(type) ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/kiba/extend/jobs/runner.rb', line 72
def check_requirements(type)
@files[type].flatten.compact.each do |data|
next unless data.path
next if File.exist?(data.path)
fail MissingDependencyError.new(data.key, data.path)
end
end
|
#destinations ⇒ Object
81
82
83
84
85
|
# File 'lib/kiba/extend/jobs/runner.rb', line 81
def destinations
@files[:destination].map { |config| file_config(config) }
.map { |src| "destination #{src[:klass]}, **#{src[:args]}" }
.join("\n")
end
|
#file_config(config) ⇒ Object
87
88
89
|
# File 'lib/kiba/extend/jobs/runner.rb', line 87
def file_config(config)
{klass: config.klass, args: config.args}
end
|
#handle_requirements(type) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/kiba/extend/jobs/runner.rb', line 92
def handle_requirements(type)
deps = @files[type]
return unless deps
deps.flatten
.compact
.each do |registered|
next unless registered.required
registered.required.call
end
check_requirements(type)
rescue MissingDependencyError => err
puts "JOB FAILED: DEPENDENCY ERROR IN: #{err.calling_job}"
err.info
exit
rescue => err
puts "JOB FAILED: Error handling #{type} file dependency for "\
"#{destination_key}: #{err.message}"
end
|
#lookups_to_memoized_methods ⇒ Object
113
114
115
116
117
|
# File 'lib/kiba/extend/jobs/runner.rb', line 113
def lookups_to_memoized_methods
@files[:lookup].each do |config|
add_lookup(config)
end
end
|
#parse_job_segments ⇒ Object
The parts that get generated by parsing of Kiba code blocks
120
121
122
|
# File 'lib/kiba/extend/jobs/runner.rb', line 120
def parse_job_segments
parse_job(control, context, [pre_process, transform, post_process])
end
|
#show_me_decoration ⇒ Object
124
125
126
127
128
129
130
|
# File 'lib/kiba/extend/jobs/runner.rb', line 124
def show_me_decoration
return unless Kiba::Extend.job_show_me
extend ShowMeJob
decorate
end
|
#sources ⇒ Object
132
133
134
135
136
|
# File 'lib/kiba/extend/jobs/runner.rb', line 132
def sources
@files[:source].map { |config| file_config(config) }
.map { |src| "source #{src[:klass]}, **#{src[:args]}" }
.join("\n")
end
|
#tell_me_decoration ⇒ Object
138
139
140
141
142
143
144
|
# File 'lib/kiba/extend/jobs/runner.rb', line 138
def tell_me_decoration
return unless Kiba::Extend.job_tell_me
extend TellMeJob
decorate
end
|
146
147
148
|
# File 'lib/kiba/extend/jobs/runner.rb', line 146
def transform
[initial_transforms, @transformer, final_transforms].flatten
end
|