resque-notifier 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +16 -1
- data/lib/core_ext/string.rb +22 -0
- data/lib/env_resque.rb +25 -0
- data/lib/resque/failure/notifier.rb +55 -10
- data/lib/resque/notifier/version.rb +1 -1
- data/spec/resque_notifier_spec.rb +13 -0
- metadata +4 -3
- data/lib/resque/notifier.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4eaa19742898bd370221847670522b38c4adbb50
|
4
|
+
data.tar.gz: 4cf637b5f47fd8e4b1fdafa50e8609a467752c71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23ccbd9239ea132a31d19e018057e1ef2f1faecee89908aec37cbf5a24a5459265ad87cd53ae42b3b193bf3547e3f61b68dcf034bc8d62bf3b44c85fc23e7e6d
|
7
|
+
data.tar.gz: 15c7615b67e4bd5806cf0720fd11c4aa35d0276ffd97c72a38252c6cb26c7d137924cf8247c0440fca63bbf3d18b5e7e9397f5030c9755273fa8d0cf481b5632
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Resque::Notifier
|
2
2
|
|
3
|
+
[](https://circleci.com/gh/daveed/resque-notifier/tree/master)
|
3
4
|
[](https://codeclimate.com/github/daveed/resque-notifier) [](https://codeclimate.com/github/daveed/resque-notifier/coverage)
|
4
5
|
|
5
6
|
Resque Notifier is a Resque plugin that sends notifications when a job fails.
|
@@ -26,7 +27,21 @@ Or install it yourself as:
|
|
26
27
|
|
27
28
|
## Usage
|
28
29
|
|
29
|
-
|
30
|
+
### This gem activates a notifier when environment variables are set.
|
31
|
+
|
32
|
+
example: Slack
|
33
|
+
RESQUE_HOOK=https://hooks.slack.com/services/<generated_hash>
|
34
|
+
RESQUE_CHANNEL="#channel-name"
|
35
|
+
|
36
|
+
### Add the Notifier backend to your existing Resque configuration (config/initializers/resque.rb)
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'resque/failure/notifier'
|
40
|
+
Resque::Failure::Multiple.classes = [Resque::Failure::Redis, Resque::Failure::Notifier]
|
41
|
+
Resque::Failure.backend = Resque::Failure::Multiple
|
42
|
+
```
|
43
|
+
|
44
|
+
|
30
45
|
|
31
46
|
## Contributing
|
32
47
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# from activesupport/lib/active_support/core_ext/object/blank.rb
|
2
|
+
|
3
|
+
class String
|
4
|
+
BLANK_REGEX = /\A[[:space:]]*\z/
|
5
|
+
|
6
|
+
# A string is blank if it's empty or contains whitespaces only:
|
7
|
+
#
|
8
|
+
# ''.blank? # => true
|
9
|
+
# ' '.blank? # => true
|
10
|
+
# "\t\n\r".blank? # => true
|
11
|
+
# ' blah '.blank? # => false
|
12
|
+
#
|
13
|
+
# Unicode whitespace is supported:
|
14
|
+
#
|
15
|
+
# "\u00a0".blank? # => true
|
16
|
+
#
|
17
|
+
# @return [true, false]
|
18
|
+
def blank?
|
19
|
+
BLANK_REGEX === self
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/env_resque.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "core_ext/string"
|
2
|
+
|
3
|
+
module EnvResque
|
4
|
+
|
5
|
+
def env_resque_channel
|
6
|
+
ENV["RESQUE_CHANNEL"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def env_resque_hook
|
10
|
+
ENV["RESQUE_HOOK"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def env_resque_host
|
14
|
+
ENV["RESQUE_HOST"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def haz_env_resque_host?
|
18
|
+
!env_resque_host.blank?
|
19
|
+
end
|
20
|
+
|
21
|
+
def haz_required_envs?
|
22
|
+
!env_resque_channel.blank? && !env_resque_hook.blank?
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -1,21 +1,66 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "uri"
|
2
|
+
require "resque"
|
3
|
+
require "net/http"
|
4
|
+
require "env_resque"
|
4
5
|
|
5
6
|
module Resque
|
6
7
|
module Failure
|
7
8
|
class Notifier < Base
|
8
9
|
|
10
|
+
include EnvResque
|
11
|
+
|
9
12
|
def save
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
return unless haz_required_envs?
|
14
|
+
unless exception_logged_already?
|
15
|
+
uri = URI(env_resque_hook)
|
16
|
+
payload = {
|
17
|
+
channel: env_resque_channel,
|
18
|
+
username: "resque",
|
19
|
+
text: text,
|
20
|
+
icon_emoji: ":ghost:"
|
21
|
+
}.to_json
|
22
|
+
Net::HTTP.post_form(uri, payload: payload)
|
23
|
+
end
|
16
24
|
end
|
17
25
|
|
18
|
-
|
26
|
+
def exception_logged_already?
|
27
|
+
count = 0
|
28
|
+
failed_resque_jobs.each do |failed_job|
|
29
|
+
break if count > 1
|
30
|
+
if failed_job.include?(error_class) && failed_job.include?(error_exception)
|
31
|
+
count += 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
count > 1 ? true : false
|
35
|
+
end
|
36
|
+
|
37
|
+
def failed_resque_jobs
|
38
|
+
Resque.redis.lrange("failed", 0, 1000)
|
39
|
+
end
|
40
|
+
|
41
|
+
def text
|
42
|
+
"Worker: #{worker.to_s} \n" \
|
43
|
+
"Class: #{link_to_class} \n" \
|
44
|
+
"Exception: #{error_exception} \n" \
|
45
|
+
"Error: #{exception.to_s} \n"
|
46
|
+
end
|
19
47
|
|
48
|
+
def link_to_class
|
49
|
+
if haz_env_resque_host?
|
50
|
+
"#{env_resque_host}/resque/failed/?class=#{error_class}"
|
51
|
+
else
|
52
|
+
error_class
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def error_exception
|
57
|
+
(exception && exception.class).to_s
|
58
|
+
end
|
59
|
+
|
60
|
+
def error_class
|
61
|
+
(payload && payload["class"]).to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
20
65
|
end
|
21
66
|
end
|
@@ -2,4 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Resque::Notifier do
|
4
4
|
|
5
|
+
context "Slack Notifications" do
|
6
|
+
|
7
|
+
it 'should display the exception message in Slack' do
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should return the exception type' do
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should prevent too many messages being displayed' do
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
5
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- daveed
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-09-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: resque
|
@@ -182,8 +182,9 @@ files:
|
|
182
182
|
- LICENSE.txt
|
183
183
|
- README.md
|
184
184
|
- Rakefile
|
185
|
+
- lib/core_ext/string.rb
|
186
|
+
- lib/env_resque.rb
|
185
187
|
- lib/resque/failure/notifier.rb
|
186
|
-
- lib/resque/notifier.rb
|
187
188
|
- lib/resque/notifier/version.rb
|
188
189
|
- resque-notifier.gemspec
|
189
190
|
- spec/resque_notifier_spec.rb
|