2

Iam running kiba job from rails service that is called inside controller. Here is current code.

class KibaRunner
  attr_reader :job,:logger
  def initialize(job)
    @job = job
    @logger = Rails.logger
  end
  def run
    logger.info "Running job"
    Kiba.run(kiba_job)
    true
  rescue => ex
    logger.warn ex
    false
  end

  def kiba_job
    Kiba.parse do
      source job.source.class_name, job.source.config
      destination  job.destination.class_name, job.destination.config
    end
  end
end

Here's what Iam getting

NoMethodError: undefined method `job' for #<Kiba::Context:0x00555bcd400e38>
Jurot King
  • 79
  • 7
  • In which line do you get the error? – Subash Jan 25 '18 at 05:45
  • inside here Kiba.parse do source job.source.class_name, job.source.config destination job.destination.class_name, job.destination.config end – Jurot King Jan 25 '18 at 06:13
  • you need to use `@` notation to refer to the instance variable so in your case it should be `source @job.source.class_name, @job.source.config destination @job.destination.class_name, @job.destination.config` – Subash Jan 25 '18 at 06:16
  • I have attr_reader which means job method is defined and returns @job – Jurot King Jan 25 '18 at 06:20
  • oh yes, missed that, what does `Kiba.parse` do or return? – Subash Jan 25 '18 at 06:29
  • `Kiba.parse` (defined [here](https://github.com/thbar/kiba/blob/master/lib/kiba/parser.rb)) evaluates the job and returns an internal `Kiba::Control` structure that you must pass to `Kiba.run`. Will reply below. – Thibaut Barrère Jan 25 '18 at 06:45

1 Answers1

1

Kiba author here! Quick answer - a slightly longer stack trace with more lines & error numbers would help, but I suspect this is because the Kiba.parse evaluation system does not have access to the top class methods.

I suggest you pass the job as a method parameter, in order to make sure it is seen inside the parse call:

def kiba_job(job)
  Kiba.parse do
    source job.source.class_name, job.source.config
    destination  job.destination.class_name, job.destination.config
  end
end

Then update your service call to use this:

kiba_job(job)

For clarity, I'd also suggest you could rename your job to job_config.

Note that if your job takes some time, it's a good idea to run it from a background job service instead of running directly in the controller call. You can check out this page for a few recommendations on how to deal with this.

Hope this helps, let me know if this fixes it!

Thibaut Barrère
  • 8,845
  • 2
  • 22
  • 27