3

I have a JRuby/Rails application comprising a web server to process HTTP requests, a MySQL database, and a Resque worker to process enqueued jobs. When I'm in development mode and something in the web application throws an exception, I get a nice trace in the browser, showing the exception thrown, the line at which it was thrown, relevant data, and a stack traceback.

However, when exception-throwing code executes in a Resque worker, I get nothing, even if I know that the code has thrown an exception. The only way that I can debug is to throw in print statements and figure out where the last print statement was called before the Resque worker threw the exception and crashed.

Is there a way to get the Resque worker to spit out an exception log and stack traceback into the log file (before it crashes), so that I can see what happened?

EDIT - (Thanks for the idea @Viren) - And I don't want to litter my application code with begin/rescue blocks. I'll put the begin/rescue code in once somewhere to make sure that the exception traceback gets logged, but I don't know where to put it.

Jay Godse
  • 15,163
  • 16
  • 84
  • 131
  • Why not add a Separate Logger for Resque and Catch the error using `begin rescue` block Hope that help – Viren Aug 30 '12 at 16:13
  • I don't want to litter my code with begin/rescue blocks looking for the exception. Is there a central place where I can put it in once and get coverage for the entire? – Jay Godse Aug 30 '12 at 17:36
  • as far as i know, you should have a failed job that should also have a valid stack-trace. are you sure this has nothing to do with jruby? – phoet Aug 30 '12 at 18:58

1 Answers1

1

You can set your Resque logger to use the Rails logger. For full stack trace you might want to set it to DEBUG level, which prints out lots of information. You put it in initializers/resque.rb:

Resque.logger = Rails.logger
Resque.logger.level = Logger::DEBUG

There also resque-backtrace gem, although it has this drawback that it overwrites the backend in Resque so now no jobs will ever make it to the error queue.

Paweł Gościcki
  • 9,066
  • 5
  • 70
  • 81