exception_notification-rake 0.0.7 → 0.1.0.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 +19 -15
- data/lib/exception_notifier/rake/rake.rb +9 -26
- data/lib/exception_notifier/rake/rake_patch.rb +2 -2
- data/lib/exception_notifier/rake/version.rb +2 -2
- data/test/rake_test.rb +2 -22
- metadata +9 -9
data/README.md
CHANGED
@@ -3,10 +3,19 @@ exception_notification-rake - ExceptionNotifier for Rake tasks
|
|
3
3
|
|
4
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).
|
5
5
|
|
6
|
-
This is the branch for the 0.0.x line of versions compatible with **Rails 3.2**.
|
7
|
-
|
8
6
|
[](https://travis-ci.org/nikhaldi/exception_notification-rake)
|
9
7
|
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
If you're using Rails 4 (or you're not using Rails at all), use the latest version of the gem:
|
11
|
+
|
12
|
+
gem 'exception_notification-rake', '~> 0.1.0'
|
13
|
+
|
14
|
+
If you're using Rails 3, use the 0.0.x line of versions:
|
15
|
+
|
16
|
+
gem 'exception_notification-rake', '~> 0.0.5'
|
17
|
+
|
18
|
+
|
10
19
|
## Usage
|
11
20
|
|
12
21
|
### Basic Configuration
|
@@ -19,9 +28,11 @@ Exception notification must be set up in your Rails config files. In general, yo
|
|
19
28
|
# Other configuration here, including ActionMailer config ...
|
20
29
|
|
21
30
|
config.middleware.use ExceptionNotifier,
|
22
|
-
:
|
23
|
-
:
|
24
|
-
|
31
|
+
:ignore_if => lambda { true },
|
32
|
+
:email => {
|
33
|
+
:sender_address => %{"notifier" <sender.address@example.com>},
|
34
|
+
:exception_recipients => %w{your.email@example.com}
|
35
|
+
}
|
25
36
|
|
26
37
|
ExceptionNotifier::Rake.configure
|
27
38
|
end
|
@@ -96,10 +107,10 @@ If you're using Heroku, the [Scheduler add-on](http://addons.heroku.com/schedule
|
|
96
107
|
This gem fixes this issue. [Here is a detailed guide](http://blog.nikhaldimann.com/2013/02/19/failure-notifications-for-rake-tasks-on-the-heroku-scheduler/) about configuring it on Heroku. In summary: If you configure exception notification as described above it should work out of the box with the Heroku Scheduler. (Provided you have email delivery set up in your Heroku app - you could try the [SendGrid add-on](https://addons.heroku.com/sendgrid) which comes in a free version that should be good enough for notifications.)
|
97
108
|
|
98
109
|
|
99
|
-
|
100
110
|
### Customization
|
101
111
|
|
102
|
-
You can pass configuration options to `ExceptionNotifier::Rake.configure`.
|
112
|
+
You can pass configuration options to `ExceptionNotifier::Rake.configure`. These will be
|
113
|
+
passed through to each notifier you configured with `ExceptionNotifier` (see [its documentation](https://github.com/smartinez87/exception_notification) for details on options). The options will be applied only to notifications sent as a result of Rake failures.
|
103
114
|
|
104
115
|
The most likely options you'll want to use are `:email_prefix` and `:exception_recpients`. Example:
|
105
116
|
|
@@ -107,18 +118,11 @@ The most likely options you'll want to use are `:email_prefix` and `:exception_r
|
|
107
118
|
:email_prefix => "[Rake Failure] ",
|
108
119
|
:exception_recipients => %w{user1@example.com user2@example.com})
|
109
120
|
|
110
|
-
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` itself, they will be overridden but for Rake failures only.
|
111
|
-
|
112
|
-
`:ignore_if` and `:ignore_exceptions` are also supported. Note that the first argument to the block expected by `:ignore_if` (the environment) will always be an empty dictionary since there is no meaningful environment for background tasks.
|
121
|
+
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.
|
113
122
|
|
114
123
|
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).
|
115
124
|
|
116
125
|
|
117
|
-
## Installation
|
118
|
-
|
119
|
-
gem install exception_notification-rake
|
120
|
-
|
121
|
-
|
122
126
|
## License
|
123
127
|
|
124
128
|
Distributed under an [MIT license](https://github.com/nikhaldi/exception_notification-rake/blob/master/LICENSE.md).
|
@@ -1,9 +1,6 @@
|
|
1
1
|
require 'exception_notifier'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
# Append application view path to the ExceptionNotifier lookup context.
|
6
|
-
Notifier.append_view_path "#{File.dirname(__FILE__)}/views"
|
3
|
+
module ExceptionNotifier
|
7
4
|
|
8
5
|
class Rake
|
9
6
|
|
@@ -17,10 +14,16 @@ class ExceptionNotifier
|
|
17
14
|
# Configure Rake exception notifications. Should be called in a config file,
|
18
15
|
# usually in config/environments/production.rb for production use.
|
19
16
|
# An optional hash of options can be given, which will be passed through
|
20
|
-
# unchanged to the underlying
|
17
|
+
# unchanged to the underlying notifiers.
|
21
18
|
def self.configure(options = {})
|
22
19
|
@notifier_options.merge!(default_notifier_options)
|
23
20
|
@notifier_options.merge!(options)
|
21
|
+
|
22
|
+
# Append view path for this gem, assuming that the client is using
|
23
|
+
# ActionMailer::Base. This isn't ideal but there doesn't seem to be
|
24
|
+
# a different way to extend the path.
|
25
|
+
require 'action_mailer'
|
26
|
+
ActionMailer::Base.append_view_path "#{File.dirname(__FILE__)}/views"
|
24
27
|
end
|
25
28
|
|
26
29
|
def self.default_notifier_options
|
@@ -40,36 +43,16 @@ class ExceptionNotifier
|
|
40
43
|
def self.maybe_deliver_notification(exception, data={})
|
41
44
|
if configured?
|
42
45
|
options = notifier_options
|
43
|
-
if conditionally_ignored(options[:ignore_if], exception) ||
|
44
|
-
ignored_exception(options[:ignore_exceptions], exception)
|
45
|
-
return
|
46
|
-
end
|
47
|
-
|
48
46
|
if !data.empty?
|
49
47
|
options = options.dup
|
50
48
|
options[:data] = data.merge(options[:data] || {})
|
51
49
|
end
|
52
|
-
ExceptionNotifier
|
53
|
-
exception, options).deliver
|
50
|
+
ExceptionNotifier.notify_exception(exception, options)
|
54
51
|
end
|
55
52
|
end
|
56
53
|
|
57
54
|
def self.reset_for_test
|
58
55
|
@notifier_options = {}
|
59
56
|
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
# Duplicated from exception_notification
|
64
|
-
def self.conditionally_ignored(ignore_proc, exception)
|
65
|
-
ignore_proc.call({}, exception)
|
66
|
-
rescue Exception
|
67
|
-
false
|
68
|
-
end
|
69
|
-
|
70
|
-
# Duplicated from exception_notification
|
71
|
-
def self.ignored_exception(ignore_array, exception)
|
72
|
-
Array.wrap(ignore_array).map(&:to_s).include?(exception.class.name)
|
73
|
-
end
|
74
57
|
end
|
75
58
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Monkey patching patterns lifted from
|
2
2
|
# https://github.com/thoughtbot/airbrake/blob/master/lib/airbrake/rake_handler.rb
|
3
|
-
|
3
|
+
module ExceptionNotifier
|
4
4
|
module RakePatch
|
5
5
|
def self.included(klass)
|
6
6
|
klass.class_eval do
|
@@ -23,7 +23,7 @@ end
|
|
23
23
|
|
24
24
|
# Only do this if we're actually in a Rake context. In some contexts (e.g.,
|
25
25
|
# in the Rails console) Rake might not be defined.
|
26
|
-
if Object.const_defined?
|
26
|
+
if Object.const_defined? :Rake
|
27
27
|
Rake.application.instance_eval do
|
28
28
|
class << self
|
29
29
|
include ExceptionNotifier::RakePatch
|
data/test/rake_test.rb
CHANGED
@@ -1,23 +1,18 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'mocha/setup'
|
3
3
|
|
4
|
+
require 'active_support/core_ext'
|
4
5
|
require 'exception_notifier/rake'
|
5
6
|
|
6
7
|
class RakeTest < Test::Unit::TestCase
|
7
8
|
|
8
|
-
class IgnoredException < Exception
|
9
|
-
end
|
10
|
-
|
11
9
|
def setup
|
12
10
|
ExceptionNotifier::Rake.reset_for_test
|
13
11
|
assert !ExceptionNotifier::Rake.configured?
|
14
12
|
end
|
15
13
|
|
16
14
|
def expect_delivery(exception, options)
|
17
|
-
|
18
|
-
ExceptionNotifier::Notifier.expects(
|
19
|
-
:background_exception_notification).with(exception, options).returns(mail)
|
20
|
-
mail.expects(:deliver)
|
15
|
+
ExceptionNotifier.expects(:notify_exception).with(exception, options)
|
21
16
|
end
|
22
17
|
|
23
18
|
def test_configure_only_default_options
|
@@ -59,19 +54,4 @@ class RakeTest < Test::Unit::TestCase
|
|
59
54
|
ExceptionNotifier::Rake.maybe_deliver_notification(ex, data)
|
60
55
|
assert_equal(original_options, options)
|
61
56
|
end
|
62
|
-
|
63
|
-
def test_maybe_deliver_notifications_with_ignore_if
|
64
|
-
ExceptionNotifier::Rake.configure(
|
65
|
-
:ignore_if => lambda { |env, e| true })
|
66
|
-
ExceptionNotifier::Rake.maybe_deliver_notification(Exception.new)
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_maybe_deliver_notifications_with_ignore_exceptions
|
70
|
-
ExceptionNotifier::Rake.configure(
|
71
|
-
:ignore_exceptions => ['RakeTest::IgnoredException'])
|
72
|
-
ExceptionNotifier::Rake.maybe_deliver_notification(IgnoredException.new)
|
73
|
-
ex = Exception.new
|
74
|
-
expect_delivery(ex, ExceptionNotifier::Rake.notifier_options)
|
75
|
-
ExceptionNotifier::Rake.maybe_deliver_notification(ex)
|
76
|
-
end
|
77
57
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exception_notification-rake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0.rc1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nik Haldimann
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: exception_notification
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 4.0.0.rc1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 4.0.0.rc1
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rake
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 4.0.0.rc2
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 4.0.0.rc2
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: mocha
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,9 +108,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
109
|
none: false
|
110
110
|
requirements:
|
111
|
-
- - ! '
|
111
|
+
- - ! '>'
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
113
|
+
version: 1.3.1
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
116
|
rubygems_version: 1.8.23
|