slackiq 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -2
- data/lib/slackiq.rb +43 -29
- data/lib/slackiq/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdc11db74c43db681c8a94413eb9ca02e39b236e
|
4
|
+
data.tar.gz: f94cc83e3afae6f9f363fe5662a6e4931a2cf293
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa7f69ec29eee9492b1490766be03441620b37445875962d1ccdfdb5e3f5cfcbb2fba26cd1e5a2855e05f8bbb6f71a312ce32b6fc144842c172e37cd4e00624a
|
7
|
+
data.tar.gz: 3194efba82b6bdf793004dc3eb79af692fe3e0a8077a6bf7b3ba04eea7dec9c1deee01f0115b7c5c71984e1fafddfa6800feeca68b10908067e27c036db122e8
|
data/README.md
CHANGED
@@ -10,6 +10,10 @@ Add this line to your Gemfile:
|
|
10
10
|
|
11
11
|
`gem 'slackiq'`
|
12
12
|
|
13
|
+
Then run:
|
14
|
+
|
15
|
+
`bundle install`
|
16
|
+
|
13
17
|
## Configuration
|
14
18
|
|
15
19
|
First, set up any number of Slack Incoming Webhooks [from your Slack](https://slack.com/services/new/incoming-webhook).
|
@@ -21,12 +25,17 @@ Slackiq.configure( web_scrapes: 'https://hooks.slack.com/services/HA298HF2/ALSKF
|
|
21
25
|
data_processing: 'https://hooks.slack.com/services/HA298HF2/ALSKF2451/H24dLKAHD22423')
|
22
26
|
```
|
23
27
|
|
28
|
+
`:web_scrapes` and `data_processing` are examples of keys. Use whatever keys you want.
|
29
|
+
|
24
30
|
## Usage
|
25
31
|
|
26
|
-
You can call `notify` to send a nicely-formatted notification to your Slack.
|
32
|
+
You can call `notify` to send a nicely-formatted notification to your Slack. You can call `notify`
|
33
|
+
|
34
|
+
* Inside the Sidekiq Pro `on_success` or `on_complete` callbacks
|
35
|
+
* From inside a Sidekiq worker while it's running, in which case you should pass in the `bid` to the `perform` method of the worker
|
27
36
|
|
28
37
|
The `notify` method has a single Hash parameter. Here are the keys and values in the Hash:
|
29
|
-
* `:webhook_name` The name of the webhook (Symbol) that you configured (eg. `:
|
38
|
+
* `:webhook_name` The name of the webhook (Symbol) that you configured (eg. `:web_scrapes` or `:data_processing`)
|
30
39
|
* `:title` The title of the notification (String)
|
31
40
|
* `:status` An instance of `Sidekiq::Batch::Status`
|
32
41
|
* Any other keys and values (both Strings) can be added too, and they'll be added to the Slack notification!
|
@@ -68,6 +77,14 @@ end
|
|
68
77
|
|
69
78
|
Note that in this case, `'Total URLs in DB'` and `'Servers'` are custom fields that will also appear in Slack!
|
70
79
|
|
80
|
+
### Want to send a message to Slack that isn't Sidekiq-related?
|
81
|
+
|
82
|
+
No prob. Just:
|
83
|
+
|
84
|
+
```
|
85
|
+
Slackiq.send('Server 5 is overloaded!', webhook_name: :data_processing)
|
86
|
+
```
|
87
|
+
|
71
88
|
## Contributing
|
72
89
|
|
73
90
|
Bug reports and pull requests are welcome on GitHub at https://github.com/MightySignal/slackiq. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
data/lib/slackiq.rb
CHANGED
@@ -6,17 +6,21 @@ require 'httparty'
|
|
6
6
|
|
7
7
|
require 'slackiq/time_helper'
|
8
8
|
|
9
|
-
require 'active_support
|
9
|
+
require 'active_support' #for Hash#except
|
10
10
|
|
11
11
|
module Slackiq
|
12
12
|
|
13
13
|
class << self
|
14
14
|
|
15
|
+
# Configure all of the webhook URLs you're going to use
|
16
|
+
# @author Jason Lew
|
15
17
|
def configure(webhook_urls={})
|
16
18
|
raise 'Argument must be a Hash' unless webhook_urls.class == Hash
|
17
19
|
@@webhook_urls = webhook_urls
|
18
20
|
end
|
19
21
|
|
22
|
+
# Send a notification to Slack with Sidekiq info about the batch
|
23
|
+
# @author Jason Lew
|
20
24
|
def notify(options={})
|
21
25
|
url = @@webhook_urls[options[:webhook_name]]
|
22
26
|
title = options[:title]
|
@@ -53,60 +57,60 @@ module Slackiq
|
|
53
57
|
|
54
58
|
fields = [
|
55
59
|
{
|
56
|
-
|
57
|
-
|
58
|
-
|
60
|
+
'title' => 'Created',
|
61
|
+
'value' => Slackiq::TimeHelper.format(created_at),
|
62
|
+
'short' => true
|
59
63
|
},
|
60
64
|
{
|
61
|
-
|
62
|
-
|
63
|
-
|
65
|
+
'title' => time_now_title,
|
66
|
+
'value' => Slackiq::TimeHelper.format(time_now),
|
67
|
+
'short' => true
|
64
68
|
},
|
65
69
|
{
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
'title' => "Duration",
|
71
|
+
'value' => duration,
|
72
|
+
'short' => true
|
69
73
|
},
|
70
74
|
{
|
71
|
-
|
72
|
-
|
73
|
-
|
75
|
+
'title' => "Total Jobs",
|
76
|
+
'value' => total_jobs,
|
77
|
+
'short' => true
|
74
78
|
},
|
75
79
|
{
|
76
|
-
|
77
|
-
|
78
|
-
|
80
|
+
'title' => "Jobs Run",
|
81
|
+
'value' => jobs_run,
|
82
|
+
'short' => true
|
79
83
|
},
|
80
84
|
{
|
81
|
-
|
82
|
-
|
83
|
-
|
85
|
+
'title' => "Completion %",
|
86
|
+
'value' => "#{completion_percentage}%",
|
87
|
+
'short' => true
|
84
88
|
},
|
85
89
|
{
|
86
|
-
|
87
|
-
|
88
|
-
|
90
|
+
'title' => "Failures",
|
91
|
+
'value' => status.failures,
|
92
|
+
'short' => true
|
89
93
|
},
|
90
94
|
{
|
91
|
-
|
92
|
-
|
93
|
-
|
95
|
+
'title' => "Failure %",
|
96
|
+
'value' => "#{failure_percentage}%",
|
97
|
+
'short' => true
|
94
98
|
},
|
95
99
|
]
|
96
100
|
|
97
101
|
# add extra fields
|
98
102
|
fields += extra_fields.map do |title, value|
|
99
103
|
{
|
100
|
-
|
101
|
-
|
102
|
-
|
104
|
+
'title' => title,
|
105
|
+
'value' => value,
|
106
|
+
'short' => false
|
103
107
|
}
|
104
108
|
end
|
105
109
|
|
106
110
|
attachments =
|
107
111
|
[
|
108
112
|
{
|
109
|
-
|
113
|
+
'fallback' => "Sidekiq Batch Completed! (#{description})",
|
110
114
|
|
111
115
|
'color' => '#00ff66',
|
112
116
|
|
@@ -122,6 +126,16 @@ module Slackiq
|
|
122
126
|
|
123
127
|
HTTParty.post(url, body: body)
|
124
128
|
end
|
129
|
+
|
130
|
+
# Send a notification without Sidekiq batch info
|
131
|
+
# @author Jason Lew
|
132
|
+
def send(message, options)
|
133
|
+
url = @@webhook_urls[options[:webhook_name]]
|
134
|
+
|
135
|
+
body = { 'text' => message }.to_json
|
136
|
+
|
137
|
+
HTTParty.post(url, body: body)
|
138
|
+
end
|
125
139
|
|
126
140
|
end
|
127
141
|
|
data/lib/slackiq/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slackiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lew
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.4.6
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: 'MightySignal: Slack and Sidekiq Pro integration'
|