Module: Kiba::Extend::Job

Defined in:
lib/kiba/extend/job.rb

Overview

Convenience methods callable on a given job

Class Method Summary collapse

Class Method Details

.output?(jobkey) ⇒ true, false

Parameters:

  • jobkey (Symbol)

    registry entry for job with namespace

Returns:

  • (true)

    if output file already exists when run, or when running job results in 1 or more rows being written

  • (false)

    if jobkey is not defined, or if job results in 0 rows when run

Since:

  • 4.0.0



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.

Parameters:

  • jobkey (Symbol)

    registry entry for job with namespace

Returns:

  • (nil, Array<Symbol>)

    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