Module: Kiba::Extend::Job
- Defined in:
- lib/kiba/extend/job.rb
Overview
Convenience methods callable on a given job
Class Method Summary collapse
-
.output?(jobkey) ⇒ true, false
-
.output_fields(jobkey) ⇒ nil, Array<Symbol>
Headers/fields for given job output.
Class Method Details
.output?(jobkey) ⇒ true, false
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/kiba/extend/job.rb', line 34 def output?(jobkey) begin reg = Kiba::Extend.registry.resolve(jobkey) rescue Dry::Container::KeyError return false end return true if File.exist?(reg.path) res = Kiba::Extend::Command::Run.job(jobkey) return false unless res !(res.outrows == 0) end |
.output_fields(jobkey) ⇒ nil, Array<Symbol>
Note:
Only works for CSV and JsonArray destinations. For JsonArray, only returns the top-level fields of the objects/rows in the output.
Returns headers/fields for given job output.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/kiba/extend/job.rb', line 13 def output_fields(jobkey) return unless output?(jobkey) entry = Kiba::Extend.registry.resolve(jobkey) path = Pathname.new(entry.path) dest = entry.dest_class.new(filename: path) unless dest.respond_to?(:fields) raise "No output field extraction logic exists for "\ "#{entry.dest_class}" end dest.fields end |