Skip to content

Commit 7626e99

Browse files
committed
Background Notifications. Thanks @sunkencity!
2 parents bd924ab + b54ba10 commit 7626e99

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/exception_notifier/notifier.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ def exception_notification(env, exception)
6666
end
6767
end
6868

69+
def background_exception_notification(exception)
70+
71+
if @notifier = Rails.application.config.middleware.detect { |x| x.klass == ExceptionNotifier }
72+
@options = (@notifier.args.first || {}).reverse_merge(self.class.default_options)
73+
subject = "#{@options[:email_prefix]} (#{exception.class}) #{exception.message.inspect}"
74+
75+
@exception = exception
76+
@backtrace = exception.backtrace || []
77+
@sections = %w{backtrace}
78+
79+
mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format|
80+
format.text { render "#{mailer_name}/background_exception_notification" }
81+
end.deliver
82+
end
83+
end
84+
85+
6986
private
7087

7188
def clean_backtrace(exception)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
A <%= @exception.class %> occurred in background:
2+
3+
<%= @exception.message %>
4+
<%= @backtrace.first %>
5+
6+
<% sections = @sections.map do |section|
7+
summary = render(section).strip
8+
unless summary.blank?
9+
title = render("title", :title => section).strip
10+
"#{title}\n\n#{summary.gsub(/^/, " ")}\n\n"
11+
end
12+
end %>
13+
<%= raw sections.join %>

0 commit comments

Comments
 (0)