Skip to content

Commit

Permalink
Background Notifications. Thanks @sunkencity!
Browse files Browse the repository at this point in the history
  • Loading branch information
smartinez87 committed Aug 7, 2011
2 parents bd924ab + b54ba10 commit 7626e99
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/exception_notifier/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ def exception_notification(env, exception)
end
end

def background_exception_notification(exception)

if @notifier = Rails.application.config.middleware.detect { |x| x.klass == ExceptionNotifier }
@options = (@notifier.args.first || {}).reverse_merge(self.class.default_options)
subject = "#{@options[:email_prefix]} (#{exception.class}) #{exception.message.inspect}"

@exception = exception
@backtrace = exception.backtrace || []
@sections = %w{backtrace}

mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format|
format.text { render "#{mailer_name}/background_exception_notification" }
end.deliver
end
end


private

def clean_backtrace(exception)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
A <%= @exception.class %> occurred in background:

<%= @exception.message %>
<%= @backtrace.first %>

<% sections = @sections.map do |section|
summary = render(section).strip
unless summary.blank?
title = render("title", :title => section).strip
"#{title}\n\n#{summary.gsub(/^/, " ")}\n\n"
end
end %>
<%= raw sections.join %>

0 comments on commit 7626e99

Please sign in to comment.