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.

4

1 に答える 1

1

Rails ロガーを使用するように Resque ロガーを設定できます。完全なスタック トレースの場合はDEBUG、多くの情報を出力する level に設定することをお勧めします。あなたはそれを入れますinitializers/resque.rb

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

resque-backtrace gemもありますが、Resque のバックエンドを上書きするという欠点があるため、ジョブがエラー キューに移動することはありません。

于 2014-09-19T10:08:24.413 に答える