red_alert 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +8 -0
- data/Guardfile +5 -0
- data/LICENSE +28 -0
- data/README.md +60 -0
- data/Rakefile +8 -0
- data/lib/red_alert/notification.rb +30 -0
- data/lib/red_alert/notifier.rb +38 -0
- data/lib/red_alert/rack/middleware.rb +16 -0
- data/lib/red_alert/rack/notifier.rb +43 -0
- data/lib/red_alert/rack.rb +1 -0
- data/lib/red_alert/sidekiq/middleware.rb +20 -0
- data/lib/red_alert/sidekiq/notifier.rb +40 -0
- data/lib/red_alert/sidekiq.rb +1 -0
- data/lib/red_alert/version.rb +3 -0
- data/lib/red_alert.rb +4 -0
- data/red_alert.gemspec +16 -0
- data/spec/red_alert/notification_spec.rb +44 -0
- data/spec/red_alert/notifier_spec.rb +78 -0
- data/spec/red_alert/rack/middleware_spec.rb +38 -0
- data/spec/red_alert/rack/notifier_spec.rb +22 -0
- data/spec/red_alert/sidekiq/middleware_spec.rb +41 -0
- data/spec/red_alert/sidekiq/notifier_spec.rb +22 -0
- data/spec/spec_helper.rb +27 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d83a2fe0d578441d5dcd018946390eb65d110b2f
|
4
|
+
data.tar.gz: 15b5f1f4e982a82ffb0ea972dc796236713cd869
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 436f1460909f014b8ce0504a10f6debee939589a94439099d897634205861c6bacd22b7f0faa93a4322da786c32f29cb8fcd5fc5c3edeec85d7b01c1bd9f3430
|
7
|
+
data.tar.gz: a9a617d550af2aec898d09bfa1b524cebb10613e63dd549d0b0cde5bea9fb4344a89a31319ada6608593a628f9935b197571f78ee948330a8b00c31fa5059d3d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Copyright (c) 2012, Peer60
|
2
|
+
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
- Redistributions of source code must retain the above copyright notice, this
|
9
|
+
list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
13
|
+
and/or other materials provided with the distribution.
|
14
|
+
|
15
|
+
- Neither the name of Katalus nor the names of its contributors may be used
|
16
|
+
to endorse or promote products derived from this software without specific
|
17
|
+
prior written permission.
|
18
|
+
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
20
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
28
|
+
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
## Installation
|
2
|
+
|
3
|
+
Add this line to your application's Gemfile:
|
4
|
+
|
5
|
+
gem 'red_alert'
|
6
|
+
|
7
|
+
And then execute:
|
8
|
+
|
9
|
+
$ bundle
|
10
|
+
|
11
|
+
Or install it yourself as:
|
12
|
+
|
13
|
+
$ gem install red_alert
|
14
|
+
|
15
|
+
## Sidekiq Wireup
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Sidekiq.configure_server do |c|
|
19
|
+
c.server_middleware do |chain|
|
20
|
+
chain.add Sidekiq::Middleware::RedAlert,
|
21
|
+
to: 'recipient@example.com',
|
22
|
+
from: 'sender@example.com',
|
23
|
+
subject: "BOOM!: %s",
|
24
|
+
transport_settings: {
|
25
|
+
address: 'smtp.server.net',
|
26
|
+
port: '587',
|
27
|
+
user_name: 'user',
|
28
|
+
password: 'secret',
|
29
|
+
domain: 'example.com',
|
30
|
+
authentication: :plain,
|
31
|
+
enable_starttls_auto: true
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## Rack Wireup
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
use Rack::RedAlert,
|
41
|
+
to: 'recipient@example.com',
|
42
|
+
from: 'sender@example.com',
|
43
|
+
subject: "BOOM!: %s",
|
44
|
+
transport_settings: {
|
45
|
+
address: 'smtp.server.net',
|
46
|
+
port: '587',
|
47
|
+
user_name: 'user',
|
48
|
+
password: 'secret',
|
49
|
+
domain: 'example.com',
|
50
|
+
authentication: :plain,
|
51
|
+
enable_starttls_auto: true
|
52
|
+
```
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module RedAlert
|
4
|
+
class Notification
|
5
|
+
attr_reader :subject, :body
|
6
|
+
|
7
|
+
def initialize(subject, body)
|
8
|
+
@subject = subject
|
9
|
+
@body = body
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def build(subject_template, body_template, exception, data = {})
|
14
|
+
subject = compile_subject subject_template, exception
|
15
|
+
body = compile_body body_template, exception, data
|
16
|
+
self.new subject, body
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def compile_subject(template, exception)
|
22
|
+
template % exception unless template.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def compile_body(template, exception, data)
|
26
|
+
ERB.new(template).result binding
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module RedAlert
|
2
|
+
module Notifier
|
3
|
+
def self.included(klass)
|
4
|
+
klass.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
def notifier_settings
|
8
|
+
@notifier_settings ||= {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def alert(exception, data = {})
|
12
|
+
notification = Notification.build notifier_settings[:subject], template, exception, data
|
13
|
+
mail = Mail.new(
|
14
|
+
to: notifier_settings[:to],
|
15
|
+
from: notifier_settings[:from],
|
16
|
+
subject: notification.subject,
|
17
|
+
body: notification.body
|
18
|
+
)
|
19
|
+
mail.delivery_method :smtp, notifier_settings[:transport_settings]
|
20
|
+
mail.deliver!
|
21
|
+
end
|
22
|
+
|
23
|
+
%i{ to from subject transport_settings }.each do |name|
|
24
|
+
define_method(name){ |value| notifier_settings[name] = value }
|
25
|
+
end
|
26
|
+
|
27
|
+
module ClassMethods
|
28
|
+
def build(settings)
|
29
|
+
notifier = self.new
|
30
|
+
notifier.to settings.fetch(:to)
|
31
|
+
notifier.from settings.fetch(:from)
|
32
|
+
notifier.subject settings.fetch(:subject)
|
33
|
+
notifier.transport_settings settings.fetch(:transport_settings)
|
34
|
+
notifier
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Rack
|
2
|
+
class RedAlert
|
3
|
+
def initialize(inner, settings)
|
4
|
+
@inner = inner
|
5
|
+
@settings = settings
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
@inner.call env
|
10
|
+
rescue => e
|
11
|
+
notification = ::RedAlert::Rack::Notifier.build @settings
|
12
|
+
notification.alert e, env: env
|
13
|
+
raise e
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'pp'
|
2
|
+
|
3
|
+
module RedAlert
|
4
|
+
module Rack
|
5
|
+
class Notifier
|
6
|
+
include RedAlert::Notifier
|
7
|
+
|
8
|
+
def template
|
9
|
+
<<-EMAIL
|
10
|
+
A <%= exception.class %> occured: <%= exception %>
|
11
|
+
<% if data[:request] %>
|
12
|
+
|
13
|
+
===================================================================
|
14
|
+
Request Body:
|
15
|
+
===================================================================
|
16
|
+
|
17
|
+
<%= data[:request].gsub(/^/, ' ') %>
|
18
|
+
<% end %>
|
19
|
+
|
20
|
+
===================================================================
|
21
|
+
Rack Environment:
|
22
|
+
===================================================================
|
23
|
+
|
24
|
+
PID: <%= $$ %>
|
25
|
+
PWD: <%= Dir.getwd %>
|
26
|
+
|
27
|
+
<%= data[:env].to_a.
|
28
|
+
sort{|a,b| a.first <=> b.first}.
|
29
|
+
map{ |k,v| "%-25s%p" % [k+':', v] }.
|
30
|
+
join("\n ") %>
|
31
|
+
|
32
|
+
<% if exception.respond_to?(:backtrace) %>
|
33
|
+
===================================================================
|
34
|
+
Backtrace:
|
35
|
+
===================================================================
|
36
|
+
|
37
|
+
<%= exception.backtrace.join("\n ") %>
|
38
|
+
<% end %>
|
39
|
+
EMAIL
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.expand_path("../rack/*.rb", __FILE__)].each { |f| require f }
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module Middleware
|
3
|
+
class RedAlert
|
4
|
+
def initialize(settings)
|
5
|
+
@settings = settings
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(worker_class, message, queue)
|
9
|
+
yield
|
10
|
+
rescue => e
|
11
|
+
notification = ::RedAlert::Sidekiq::Notifier.build @settings
|
12
|
+
notification.alert e,
|
13
|
+
worker_class: worker_class,
|
14
|
+
message: message,
|
15
|
+
queue: queue
|
16
|
+
raise e
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module RedAlert
|
2
|
+
module Sidekiq
|
3
|
+
class Notifier
|
4
|
+
include RedAlert::Notifier
|
5
|
+
|
6
|
+
def template
|
7
|
+
<<-EMAIL
|
8
|
+
A <%= exception.class %> occured: <%= exception %>
|
9
|
+
|
10
|
+
===================================================================
|
11
|
+
Message:
|
12
|
+
===================================================================
|
13
|
+
|
14
|
+
<%= data[:message].to_a.
|
15
|
+
sort{|a,b| a.first <=> b.first}.
|
16
|
+
map{ |k,v| "%-25s%p" % [k+':', v] }.
|
17
|
+
join("\n ") %>
|
18
|
+
|
19
|
+
===================================================================
|
20
|
+
Sidekiq Environment:
|
21
|
+
===================================================================
|
22
|
+
|
23
|
+
PID: <%= $$ %>
|
24
|
+
PWD: <%= Dir.getwd %>
|
25
|
+
|
26
|
+
Worker Class: <%= data[:worker_class] %>
|
27
|
+
Queue: <%= data[:queue] %>
|
28
|
+
|
29
|
+
<% if exception.respond_to?(:backtrace) %>
|
30
|
+
===================================================================
|
31
|
+
Backtrace:
|
32
|
+
===================================================================
|
33
|
+
|
34
|
+
<%= exception.backtrace.join("\n ") %>
|
35
|
+
<% end %>
|
36
|
+
EMAIL
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.expand_path("../sidekiq/*.rb", __FILE__)].each { |f| require f }
|
data/lib/red_alert.rb
ADDED
data/red_alert.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/red_alert/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.author = 'vyrak.bunleang@gmail.com'
|
6
|
+
gem.description = 'Middlewares for mailing errors'
|
7
|
+
gem.summary = 'Middlewares for mailing errors'
|
8
|
+
|
9
|
+
gem.files = `git ls-files`.split("\n")
|
10
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
11
|
+
gem.name = "red_alert"
|
12
|
+
gem.require_paths = ["lib"]
|
13
|
+
gem.version = RedAlert::VERSION
|
14
|
+
|
15
|
+
gem.add_dependency 'mail', '>= 2.5.4'
|
16
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RedAlert::Notification do
|
4
|
+
describe '::new' do
|
5
|
+
it 'initalizes' do
|
6
|
+
result = RedAlert::Notification.new 'test subject', 'test body'
|
7
|
+
result.subject.must_equal 'test subject'
|
8
|
+
result.body.must_equal 'test body'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '::build' do
|
13
|
+
let(:exception) { RuntimeError.new 'explosion happened' }
|
14
|
+
let(:subject_template) { 'BOOM! %s' }
|
15
|
+
let(:body_template) { 'error: <%= exception.to_s %>' }
|
16
|
+
let(:additional_data) { {} }
|
17
|
+
subject { RedAlert::Notification.build subject_template, body_template, exception, additional_data }
|
18
|
+
|
19
|
+
it 'has subject' do
|
20
|
+
subject.subject.must_equal 'BOOM! explosion happened'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'has body' do
|
24
|
+
subject.body.must_equal 'error: explosion happened'
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'without subject' do
|
28
|
+
let(:subject_template) { nil }
|
29
|
+
|
30
|
+
it 'has nil subject' do
|
31
|
+
subject.subject.must_be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'with additional data for body' do
|
36
|
+
let(:additional_data) { { stuff: 'in body' } }
|
37
|
+
let(:body_template) { 'error: <%= exception.to_s %> with stuff: <%= data[:stuff] %>' }
|
38
|
+
|
39
|
+
it 'has body' do
|
40
|
+
subject.body.must_equal 'error: explosion happened with stuff: in body'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestNotifier
|
4
|
+
include RedAlert::Notifier
|
5
|
+
attr_reader :template
|
6
|
+
|
7
|
+
def initialize(template = '')
|
8
|
+
@template = template
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe RedAlert::Notifier do
|
13
|
+
let(:settings) {
|
14
|
+
{ to: 'recipient@example.com',
|
15
|
+
from: 'sender@example.com',
|
16
|
+
subject: 'something go bad',
|
17
|
+
transport_settings: {
|
18
|
+
field: 'custom'
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
subject { TestNotifier.build settings }
|
24
|
+
|
25
|
+
describe '::build' do
|
26
|
+
%w{ to from subject transport_settings }.each do |field|
|
27
|
+
it "builds with #{field} setting" do
|
28
|
+
field_sym = field.to_sym
|
29
|
+
subject.notifier_settings[field_sym].must_equal settings[field_sym]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#alert' do
|
35
|
+
let(:exception) { RuntimeError.new 'something bad happened' }
|
36
|
+
let(:to) { 'recipient@example.com' }
|
37
|
+
let(:from) { 'sender@example.com' }
|
38
|
+
let(:mail_subject) { 'test subject %s' }
|
39
|
+
let(:data) { { stuff: 'here' } }
|
40
|
+
let(:settings) { {
|
41
|
+
domain: 'example.com',
|
42
|
+
address: 'smtp.sendgrid.net',
|
43
|
+
port: '587',
|
44
|
+
user_name: 'the_user',
|
45
|
+
password: 'secret',
|
46
|
+
authentication: :plain,
|
47
|
+
enable_starttls_auto: true
|
48
|
+
} }
|
49
|
+
|
50
|
+
subject { TestNotifier.new 'test template <%= exception %> |<%= data[:stuff] %>|' }
|
51
|
+
|
52
|
+
before do
|
53
|
+
subject.to to
|
54
|
+
subject.from from
|
55
|
+
subject.subject mail_subject
|
56
|
+
subject.transport_settings settings
|
57
|
+
end
|
58
|
+
|
59
|
+
after { deliveries.clear }
|
60
|
+
|
61
|
+
it 'delivers mail' do
|
62
|
+
result = subject.alert exception, data
|
63
|
+
|
64
|
+
deliveries.length.must_equal 1
|
65
|
+
notification = deliveries.first
|
66
|
+
result.must_equal notification
|
67
|
+
notification.to.must_include to
|
68
|
+
notification.from.must_include from
|
69
|
+
notification.subject.must_equal 'test subject something bad happened'
|
70
|
+
notification.body.to_s.must_equal 'test template something bad happened |here|'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'uses settings' do
|
74
|
+
result = subject.alert(exception).delivery_method.settings
|
75
|
+
result.must_equal settings
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rack::RedAlert do
|
4
|
+
let(:notification) { mock }
|
5
|
+
let(:env) { { 'field' => 'variable' } }
|
6
|
+
let(:error) { RuntimeError.new }
|
7
|
+
let(:settings) { { domain: 'example.com' } }
|
8
|
+
|
9
|
+
it 'wont alert' do
|
10
|
+
inner = mock
|
11
|
+
inner.expect :call, nil, [env]
|
12
|
+
subject = Rack::RedAlert.new inner, settings
|
13
|
+
subject.call env
|
14
|
+
inner.verify
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'alerts' do
|
18
|
+
actual_args = nil
|
19
|
+
actual_error = nil
|
20
|
+
data = { env: env }
|
21
|
+
inner = OpenStruct.new error: error
|
22
|
+
def inner.call(*args); raise error end
|
23
|
+
notification.expect :alert, nil, [error, data]
|
24
|
+
|
25
|
+
begin
|
26
|
+
action = ->(*args) { actual_args = args; notification }
|
27
|
+
RedAlert::Rack::Notifier.stub :build, action do
|
28
|
+
subject = Rack::RedAlert.new inner, settings
|
29
|
+
subject.call env
|
30
|
+
end
|
31
|
+
rescue => e
|
32
|
+
actual_error = e
|
33
|
+
end
|
34
|
+
actual_args.length.must_equal 1
|
35
|
+
actual_args[0].must_equal settings
|
36
|
+
actual_error.must_equal error
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RedAlert::Rack::Notifier do
|
4
|
+
subject { RedAlert::Rack::Notifier.new }
|
5
|
+
|
6
|
+
before do
|
7
|
+
subject.to 'recipient@example.com'
|
8
|
+
subject.from 'sender@example.com'
|
9
|
+
subject.transport_settings({})
|
10
|
+
end
|
11
|
+
|
12
|
+
after { deliveries.clear }
|
13
|
+
|
14
|
+
it 'alerts' do
|
15
|
+
begin
|
16
|
+
raise 'boom'
|
17
|
+
rescue => e
|
18
|
+
subject.alert(e, request: 'data', env: { 'in' => 'out' }).body.wont_be_nil
|
19
|
+
deliveries.length.must_be :>, 0
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sidekiq::Middleware::RedAlert do
|
4
|
+
let(:notification) { mock }
|
5
|
+
let(:worker_class) { mock }
|
6
|
+
let(:msg) { mock }
|
7
|
+
let(:queue) { mock }
|
8
|
+
let(:error) { RuntimeError.new }
|
9
|
+
let(:settings) { { domain: 'example.com' } }
|
10
|
+
|
11
|
+
subject { Sidekiq::Middleware::RedAlert.new settings }
|
12
|
+
|
13
|
+
after { notification.verify }
|
14
|
+
|
15
|
+
it 'wont alert' do
|
16
|
+
subject.call(worker_class, msg, queue) { }
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'alerts' do
|
20
|
+
actual_args = nil
|
21
|
+
actual_error = nil
|
22
|
+
data = {
|
23
|
+
worker_class: worker_class,
|
24
|
+
message: msg,
|
25
|
+
queue: queue
|
26
|
+
}
|
27
|
+
notification.expect :alert, nil, [error, data]
|
28
|
+
|
29
|
+
begin
|
30
|
+
action = ->(*args) { actual_args = args; notification }
|
31
|
+
RedAlert::Sidekiq::Notifier.stub :build, action do
|
32
|
+
subject.call(worker_class, msg, queue) { raise error }
|
33
|
+
end
|
34
|
+
rescue => e
|
35
|
+
actual_error = e
|
36
|
+
end
|
37
|
+
actual_args.length.must_equal 1
|
38
|
+
actual_args[0].must_equal settings
|
39
|
+
actual_error.must_equal error
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RedAlert::Sidekiq::Notifier do
|
4
|
+
subject { RedAlert::Sidekiq::Notifier.new }
|
5
|
+
|
6
|
+
before do
|
7
|
+
subject.to 'recipient@example.com'
|
8
|
+
subject.from 'sender@example.com'
|
9
|
+
subject.transport_settings({})
|
10
|
+
end
|
11
|
+
|
12
|
+
after { deliveries.clear }
|
13
|
+
|
14
|
+
it 'alerts' do
|
15
|
+
begin
|
16
|
+
raise 'boom'
|
17
|
+
rescue => e
|
18
|
+
subject.alert(e, message: { 'args' => ['something', 'useful'] }).body.wont_be_nil
|
19
|
+
deliveries.length.must_be :>, 0
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
4
|
+
require 'red_alert'
|
5
|
+
require 'minitest/pride'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
|
8
|
+
Bundler.require :development
|
9
|
+
|
10
|
+
class Minitest::Spec
|
11
|
+
def mock
|
12
|
+
Minitest::Mock.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def deliveries
|
16
|
+
Mail::TestMailer.deliveries
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Mail.defaults do
|
21
|
+
delivery_method :test
|
22
|
+
end
|
23
|
+
|
24
|
+
mail_configuration = Mail::Configuration.instance
|
25
|
+
def mail_configuration.lookup_delivery_method(*args)
|
26
|
+
Mail::TestMailer
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: red_alert
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- vyrak.bunleang@gmail.com
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mail
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.5.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.5.4
|
27
|
+
description: Middlewares for mailing errors
|
28
|
+
email:
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- Guardfile
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- lib/red_alert.rb
|
40
|
+
- lib/red_alert/notification.rb
|
41
|
+
- lib/red_alert/notifier.rb
|
42
|
+
- lib/red_alert/rack.rb
|
43
|
+
- lib/red_alert/rack/middleware.rb
|
44
|
+
- lib/red_alert/rack/notifier.rb
|
45
|
+
- lib/red_alert/sidekiq.rb
|
46
|
+
- lib/red_alert/sidekiq/middleware.rb
|
47
|
+
- lib/red_alert/sidekiq/notifier.rb
|
48
|
+
- lib/red_alert/version.rb
|
49
|
+
- red_alert.gemspec
|
50
|
+
- spec/red_alert/notification_spec.rb
|
51
|
+
- spec/red_alert/notifier_spec.rb
|
52
|
+
- spec/red_alert/rack/middleware_spec.rb
|
53
|
+
- spec/red_alert/rack/notifier_spec.rb
|
54
|
+
- spec/red_alert/sidekiq/middleware_spec.rb
|
55
|
+
- spec/red_alert/sidekiq/notifier_spec.rb
|
56
|
+
- spec/spec_helper.rb
|
57
|
+
homepage:
|
58
|
+
licenses: []
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.0.3
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Middlewares for mailing errors
|
80
|
+
test_files:
|
81
|
+
- spec/red_alert/notification_spec.rb
|
82
|
+
- spec/red_alert/notifier_spec.rb
|
83
|
+
- spec/red_alert/rack/middleware_spec.rb
|
84
|
+
- spec/red_alert/rack/notifier_spec.rb
|
85
|
+
- spec/red_alert/sidekiq/middleware_spec.rb
|
86
|
+
- spec/red_alert/sidekiq/notifier_spec.rb
|
87
|
+
- spec/spec_helper.rb
|