How can I run an ActiveJob in Rails console for debugging?

daveomcd picture daveomcd · Dec 29, 2015 · Viewed 14.9k times · Source

I currently have an ActiveJob that I've created and use Sidekiq to queue it. I'm wanting to debug the job, but for me to see any messages I program into it I have to check my log files. I feel like it would be more convenient to be able to see my puts messages in my job in the Rails Console. When I run the perform_later method though in rails console it just queues the job up and I never see the messages in console. Is there a way to make it where I will see them in the console?

Answer

Rob Di Marco picture Rob Di Marco · Dec 29, 2015

You can run a job with perform_now.

For example...

class Foo < ActiveJob::Base
  def perform(arg1)
    puts "Hello #{arg1}"
  end
end

Foo.perform_now('world')