Debugging delayed_job jobs from within the console

11 Jul 2013 . Programming . Comments #rails #ruby #debugger #delayed_job

Did you ever want to step in with the Ruby debugger to fix or inspect a background job? Here’s how:

DISCLAIMER: Tested with delayed_job 2.14. Should work with recent versions, too.

Open a rails console within your project

$ rails c
Loading development environment (Rails 3.2.13)

Initialise a delayed_job worker, and make it output to console by passing {quiet: false} to its initialiser.

1.9.2p325 :001 > worker = Delayed::Worker.new({quiet: false})
 => #<Delayed::Worker:0x007fa295ecef48 @quiet=false>

Start the worker

1.9.2p325 :002 > worker.start

Now you can put a debugger statement into your jobs and debug nicely without using loggers.