Class: Resque::Failure::Slack
- Inherits:
-
Base
- Object
- Base
- Resque::Failure::Slack
- Defined in:
- lib/resque/failure/slack.rb
Constant Summary collapse
- LEVELS =
%i(verbose compact minimal)
- SLACK_URL =
'https://slack.com/api'
Class Attribute Summary collapse
-
.channel ⇒ Object
Slack channel id.
-
.level ⇒ Object
Notification style:.
-
.token ⇒ Object
Team token.
Class Method Summary collapse
-
.configure {|_self| ... } ⇒ Object
Configures the failure backend.
- .configured? ⇒ Boolean
Instance Method Summary collapse
-
#report_exception ⇒ Object
Sends a HTTP Post to the Slack api.
-
#save ⇒ Object
Sends the exception data to the Slack channel.
-
#text ⇒ Object
Text to be displayed in the Slack notification.
Class Attribute Details
.channel ⇒ Object
Slack channel id.
12 13 14 |
# File 'lib/resque/failure/slack.rb', line 12 def channel @channel end |
.level ⇒ Object
Notification style:
verbose: full backtrace (default) compact: exception only minimal: worker and payload
20 21 22 |
# File 'lib/resque/failure/slack.rb', line 20 def level @level end |
.token ⇒ Object
Team token
13 14 15 |
# File 'lib/resque/failure/slack.rb', line 13 def token @token end |
Class Method Details
.configure {|_self| ... } ⇒ Object
Configures the failure backend. You will need to set a channel id and a team token.
36 37 38 39 |
# File 'lib/resque/failure/slack.rb', line 36 def self.configure yield self fail 'Slack channel and token are not configured.' unless configured? end |
.configured? ⇒ Boolean
41 42 43 |
# File 'lib/resque/failure/slack.rb', line 41 def self.configured? !!channel && !!token end |
Instance Method Details
#report_exception ⇒ Object
Sends a HTTP Post to the Slack api.
56 57 58 59 60 |
# File 'lib/resque/failure/slack.rb', line 56 def report_exception uri = URI.parse(SLACK_URL + '/chat.postMessage') params = { 'channel' => self.class.channel, 'token' => self.class.token, 'text' => text } Net::HTTP.post_form(uri, params) end |
#save ⇒ Object
Sends the exception data to the Slack channel.
When a job fails, a new instance is created and #save is called.
48 49 50 51 52 |
# File 'lib/resque/failure/slack.rb', line 48 def save return unless self.class.configured? report_exception end |
#text ⇒ Object
Text to be displayed in the Slack notification
64 65 66 |
# File 'lib/resque/failure/slack.rb', line 64 def text Notification.generate(self, self.class.level) end |