resque-slack 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.markdown +56 -0
- data/Rakefile +7 -0
- data/lib/resque/failure/slack.rb +108 -0
- data/spec/spec_helper.rb +10 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 78d0b80f0f855aa5fdc798995494912b2b0af915
|
4
|
+
data.tar.gz: 769178553de497d952e8c7f175b3e6dad0f79d7b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa15713942cea5dd021493870cfb1ce164b35109ba1961a1e1fb192b8db0cf0a827c02db25ada984a234b991376e038a38646e369367abb88fda692b2b74784b
|
7
|
+
data.tar.gz: 4ce830385a993b7de64907b3c04c4420bae177e5a1c387cd63e715fef6d53d80818c5b14ecf9f69a0810a1fa61aa7869d4c06b24b0ba0855a7c8a6a57cce68ad
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) Julien Blanchard
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
Software), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Resque Slack
|
2
|
+
============
|
3
|
+
|
4
|
+
A [Resque][rq] plugin. Requires Resque >= 1.19 and a >= 1.9 Ruby (MRI, JRuby or Rubinius).
|
5
|
+
|
6
|
+
Post a notification in a [Slack][slack] channel when one your jobs fails.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'resque-slack'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install resque-slack
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Configure your channel, token and notification verbosity:
|
25
|
+
```ruby
|
26
|
+
require 'resque/failure/slack'
|
27
|
+
|
28
|
+
Resque::Failure::Slack.configure do |config|
|
29
|
+
config.channel = 'CHANNEL_ID' # required
|
30
|
+
config.token = 'TEAM_TOKEN' # required
|
31
|
+
config.level = verbosity_level # optional
|
32
|
+
end
|
33
|
+
|
34
|
+
Resque::Failure.backend = Resque::Failure::Slack
|
35
|
+
|
36
|
+
```
|
37
|
+
|
38
|
+
Level can be:
|
39
|
+
- verbose: worker, payload, exception and full backtrace
|
40
|
+
- compact: worker, payload and exception
|
41
|
+
- minimal: worker and payload only
|
42
|
+
|
43
|
+
NB: Your team token is found [here](https://api.slack.com/#auth)
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
52
|
+
|
53
|
+
[rq]: http://github.com/julienXX/resque
|
54
|
+
[slack]: http://slack.com
|
55
|
+
|
56
|
+
[![Build Status](https://travis-ci.org/julienXX/resque-slack.png)](https://travis-ci.org/julienXX/resque-slack) [![Code Climate](https://codeclimate.com/github/julienXX/resque-slack.png)](https://codeclimate.com/github/julienXX/resque-slack)
|
data/Rakefile
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'resque'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module Resque
|
6
|
+
module Failure
|
7
|
+
class Slack < Base
|
8
|
+
LEVELS = %i(verbose compact minimal)
|
9
|
+
SLACK_URL = 'https://slack.com/api'
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :channel # Slack channel id.
|
13
|
+
attr_accessor :token # Team token
|
14
|
+
|
15
|
+
# Notification style:
|
16
|
+
#
|
17
|
+
# verbose: full backtrace (default)
|
18
|
+
# compact: exception only
|
19
|
+
# minimal: worker and payload
|
20
|
+
attr_accessor :level
|
21
|
+
|
22
|
+
def level
|
23
|
+
@level && LEVELS.include?(@level) ? @level : :verbose
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Configures the failure backend. You will need to set
|
28
|
+
# a channel id and a team token.
|
29
|
+
#
|
30
|
+
# @example Configure your Slack account:
|
31
|
+
# Resque::Failure::Slack.configure do |config|
|
32
|
+
# config.channel = 'CHANNEL_ID'
|
33
|
+
# config.token = 'TOKEN'
|
34
|
+
# config.verbose = true or false, true is the default
|
35
|
+
# end
|
36
|
+
def self.configure
|
37
|
+
yield self
|
38
|
+
fail 'Slack channel and token are not configured.' unless configured?
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.configured?
|
42
|
+
!!channel && !!token
|
43
|
+
end
|
44
|
+
|
45
|
+
# Sends the exception data to the Slack channel.
|
46
|
+
#
|
47
|
+
# When a job fails, a new instance is created and #save is called.
|
48
|
+
def save
|
49
|
+
return unless self.class.configured?
|
50
|
+
|
51
|
+
report_exception
|
52
|
+
end
|
53
|
+
|
54
|
+
# Sends a HTTP Post to the Slack api.
|
55
|
+
#
|
56
|
+
def report_exception
|
57
|
+
uri = URI.parse(SLACK_URL + '/chat.postMessage')
|
58
|
+
params = { 'channel' => self.class.channel, 'token' => self.class.token, 'text' => text }
|
59
|
+
Net::HTTP.post_form(uri, params)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Text to be displayed in the Slack notification
|
63
|
+
#
|
64
|
+
def text
|
65
|
+
send("text_#{self.class.level}")
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
|
70
|
+
def msg_worker
|
71
|
+
"#{worker} failed processing #{queue}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def msg_payload
|
75
|
+
"Payload:\n#{payload.inspect.split("\n").map { |l| ' ' + l }.join('\n')}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def msg_exception(backtrace)
|
79
|
+
str = "Exception:\n#{exception}"
|
80
|
+
str += "\n#{exception.backtrace.map { |l| ' ' + l }.join('\n')}" if backtrace
|
81
|
+
end
|
82
|
+
|
83
|
+
def text_verbose
|
84
|
+
<<-EOF
|
85
|
+
#{msg_worker}
|
86
|
+
#{msg_payload}
|
87
|
+
#{msg_exception(true)}
|
88
|
+
EOF
|
89
|
+
end
|
90
|
+
|
91
|
+
def text_compact
|
92
|
+
<<-EOF
|
93
|
+
#{msg_worker}
|
94
|
+
#{msg_payload}
|
95
|
+
#{msg_exception(false)}
|
96
|
+
EOF
|
97
|
+
end
|
98
|
+
|
99
|
+
def text_minimal
|
100
|
+
<<-EOF
|
101
|
+
#{msg_worker}
|
102
|
+
#{msg_payload}
|
103
|
+
EOF
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'resque'
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'resque', 'failure', 'slack'))
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.mock_framework = :rspec
|
7
|
+
end
|
8
|
+
|
9
|
+
# Require ruby files in support dir.
|
10
|
+
Dir[File.expand_path('spec/support/*.rb')].each { |file| require file }
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resque-slack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julien Blanchard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: resque
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Slack notifications for your failed jobs
|
42
|
+
email:
|
43
|
+
- julien@sideburns.eu
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE
|
49
|
+
- README.markdown
|
50
|
+
- Rakefile
|
51
|
+
- lib/resque/failure/slack.rb
|
52
|
+
- spec/spec_helper.rb
|
53
|
+
homepage: https://www.github.com/julienXX/resque-slack
|
54
|
+
licenses: []
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project: resque-slack
|
72
|
+
rubygems_version: 2.2.2
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Post Slack notifications whenever one of your Resque jobs fails
|
76
|
+
test_files: []
|