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
53
54
55
56
57
|
# File 'lib/kiba/extend/jobs/runner.rb', line 53
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
59
60
61
|
# File 'lib/kiba/extend/jobs/runner.rb', line 59
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
45
46
47
48
49
50
|
# File 'lib/kiba/extend/jobs/runner.rb', line 31
def add_lookup(config)
cust = :@instance_variable_name
name = if config.instance_variable_defined?(cust)
config.instance_variable_get(cust)
else
config.key
end
ivname = :"@#{name}"
context.define_singleton_method(name.to_sym) do
if instance_variable_defined?(ivname)
instance_variable_get(ivname)
else
instance_variable_set(
ivname,
Lookup.csv_to_hash(**config.args.compact)
)
end
end
end
|
#add_sources ⇒ Object
63
64
65
|
# File 'lib/kiba/extend/jobs/runner.rb', line 63
def add_sources
context.instance_eval(sources)
end
|
#assemble_control ⇒ Object
67
68
69
70
71
72
73
74
75
|
# File 'lib/kiba/extend/jobs/runner.rb', line 67
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
78
79
80
81
82
83
84
85
|
# File 'lib/kiba/extend/jobs/runner.rb', line 78
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
87
88
89
90
91
|
# File 'lib/kiba/extend/jobs/runner.rb', line 87
def destinations
@files[:destination].map { |config| file_config(config) }
.map { |src| "destination #{src[:klass]}, **#{src[:args]}" }
.join("\n")
end
|
#file_config(config) ⇒ Object
93
94
95
|
# File 'lib/kiba/extend/jobs/runner.rb', line 93
def file_config(config)
{klass: config.klass, args: config.args}
end
|
#handle_requirements(type) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/kiba/extend/jobs/runner.rb', line 98
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
119
120
121
122
123
|
# File 'lib/kiba/extend/jobs/runner.rb', line 119
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
126
127
128
|
# File 'lib/kiba/extend/jobs/runner.rb', line 126
def parse_job_segments
parse_job(control, context, [pre_process, transform, post_process])
end
|
#show_me_decoration ⇒ Object
130
131
132
133
134
135
136
|
# File 'lib/kiba/extend/jobs/runner.rb', line 130
def show_me_decoration
return unless Kiba::Extend.job_show_me
extend ShowMeJob
decorate
end
|
#sources ⇒ Object
138
139
140
141
142
|
# File 'lib/kiba/extend/jobs/runner.rb', line 138
def sources
@files[:source].map { |config| file_config(config) }
.map { |src| "source #{src[:klass]}, **#{src[:args]}" }
.join("\n")
end
|
#tell_me_decoration ⇒ Object
144
145
146
147
148
149
150
|
# File 'lib/kiba/extend/jobs/runner.rb', line 144
def tell_me_decoration
return unless Kiba::Extend.job_tell_me
extend TellMeJob
decorate
end
|
152
153
154
|
# File 'lib/kiba/extend/jobs/runner.rb', line 152
def transform
[initial_transforms, @transformer, final_transforms].flatten
end
|