exception_notification-rake 0.0.1 → 0.0.2
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
CHANGED
@@ -1,4 +1,120 @@
|
|
1
|
-
exception_notification-rake
|
2
|
-
|
1
|
+
exception_notification-rake - ExceptionNotifier for Rake tasks
|
2
|
+
==============================================================
|
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
|
+
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
### Basic Configuration
|
10
|
+
|
11
|
+
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:
|
12
|
+
|
13
|
+
# config/environments/production.rb
|
14
|
+
require 'exception_notifier/rake'
|
15
|
+
|
16
|
+
YourApp::Application.configure do
|
17
|
+
# Other configuration here, including ActionMailer config ...
|
18
|
+
|
19
|
+
config.middleware.use ExceptionNotifier,
|
20
|
+
:sender_address => %{"notifier" <sender.address@example.com>},
|
21
|
+
:exception_recipients => %w{your.email@example.com},
|
22
|
+
:ignore_if => lambda { true }
|
23
|
+
|
24
|
+
ExceptionNotifier::Rake.configure
|
25
|
+
end
|
26
|
+
|
27
|
+
**Note:** This uses `:ignore_if` to suppress all exception notifications triggered by the Rails server itself (as opposed to Rake). If you want those notifications as well, omit the `:ignore_if` option.
|
28
|
+
|
29
|
+
If you are already using `ExceptionNotifier` anyway, you don't need to configure it again and all you need is:
|
30
|
+
|
31
|
+
# config/environments/production.rb
|
32
|
+
require 'exception_notifier/rake'
|
33
|
+
|
34
|
+
YourApp::Application.configure do
|
35
|
+
# Other configuration here, including ExceptionNotifer and ActionMailer config ...
|
36
|
+
|
37
|
+
ExceptionNotifier::Rake.configure
|
38
|
+
end
|
39
|
+
|
40
|
+
**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).
|
41
|
+
|
42
|
+
|
43
|
+
### Notification Example
|
44
|
+
|
45
|
+
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`:
|
46
|
+
|
47
|
+
Subject: [Rake Failure] (NoMethodError) "undefined method `khaaaaan!' for main:Object"
|
48
|
+
From: "notifier" <sender.address@example.com>
|
49
|
+
To: <your.email@example.com>
|
50
|
+
|
51
|
+
A NoMethodError occurred in background at 2013-02-07 18:31:57 UTC :
|
52
|
+
|
53
|
+
undefined method `khaaaaan!' for main:Object
|
54
|
+
lib/tasks/scheduler.rake:33:in `block in <top (required)>'
|
55
|
+
|
56
|
+
-------------------------------
|
57
|
+
Rake:
|
58
|
+
-------------------------------
|
59
|
+
|
60
|
+
rake failing_task
|
61
|
+
|
62
|
+
-------------------------------
|
63
|
+
Backtrace:
|
64
|
+
-------------------------------
|
65
|
+
|
66
|
+
lib/tasks/scheduler.rake:33:in `block in <top (required)>'
|
67
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
|
68
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
|
69
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
|
70
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
|
71
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
|
72
|
+
.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
|
73
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
|
74
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
|
75
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
|
76
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
|
77
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
|
78
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
|
79
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
|
80
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
|
81
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
|
82
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
|
83
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
|
84
|
+
.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
|
85
|
+
.rvm/gems/ruby-1.9.3-p327/bin/rake:23:in `load'
|
86
|
+
.rvm/gems/ruby-1.9.3-p327/bin/rake:23:in `<main>'
|
87
|
+
|
88
|
+
(If you're spotting encoding issues here, those appear to be a problem upstream in the exception_notification gem.)
|
89
|
+
|
90
|
+
|
91
|
+
### Usage with Heroku Scheduler
|
92
|
+
|
93
|
+
If you're using Heroku, the [Scheduler add-on](http://addons.heroku.com/scheduler) is a very convenient and cheap (i.e., free) way to run scheduled batch jobs. In a Rails environment it's easiest to define batch jobs as Rake tasks. However, the only way to find out whether a task run by the scheduler succeeded or failed is generally reading the logs.
|
94
|
+
|
95
|
+
This gem fixes this issue. 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.)
|
96
|
+
|
97
|
+
|
98
|
+
### Customization
|
99
|
+
|
100
|
+
You can pass configuration options to `ExceptionNotifier::Rake.configure`. It accepts all the same options as standard `ExceptionNotifier` (see [its documentation](https://github.com/smartinez87/exception_notification)). These options will be applied only to notifications sent as a result of Rake failures.
|
101
|
+
|
102
|
+
The most likely options you'll want to use are `:email_prefix` and `:exception_recpients`. Example:
|
103
|
+
|
104
|
+
ExceptionNotifier::Rake.configure(
|
105
|
+
:email_prefix => "[Cron Failure] ",
|
106
|
+
:exception_recipients => %w{user1@example.com user2@example.com})
|
107
|
+
|
108
|
+
This will prefix the email subjects of Rake failure notifications with `[Cron 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.
|
109
|
+
|
110
|
+
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).
|
111
|
+
|
112
|
+
|
113
|
+
## Installation
|
114
|
+
|
115
|
+
gem install exception_notification-rake
|
116
|
+
|
117
|
+
|
118
|
+
## License
|
119
|
+
|
120
|
+
Distributed under an [MIT license](https://github.com/nikhaldi/exception_notification-rake/blob/master/LICENSE.md).
|
@@ -9,10 +9,15 @@ class ExceptionNotifier
|
|
9
9
|
|
10
10
|
@notifier_options = {}
|
11
11
|
|
12
|
+
# Whether Rake exception notifications have been configured.
|
12
13
|
def self.configured?
|
13
14
|
!@notifier_options.empty?
|
14
15
|
end
|
15
16
|
|
17
|
+
# Configure Rake exception notifications. Should be called in a config file,
|
18
|
+
# usually in config/environments/production.rb for production use.
|
19
|
+
# An optional hash of options can be given, which will be passed through
|
20
|
+
# unchanged to the underlying ExceptionNotifier.
|
16
21
|
def self.configure(options = {})
|
17
22
|
@notifier_options.merge!(default_notifier_options)
|
18
23
|
@notifier_options.merge!(options)
|
@@ -29,7 +34,13 @@ class ExceptionNotifier
|
|
29
34
|
@notifier_options
|
30
35
|
end
|
31
36
|
|
37
|
+
# Deliver a notification about the given exception by email, in case
|
38
|
+
# notifications have been configured. The additional data hash will
|
39
|
+
# be passed through to ExceptionNotifier's data hash and will be availble
|
40
|
+
# in templates.
|
32
41
|
def self.maybe_deliver_notification(exception, data={})
|
42
|
+
# TODO must check whether config has fully loaded yet, to avoid masking
|
43
|
+
# configuration issues.
|
33
44
|
if configured?
|
34
45
|
options = notifier_options
|
35
46
|
if !data.empty?
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
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: 2013-02-
|
12
|
+
date: 2013-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: exception_notification
|
@@ -74,13 +74,11 @@ files:
|
|
74
74
|
- Rakefile
|
75
75
|
- exception_notification-rake.gemspec
|
76
76
|
- lib/exception_notifier/rake.rb
|
77
|
-
- lib/exception_notifier/rake/multi_delegator.rb
|
78
77
|
- lib/exception_notifier/rake/rake.rb
|
79
78
|
- lib/exception_notifier/rake/rake_patch.rb
|
80
79
|
- lib/exception_notifier/rake/version.rb
|
81
80
|
- lib/exception_notifier/rake/views/exception_notifier/_rake.html.erb
|
82
81
|
- lib/exception_notifier/rake/views/exception_notifier/_rake.text.erb
|
83
|
-
- test/multi_delegator_test.rb
|
84
82
|
- test/rake_test.rb
|
85
83
|
homepage: https://github.com/nikhaldi/exception_notification-rake
|
86
84
|
licenses: []
|
@@ -107,6 +105,5 @@ signing_key:
|
|
107
105
|
specification_version: 3
|
108
106
|
summary: Sending exception notifications upon Rake task failures
|
109
107
|
test_files:
|
110
|
-
- test/multi_delegator_test.rb
|
111
108
|
- test/rake_test.rb
|
112
109
|
has_rdoc:
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'delegate'
|
2
|
-
|
3
|
-
class ExceptionNotifier
|
4
|
-
class Rake
|
5
|
-
class MultiDelegator
|
6
|
-
|
7
|
-
def initialize(delegates)
|
8
|
-
@delegates = delegates.map do |del|
|
9
|
-
SimpleDelegator.new(del)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def method_missing(m, *args, &block)
|
14
|
-
return_values = @delegates.map do |del|
|
15
|
-
del.method_missing(m, *args, &block)
|
16
|
-
end
|
17
|
-
return_values.first
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
|
3
|
-
require 'exception_notifier/rake/multi_delegator'
|
4
|
-
|
5
|
-
class MultiDelegatorTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@delegate1 = []
|
9
|
-
@delegate2 = [42]
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_one_delegate
|
13
|
-
delegator = ExceptionNotifier::Rake::MultiDelegator.new([@delegate1])
|
14
|
-
result = delegator.push(42)
|
15
|
-
assert_equal [42], @delegate1
|
16
|
-
assert_equal [42], result
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_multiple_delegates
|
20
|
-
delegator = ExceptionNotifier::Rake::MultiDelegator.new([@delegate1, @delegate2])
|
21
|
-
result = delegator.push(43)
|
22
|
-
assert_equal [43], result
|
23
|
-
assert_equal [43], @delegate1
|
24
|
-
assert_equal [42, 43], @delegate2
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_multiple_delegates_block_argument
|
28
|
-
delegator = ExceptionNotifier::Rake::MultiDelegator.new([@delegate1, @delegate2])
|
29
|
-
result = delegator.map! do |e| e + 1 end
|
30
|
-
assert_equal [], result
|
31
|
-
assert_equal [], @delegate1
|
32
|
-
assert_equal [43], @delegate2
|
33
|
-
end
|
34
|
-
end
|