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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4443c85830f98e8e8f8206eeced59bc57a67714d
4
- data.tar.gz: 3bf7637a2175fc9ef88643d59fa9ae96a66d04d0
3
+ metadata.gz: cdc11db74c43db681c8a94413eb9ca02e39b236e
4
+ data.tar.gz: f94cc83e3afae6f9f363fe5662a6e4931a2cf293
5
5
  SHA512:
6
- metadata.gz: 1e443da2e0523607404a784d179535f48a7aca0088ab770a37de6dc4e76c034f7310ed71f6c588ec27c8df2fb122acb64336490472ab5cef1979a20b46ba4f3d
7
- data.tar.gz: ebee654dc480deb09fb1e21bdd29d86646889ec1410130a952d5f5f716bfe5cac29f402c9cf64047cba89d054172e3c1c7081c4260a4e1e60b269b7c7ab2c2e0
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. `:main` or `:data_processing`)
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/core_ext' #for Hash#except
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
- "title" => "Created",
57
- "value" => Slackiq::TimeHelper.format(created_at),
58
- "short" => true
60
+ 'title' => 'Created',
61
+ 'value' => Slackiq::TimeHelper.format(created_at),
62
+ 'short' => true
59
63
  },
60
64
  {
61
- "title" => time_now_title,
62
- "value" => Slackiq::TimeHelper.format(time_now),
63
- "short" => true
65
+ 'title' => time_now_title,
66
+ 'value' => Slackiq::TimeHelper.format(time_now),
67
+ 'short' => true
64
68
  },
65
69
  {
66
- "title" => "Duration",
67
- "value" => duration,
68
- "short" => true
70
+ 'title' => "Duration",
71
+ 'value' => duration,
72
+ 'short' => true
69
73
  },
70
74
  {
71
- "title" => "Total Jobs",
72
- "value" => total_jobs,
73
- "short" => true
75
+ 'title' => "Total Jobs",
76
+ 'value' => total_jobs,
77
+ 'short' => true
74
78
  },
75
79
  {
76
- "title" => "Jobs Run",
77
- "value" => jobs_run,
78
- "short" => true
80
+ 'title' => "Jobs Run",
81
+ 'value' => jobs_run,
82
+ 'short' => true
79
83
  },
80
84
  {
81
- "title" => "Completion %",
82
- "value" => "#{completion_percentage}%",
83
- "short" => true
85
+ 'title' => "Completion %",
86
+ 'value' => "#{completion_percentage}%",
87
+ 'short' => true
84
88
  },
85
89
  {
86
- "title" => "Failures",
87
- "value" => status.failures,
88
- "short" => true
90
+ 'title' => "Failures",
91
+ 'value' => status.failures,
92
+ 'short' => true
89
93
  },
90
94
  {
91
- "title" => "Failure %",
92
- "value" => "#{failure_percentage}%",
93
- "short" => true
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
- "title" => title,
101
- "value" => value,
102
- "short" => false
104
+ 'title' => title,
105
+ 'value' => value,
106
+ 'short' => false
103
107
  }
104
108
  end
105
109
 
106
110
  attachments =
107
111
  [
108
112
  {
109
- "fallback" => "Sidekiq Batch Completed! (#{description})",
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
 
@@ -1,3 +1,3 @@
1
1
  module Slackiq
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
3
3
  end
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.3
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-07-31 00:00:00.000000000 Z
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.2.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'