MS remove custom resque job logging as it is making heroku very sad
This commit is contained in:
parent
467f3b0bda
commit
6e02f61395
3 changed files with 0 additions and 83 deletions
|
|
@ -5,6 +5,5 @@
|
|||
module Jobs
|
||||
class Base
|
||||
Dir["#{Rails.root}/app/models/jobs/mail/*.rb"].each {|file| require file }
|
||||
extend ResqueJobLogging
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
module ResqueJobLogging
|
||||
def around_perform_log_job(*args)
|
||||
Rails.logger.auto_flushing=1
|
||||
log_string = "event=resque_job job=#{self} "
|
||||
error = nil
|
||||
time = Benchmark.realtime{
|
||||
begin
|
||||
yield
|
||||
rescue Exception => e
|
||||
error = e
|
||||
end
|
||||
}*1000
|
||||
|
||||
log_string += "ms=#{time} "
|
||||
args.each_with_index{|arg,idx| log_string += "arg#{idx.succ}=\"#{arg.to_s[0..30]}\" "}
|
||||
|
||||
if error
|
||||
log_string += "status=error "
|
||||
log_string << "error_class=#{error.class} error_message='#{error.message}' "
|
||||
log_string << "orig_error_message='#{error.original_error.message}'" if error.respond_to?(:original_error)
|
||||
log_string << "annotated_source='#{error.annoted_source_code.to_s}' " if error.respond_to?(:annoted_source_code)
|
||||
backtrace = application_trace(error)
|
||||
log_string << "app_backtrace='#{backtrace.join(";")}' "
|
||||
notify_hoptoad(error, args) if AppConfig[:hoptoad_api_key].present?
|
||||
else
|
||||
log_string += "status=complete "
|
||||
end
|
||||
|
||||
Rails.logger.info(log_string)
|
||||
raise error if error
|
||||
end
|
||||
|
||||
def notify_hoptoad(error, job_arguments)
|
||||
HoptoadNotifier.notify(
|
||||
:error_class => error.class,
|
||||
:error_message => error.message,
|
||||
:backtrace => error.backtrace,
|
||||
:parameters => {
|
||||
:job_class => self.name,
|
||||
:arguments => job_arguments.map!{|a| a.to_s[0..30]}.join(', '),
|
||||
:controller => "Resque",
|
||||
:action => self.name
|
||||
}
|
||||
) if Rails.env.production? && AppConfig[:hoptoad_api_key].present?
|
||||
end
|
||||
|
||||
def application_trace(error) #copied from ActionDispatch::ShowExceptions
|
||||
defined?(Rails) && Rails.respond_to?(:backtrace_cleaner) ?
|
||||
Rails.backtrace_cleaner.clean(error.backtrace, :silent) :
|
||||
error.backtrace
|
||||
end
|
||||
end
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe ResqueJobLogging do
|
||||
before do
|
||||
Rails.stub!(:logger).and_return(mock())
|
||||
Rails.logger.should_receive(:auto_flushing=).with(1)
|
||||
|
||||
silence_warnings { Object.const_set("ResqueJobLoggingDummy", Class.new(Object)) }
|
||||
ResqueJobLoggingDummy.extend(ResqueJobLogging)
|
||||
end
|
||||
|
||||
after do
|
||||
Rails.unstub!(:logger)
|
||||
end
|
||||
|
||||
|
||||
it 'notifies hoptoad if the hoptoad api key is set' do
|
||||
Rails.logger.should_receive(:info)
|
||||
AppConfig.should_receive(:[]).with(:hoptoad_api_key).and_return("what")
|
||||
error = RuntimeError.new("GRAAAAAAAAAGH")
|
||||
ResqueJobLoggingDummy.should_receive(:notify_hoptoad).with(error, ["stuff"])
|
||||
proc {
|
||||
ResqueJobLoggingDummy.around_perform_log_job("stuff"){raise error }
|
||||
}.should raise_error(Regexp.new(error.message))
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue