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, mode: :warn_if_unregistered) ⇒ true, false
-
.output_fields(jobkey, suppress_warnings: false) ⇒ Array<Symbol>
Headers/fields for given job output.
-
.registered?(jobkey) ⇒ Boolean
Without drama about registry errors.
Class Method Details
.output?(jobkey, mode: :warn_if_unregistered) ⇒ true, false
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/kiba/extend/job.rb', line 43 def output?(jobkey, mode: :warn_if_unregistered) return false if Kiba::Extend::ProjectConfig.blank_jobs.include?(jobkey) begin reg = Kiba::Extend::Registry.entry_for(jobkey) rescue Kiba::Extend::JobNotRegisteredError => err if mode == :warn_if_unregistered puts Kiba::Extend.warn(err.) end return false end return true if File.exist?(reg.path) res = Kiba::Extend::Command::Run.job(jobkey) unless res Kiba::Extend::ProjectConfig.blank_jobs << jobkey return false end return true if res.outrows > 0 Kiba::Extend::ProjectConfig.blank_jobs << jobkey false end |
.output_fields(jobkey, suppress_warnings: false) ⇒ 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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kiba/extend/job.rb', line 14 def output_fields(jobkey, suppress_warnings: false) unless output?(jobkey) msg = "Kiba::Extend::Job.output_fields(#{jobkey}) is returning an "\ "empty Array instead of nil because #{jobkey} has no output. "\ "This is a recent change in this method's behavior, so make "\ "sure your code is still behaving as expected" warn(Kiba::Extend.warn(msg)) unless suppress_warnings return [] end entry = Kiba::Extend::Registry.entry_for(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 |
.registered?(jobkey) ⇒ Boolean
Note:
Use this if you only care about whether a job has been registered, not whether it has output
Returns without drama about registry errors.
73 74 75 |
# File 'lib/kiba/extend/job.rb', line 73 def registered?(jobkey) = Kiba::Extend.registry.entry_objs .map { |eo| eo.key.to_sym } .include?(jobkey) |