resque_slack_notifier 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f8e2809889856e72c43bff16e5875243b99ca0ad
4
+ data.tar.gz: 5ae329eb29f2153b31ea48134c10a4ce1df122bb
5
+ SHA512:
6
+ metadata.gz: 0d93749bee8ae46f876851ce209dba907e538d031322c4dbf212c5b7e858ea6c20267c67597df63f1beff6c4991f0458a3e6cfa1c791bff83c3852a47bf079b6
7
+ data.tar.gz: 9ff66a8def879896a9bae64c1540a91b4dcccf31228f25c384556db128f38fe170faa851d7d776b4da56a6b3a50c0529e9b126fdd01d7c692d5d9287a5bb5efc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Keegan Leitz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # ResqueSlackNotifier
2
+
3
+ Sends a message to Slack whenever a Resque job raises an uncaught exception.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'resque_slack_notifier'
11
+ ```
12
+
13
+ And then do a `bundle install`:
14
+
15
+ ```
16
+ $ bundle
17
+ ```
18
+
19
+ ## Setup
20
+
21
+ Configure the notifier in `config/initializers/resque.rb`:
22
+
23
+ ```ruby
24
+ require "resque/failure/multiple"
25
+ require "resque/failure/redis"
26
+ require "resque/failure/slack_notifier"
27
+
28
+ Resque::Failure::SlackNotifier.configure(
29
+ webhook_url: "your slack webhook url",
30
+ channel: "#some-channel-name",
31
+ display_name: "The Display Name for the Messages",
32
+ notify_channel: true # if you want the messages to start with "@channel"
33
+ )
34
+
35
+ Resque::Failure::Multiple.classes = [ Resque::Failure::Redis, Resque::Failure::SlackNotifier ]
36
+ Resque::Failure.backend = Resque::Failure::Multiple
37
+ ```
38
+
39
+ You can supply a YAML file for the configuration instead, and point to its path:
40
+
41
+ ```ruby
42
+ require "resque/failure/multiple"
43
+ require "resque/failure/redis"
44
+ require "resque/failure/slack_notifier"
45
+ # use your project's root if it's not a Rails app, obviously
46
+ Resque::Failure::SlackNotifier.config_path = File.join(Rails.root, 'path/to/slack_notifier_config.yml')
47
+
48
+ Resque::Failure::Multiple.classes = [ Resque::Failure::Redis, Resque::Failure::SlackNotifier ]
49
+ Resque::Failure.backend = Resque::Failure::Multiple
50
+ ```
51
+
52
+ ...where `path/to/slack_notifier_config.yml` looks like this:
53
+
54
+ ```yaml
55
+ # path/to/slack_notifier_config.yml
56
+
57
+ webhook_url: https://hooks.slack.com/services/s0m3/g4rb4g3/l1k3th1s
58
+ channel: '#resque-failures' # or whatever channel you'd like to be notified in
59
+ display_name: Failed Resque Job Notifier
60
+ notify_channel: true
61
+ ```
62
+
63
+ The only _required_ option, no matter which configuration method you choose, is `webhook_url`. The `channel` option defaults to `"#general"`, `display_name` defaults to `"Resque worker failure"`, and `notify_channel` defaults to `false`.
64
+
65
+ ## Usage
66
+
67
+ That's all there is, really. As long as you have Slack set up properly, you should get a notification any time an exception goes uncaught in a Resque job.
68
+
69
+ ## Bug reports
70
+
71
+ If you encounter a bug, you can report it at https://github.com/kjleitz/resque_slack_notifier/issues. Please include the following information, if possible:
72
+
73
+ - the contents of your `config/initializers/resque.rb` file
74
+ - the contents of your configuration `.yml` file (if applicable)
75
+ - your soul (for eating)
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kjleitz/resque_slack_notifier.
@@ -0,0 +1,58 @@
1
+ require 'yaml'
2
+ require 'slack-notifier'
3
+
4
+ module Resque
5
+ module Failure
6
+ class SlackNotifier < Base
7
+ DEFAULT_CONFIG_OPTIONS = {
8
+ channel: "#general",
9
+ display_name: "Resque worker failure",
10
+ notify_channel: false
11
+ }.freeze
12
+
13
+ class << self
14
+ attr_accessor :config, :client
15
+
16
+ def configure(**options)
17
+ valid_keys = %i(webhook_url channel display_name notify_channel)
18
+ config_options = options.select { |key| valid_keys.include? key }
19
+
20
+ self.config = DEFAULT_CONFIG_OPTIONS.merge config_options
21
+ self.client = Slack::Notifier.new config[:webhook_url],
22
+ channel: config[:channel],
23
+ username: config[:display_name]
24
+ end
25
+
26
+ def config_path=(path)
27
+ configure YAML.load_file(path).symbolize_keys
28
+ end
29
+
30
+ def count
31
+ Stat[:failed]
32
+ end
33
+ end
34
+
35
+ def client
36
+ self.class.client
37
+ end
38
+
39
+ def config
40
+ self.class.config
41
+ end
42
+
43
+ def save
44
+ raise "Client not configured" unless client && config
45
+
46
+ message = [
47
+ "#{"<!channel> " if config[:notify_channel]}Resque worker failure!",
48
+ "Worker: #{worker}",
49
+ "Queue: #{queue}",
50
+ "Job: #{payload['class']}",
51
+ "Args: #{payload['args']}"
52
+ ].join "\n"
53
+
54
+ client.ping message
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module ResqueSlackNotifier
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque_slack_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Keegan Leitz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slack-notifier
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Resque::Failure back-end which sends a Slack message whenever a Resque
56
+ worker fails.
57
+ email:
58
+ - kjleitz@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - lib/resque/failure/slack_notifier.rb
67
+ - lib/resque_slack_notifier/version.rb
68
+ homepage: https://github.com/kjleitz/resque_slack_notifier
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.6.13
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Slack notifier for failed Resque jobs
92
+ test_files: []