exception_notification-rake 0.2.0.rc1 → 0.2.1.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +68 -64
- data/lib/exception_notification/rake.rb +1 -0
- data/lib/exception_notifier/rake/rake.rb +8 -19
- data/lib/exception_notifier/rake/version.rb +1 -1
- data/test/rake_test.rb +2 -4
- metadata +2 -4
- data/lib/exception_notifier/rake/views/exception_notifier/_rake.html.erb +0 -1
- data/lib/exception_notifier/rake/views/exception_notifier/_rake.text.erb +0 -1
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
exception_notification-rake - ExceptionNotifier for Rake tasks
|
2
2
|
==============================================================
|
3
3
|
|
4
|
-
This Ruby gem is an extension of the [exception_notification gem](http://rubygems.org/gems/exception_notification) to support sending mail upon failures in Rake tasks. This is useful if you run Rake tasks as batch jobs on a schedule, particularly if you're using the [Heroku Scheduler add-on](http://addons.heroku.com/scheduler).
|
4
|
+
This Ruby gem is an extension of the [exception_notification gem](http://rubygems.org/gems/exception_notification) to support sending mail (or other sorts of notifications) upon failures in Rake tasks. This is useful if you run Rake tasks as batch jobs on a schedule, particularly if you're using the [Heroku Scheduler add-on](http://addons.heroku.com/scheduler).
|
5
5
|
|
6
6
|
[](https://travis-ci.org/nikhaldi/exception_notification-rake)
|
7
7
|
|
@@ -9,7 +9,7 @@ This Ruby gem is an extension of the [exception_notification gem](http://rubygem
|
|
9
9
|
|
10
10
|
If you're using Rails 4.1.x (or you're not using Rails at all), use the latest version of the gem:
|
11
11
|
|
12
|
-
gem 'exception_notification-rake', '~> 0.2.
|
12
|
+
gem 'exception_notification-rake', '~> 0.2.1'
|
13
13
|
|
14
14
|
If you're using Rails 4.0.x, use the 0.1.x line of versions:
|
15
15
|
|
@@ -22,9 +22,9 @@ If you're using Rails 3, use the 0.0.x line of versions:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
###
|
25
|
+
### Configuration for Email Notifications
|
26
26
|
|
27
|
-
**Note:** These examples are for the latest version of the gem (using exception_notification 4 and Rails 4). For a Rails 3.2 example [see below](#rails-32-configuration-example).
|
27
|
+
**Note:** These examples are for the latest version of the gem (using exception_notification 4.1 and Rails 4.1). For a Rails 3.2 example [see below](#rails-32-configuration-example).
|
28
28
|
|
29
29
|
Exception notification must be set up in your Rails config files. In general, you'll want to do this in environment-specific config files, such as `config/environments/production.rb`. Minimal configuration:
|
30
30
|
|
@@ -34,7 +34,7 @@ Exception notification must be set up in your Rails config files. In general, yo
|
|
34
34
|
# Other configuration here, including ActionMailer config ...
|
35
35
|
|
36
36
|
config.middleware.use ExceptionNotification::Rack,
|
37
|
-
|
37
|
+
:ignore_if => lambda { |env, exception| !env.nil? },
|
38
38
|
:email => {
|
39
39
|
:sender_address => %{"notifier" <sender.address@example.com>},
|
40
40
|
:exception_recipients => %w{your.email@example.com}
|
@@ -43,85 +43,90 @@ Exception notification must be set up in your Rails config files. In general, yo
|
|
43
43
|
ExceptionNotifier::Rake.configure
|
44
44
|
end
|
45
45
|
|
46
|
-
**Note:** This uses `:ignore_if` to suppress all exception notifications not triggered by
|
46
|
+
**Note:** This uses `:ignore_if` to suppress all exception notifications not triggered by a background exception (identified by a `nil` environment). If you want to see all notifications (i.e., also those triggered by requests to the Rails server), omit the `:ignore_if` option.
|
47
47
|
|
48
48
|
If you are already using `ExceptionNotifier` anyway, you don't need to configure it again and all you need is:
|
49
49
|
|
50
|
-
|
50
|
+
# config/environments/production.rb
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
YourApp::Application.configure do
|
53
|
+
# Other configuration here, including ExceptionNotifer and ActionMailer config ...
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
ExceptionNotifier::Rake.configure
|
56
|
+
end
|
57
57
|
|
58
58
|
**Note:** As a prerequisite for sending mail your Rails Action Mailer needs to be configured in the environment where you're using exception notification. See the [Rails guide on Action Mailer](http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration).
|
59
59
|
|
60
60
|
|
61
|
-
|
61
|
+
### Other Notifiers
|
62
62
|
|
63
|
-
|
63
|
+
exception_notificatons supports a bunch of notifiers other than email. See [its documentation](http://smartinez87.github.io/exception_notification/#notifiers) for details. This gem should generally work out of the box with all notifiers. The Rake command line that led to the failure is available at the `:rake_command_line` key in the `data` dictionary.
|
64
64
|
|
65
|
-
YourApp::Application.configure do
|
66
|
-
# Other configuration here, including ActionMailer config ...
|
67
65
|
|
68
|
-
|
69
|
-
:sender_address => %{"notifier" <sender.address@example.com>},
|
70
|
-
:exception_recipients => %w{your.email@example.com},
|
71
|
-
:ignore_if => lambda { true }
|
66
|
+
### Rails 3.2 Configuration Example
|
72
67
|
|
73
|
-
|
74
|
-
end
|
68
|
+
# config/environments/production.rb
|
75
69
|
|
76
|
-
|
70
|
+
YourApp::Application.configure do
|
71
|
+
# Other configuration here, including ActionMailer config ...
|
77
72
|
|
73
|
+
config.middleware.use ExceptionNotifier,
|
74
|
+
:sender_address => %{"notifier" <sender.address@example.com>},
|
75
|
+
:exception_recipients => %w{your.email@example.com},
|
76
|
+
:ignore_if => lambda { true }
|
78
77
|
|
79
|
-
|
78
|
+
ExceptionNotifier::Rake.configure
|
79
|
+
end
|
80
80
|
|
81
|
-
|
81
|
+
For complete documentation on the Rails 3.2 version see the [corresponding branch on GitHub](https://github.com/nikhaldi/exception_notification-rake/tree/rails3.2).
|
82
82
|
|
83
|
-
Subject: [ERROR] (NoMethodError) "undefined method `khaaaaan!' for main:Object"
|
84
|
-
From: "notifier" <sender.address@example.com>
|
85
|
-
To: <your.email@example.com>
|
86
83
|
|
87
|
-
|
84
|
+
### Email Notification Example
|
88
85
|
|
89
|
-
|
90
|
-
lib/tasks/scheduler.rake:33:in `block in <top (required)>'
|
86
|
+
Email sent upon a failure will include the Rake tasks executed and a stacktrace. This is the result from calling an undefined method `khaaaaan!` in a task called `failing_task` (the data section contains the executed Rake command line in the `:rake_command_line` key):
|
91
87
|
|
92
|
-
|
93
|
-
|
94
|
-
|
88
|
+
Subject: [ERROR] (NoMethodError) "undefined method `khaaaaan!' for main:Object"
|
89
|
+
From: "notifier" <sender.address@example.com>
|
90
|
+
To: <your.email@example.com>
|
95
91
|
|
96
|
-
|
92
|
+
A NoMethodError occurred in background at 2014-07-20 21:25:00 UTC :
|
97
93
|
|
98
|
-
|
99
|
-
|
100
|
-
-------------------------------
|
94
|
+
undefined method `khaaaaan!' for main:Object
|
95
|
+
/Users/haldimann/Projects/nikhaldimann.com/lib/tasks/scheduler.rake:33:in `block in <top (required)>'
|
101
96
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
|
106
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
|
107
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
|
108
|
-
.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
|
109
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
|
110
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
|
111
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
|
112
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
|
113
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
|
114
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
|
115
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
|
116
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
|
117
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
|
118
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
|
119
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
|
120
|
-
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
|
121
|
-
.rvm/gems/ruby-1.9.3-p327/bin/rake:23:in `load'
|
122
|
-
.rvm/gems/ruby-1.9.3-p327/bin/rake:23:in `<main>'
|
97
|
+
-------------------------------
|
98
|
+
Backtrace:
|
99
|
+
-------------------------------
|
123
100
|
|
124
|
-
|
101
|
+
lib/tasks/scheduler.rake:33:in `block in <top (required)>'
|
102
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
|
103
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
|
104
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
|
105
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
|
106
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
|
107
|
+
.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
|
108
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
|
109
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
|
110
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/application.rb:150:in `invoke_task'
|
111
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
|
112
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
|
113
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
|
114
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
|
115
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
|
116
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
|
117
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
|
118
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
|
119
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
|
120
|
+
.rvm/gems/ruby-1.9.3-p327/bin/rake:19:in `load'
|
121
|
+
.rvm/gems/ruby-1.9.3-p327/bin/rake:19:in `<main>'
|
122
|
+
.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval'
|
123
|
+
.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `<main>'
|
124
|
+
|
125
|
+
-------------------------------
|
126
|
+
Data:
|
127
|
+
-------------------------------
|
128
|
+
|
129
|
+
* data: {:rake_command_line=>"rake failing_task"}
|
125
130
|
|
126
131
|
|
127
132
|
### Usage with Heroku Scheduler
|
@@ -139,14 +144,13 @@ passed through to each notifier you configured with `ExceptionNotifier` (see [it
|
|
139
144
|
The most likely options you'll want to use are `:email_prefix` and `:exception_recpients`. Example:
|
140
145
|
|
141
146
|
ExceptionNotifier::Rake.configure(
|
142
|
-
|
143
|
-
|
147
|
+
:email => {
|
148
|
+
:email_prefix => "[Rake Failure] ",
|
149
|
+
:exception_recipients => %w{user1@example.com user2@example.com}})
|
144
150
|
|
145
151
|
This will prefix the email subjects of Rake failure notifications with `[Rake Failure]` and will send them to the two given email addresses. Note that if you set the same options when you configure `ExceptionNotifier` mail notifier itself, they will be overridden but for Rake failures only.
|
146
152
|
|
147
|
-
`:ignore_if` and `:ignore_exceptions` are also supported. But note that the `:ignore_if` block will be evaluated for all exceptions, not just the ones triggered by Rake (this is unavoidable because of the design of exception_notification). The first argument to the block passed to `:ignore_if` is the environment - for all Rake failures
|
148
|
-
|
149
|
-
If you want to configure sections, which is unlikely, note that by default the sections `['rake', 'backtrace']` are used (where `rake` is a custom section introduced by this gem).
|
153
|
+
`:ignore_if` and `:ignore_exceptions` are also supported. But note that the `:ignore_if` block will be evaluated for all exceptions, not just the ones triggered by Rake (this is unavoidable because of the design of exception_notification). The first argument to the block passed to `:ignore_if` is the environment - for all Rake failures and other background exceptions this will be `nil`, giving you some way to distinguish them.
|
150
154
|
|
151
155
|
|
152
156
|
## License
|
@@ -5,10 +5,11 @@ module ExceptionNotifier
|
|
5
5
|
class Rake
|
6
6
|
|
7
7
|
@notifier_options = {}
|
8
|
+
@configured = false
|
8
9
|
|
9
10
|
# Whether Rake exception notifications have been configured.
|
10
11
|
def self.configured?
|
11
|
-
|
12
|
+
@configured
|
12
13
|
end
|
13
14
|
|
14
15
|
# Configure Rake exception notifications. Should be called in a config file,
|
@@ -16,31 +17,18 @@ module ExceptionNotifier
|
|
16
17
|
# An optional hash of options can be given, which will be passed through
|
17
18
|
# unchanged to the underlying notifiers.
|
18
19
|
def self.configure(options = {})
|
19
|
-
@
|
20
|
+
@configured = true
|
20
21
|
@notifier_options.merge!(options)
|
21
22
|
|
22
23
|
# There is only a single static list registered ignore_ifs. We make
|
23
|
-
# ignore_ifs passed to just this configuration only effective for
|
24
|
-
#
|
25
|
-
#
|
24
|
+
# ignore_ifs passed to just this configuration only effective for
|
25
|
+
# background exceptions (the enviornment will be nil). That's the
|
26
|
+
# best we can do, there isn't really a way to identify just our exceptions.
|
26
27
|
if options[:ignore_if]
|
27
28
|
ExceptionNotifier.ignore_if do |exception, passed_options|
|
28
|
-
passed_options[:env]
|
29
|
+
passed_options[:env].nil? && options[:ignore_if].call({}, exception)
|
29
30
|
end
|
30
31
|
end
|
31
|
-
|
32
|
-
# Append view path for this gem, assuming that the client is using
|
33
|
-
# ActionMailer::Base. This isn't ideal but there doesn't seem to be
|
34
|
-
# a different way to extend the path.
|
35
|
-
require 'action_mailer'
|
36
|
-
ActionMailer::Base.append_view_path "#{File.dirname(__FILE__)}/views"
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.default_notifier_options
|
40
|
-
{
|
41
|
-
:background_sections => %w(rake backtrace),
|
42
|
-
:env => {:rake? => true},
|
43
|
-
}
|
44
32
|
end
|
45
33
|
|
46
34
|
def self.notifier_options
|
@@ -64,6 +52,7 @@ module ExceptionNotifier
|
|
64
52
|
|
65
53
|
def self.reset_for_test
|
66
54
|
@notifier_options = {}
|
55
|
+
@configured = false
|
67
56
|
ExceptionNotifier.clear_ignore_conditions!
|
68
57
|
end
|
69
58
|
end
|
data/test/rake_test.rb
CHANGED
@@ -35,8 +35,7 @@ class RakeTest < Minitest::Test
|
|
35
35
|
def test_configure_only_default_options
|
36
36
|
ExceptionNotifier::Rake.configure
|
37
37
|
assert ExceptionNotifier::Rake.configured?
|
38
|
-
assert_equal ExceptionNotifier::Rake.
|
39
|
-
ExceptionNotifier::Rake.notifier_options
|
38
|
+
assert_equal({}, ExceptionNotifier::Rake.notifier_options)
|
40
39
|
end
|
41
40
|
|
42
41
|
def test_configure_custom_options
|
@@ -46,8 +45,7 @@ class RakeTest < Minitest::Test
|
|
46
45
|
}
|
47
46
|
ExceptionNotifier::Rake.configure some_options
|
48
47
|
assert ExceptionNotifier::Rake.configured?
|
49
|
-
assert_equal some_options
|
50
|
-
ExceptionNotifier::Rake.notifier_options
|
48
|
+
assert_equal some_options, ExceptionNotifier::Rake.notifier_options
|
51
49
|
end
|
52
50
|
|
53
51
|
def test_maybe_deliver_notifications_without_configuration
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exception_notification-rake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1.rc1
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-07-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: exception_notification
|
@@ -73,8 +73,6 @@ files:
|
|
73
73
|
- lib/exception_notifier/rake/rake.rb
|
74
74
|
- lib/exception_notifier/rake/rake_patch.rb
|
75
75
|
- lib/exception_notifier/rake/version.rb
|
76
|
-
- lib/exception_notifier/rake/views/exception_notifier/_rake.html.erb
|
77
|
-
- lib/exception_notifier/rake/views/exception_notifier/_rake.text.erb
|
78
76
|
- lib/exception_notifier/rake.rb
|
79
77
|
- test/rake_test.rb
|
80
78
|
homepage: https://github.com/nikhaldi/exception_notification-rake
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= raw @data[:rake_command_line] %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= raw @data[:rake_command_line] %>
|