File tree 4 files changed +34
-4
lines changed
4 files changed +34
-4
lines changed Original file line number Diff line number Diff line change 126
126
rails (>= 3.1.0 )
127
127
redcarpet (>= 2.0.0 )
128
128
metaclass (0.0.1 )
129
- minitest (2.12.1 )
130
- mocha (0.11.4 )
131
129
mime-types (1.19 )
132
130
minitest (2.12.1 )
131
+ mocha (0.11.4 )
133
132
multi_json (1.3.6 )
134
133
multi_xml (0.2.2 )
135
134
multipart-post (1.1.5 )
Original file line number Diff line number Diff line change 3
3
4
4
require File . expand_path ( '../config/application' , __FILE__ )
5
5
require 'rake'
6
+ require File . expand_path ( '../lib/rake_exception_notification' , __FILE__ )
6
7
7
8
PracticingRubyWeb ::Application . load_tasks
Original file line number Diff line number Diff line change
1
+ module RakeExceptionNotification
2
+ # Exception notification (rails3) only works as a rack middleware,
3
+ # but what if you need notifications inside a rake task or a script?
4
+ # This is a quick hack around that.
5
+ #
6
+ # Source: https://gist.github.com/551136
7
+ #
8
+ # Wrap your code inside an exception_notify block and you will be notified of exceptions
9
+ #
10
+ # exception_notify { # Dangerous Code Here }
11
+ def exception_notify
12
+ yield
13
+ rescue Exception => exception
14
+ if Rails . env . production?
15
+ env = { }
16
+ env [ 'exception_notifier.options' ] = {
17
+ # TODO: DRY this configuration up
18
+ :email_prefix => '[Practicing Ruby Rake] ' ,
19
+
20
+ :sections => [ 'backtrace' ]
21
+ }
22
+ ExceptionNotifier ::Notifier . exception_notification ( env , exception ) . deliver
23
+ end
24
+ raise exception
25
+ end
26
+ end
Original file line number Diff line number Diff line change 1
1
include ActionView ::Helpers ::TextHelper
2
+ include RakeExceptionNotification
2
3
3
4
namespace :mailchimp do
4
5
desc 'Disable accounts which have been unsubscribed in mailchimp'
5
6
task :disable_unsubscribed => :environment do
6
7
7
8
puts "== Running mailchip:update_subscribers at #{ Time . now } =="
8
9
9
- user_manager = UserManager . new
10
+ exception_notify do
11
+ user_manager = UserManager . new
12
+ user_manager . disable_unsubscribed_users
10
13
11
- user_manager . disable_unsubscribed_users
14
+ raise "Wow"
15
+ end
12
16
end
13
17
end
You can’t perform that action at this time.
0 commit comments