Skip to content

Instantly share code, notes, and snippets.

@timdiggins
Created December 18, 2014 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timdiggins/294f0a37312fcbeaac70 to your computer and use it in GitHub Desktop.
Save timdiggins/294f0a37312fcbeaac70 to your computer and use it in GitHub Desktop.
delayedjob plugin to log backtraces
module Delayed
module Plugins
class LogErrors < Plugin
callbacks do |lifecycle|
lifecycle.around(:invoke_job) do |job, &block|
begin
block.call(job)
rescue Exception => error
Delayed::Worker.logger.error(error.message)
Delayed::Worker.logger.error(error.backtrace.join("\n"))
raise
end
end
end
end
end
end
if Rails.env.development?
Delayed::Worker.plugins << Delayed::Plugins::LogErrors
Delayed::Worker.logger = Logger.new(File.join(Rails.root, 'log', 'delayed_job.log'))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment