resque-slack 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 78d0b80f0f855aa5fdc798995494912b2b0af915
4
- data.tar.gz: 769178553de497d952e8c7f175b3e6dad0f79d7b
2
+ SHA256:
3
+ metadata.gz: 2ce41f85c44a0507cdaa982921d5374a0bd6b9e33db739019b4f94438abd2839
4
+ data.tar.gz: b3e7cad8320ae24d52b8041e2c1395724e5d447d8aaae4d98ca8bfbff0aebdc6
5
5
  SHA512:
6
- metadata.gz: fa15713942cea5dd021493870cfb1ce164b35109ba1961a1e1fb192b8db0cf0a827c02db25ada984a234b991376e038a38646e369367abb88fda692b2b74784b
7
- data.tar.gz: 4ce830385a993b7de64907b3c04c4420bae177e5a1c387cd63e715fef6d53d80818c5b14ecf9f69a0810a1fa61aa7869d4c06b24b0ba0855a7c8a6a57cce68ad
6
+ metadata.gz: a2afbb049a33a2adc854331965ed4180e2b880800b9f6cee7903b6425d76da8cb753592415f0b758708d6e6ba1cf7b78ca0941472af9eda9e327e308cc472c2b
7
+ data.tar.gz: d0c0f2e0d87cdfc1fb54a7afb9115e4c43d770c4ae8a81e98411af9460abdaa53cb1a18a0ca6105319252b97bfe6a5d7de86ce12e6a9cb9828c4f66fa68e2e48
@@ -0,0 +1,76 @@
1
+ module Resque
2
+ module Failure
3
+ class Notification
4
+
5
+ # Generate the text to be displayed in the Slack Notification
6
+ #
7
+ # failure: resque failure
8
+ # level: notification style
9
+ def self.generate(failure, level)
10
+ new(failure, level).generate
11
+ end
12
+
13
+ def initialize(failure, level)
14
+ @failure = failure
15
+ @level = level
16
+ end
17
+
18
+ def generate
19
+ send(@level)
20
+ end
21
+
22
+ protected
23
+
24
+ # Returns the worker & queue linked to the failed job
25
+ #
26
+ def msg_worker
27
+ "#{@failure.worker} failed processing #{@failure.queue}"
28
+ end
29
+
30
+ # Returns the formatted payload linked to the failed job
31
+ #
32
+ def msg_payload
33
+ "Payload:\n#{format_message(@failure.payload.inspect.split('\n'))}"
34
+ end
35
+
36
+ # Returns the formatted exception linked to the failed job
37
+ #
38
+ def msg_exception
39
+ "Exception:\n#{exception}"
40
+ end
41
+
42
+ # Returns the formatted exception linked to the failed job with backtrace
43
+ #
44
+ def msg_exception_with_backtrace
45
+ "#{msg_exception}\n#{format_message(exception.backtrace)}"
46
+ end
47
+
48
+ # Returns the verbose text notification
49
+ #
50
+ def verbose
51
+ "#{msg_worker}\n#{msg_payload}\n#{msg_exception_with_backtrace}"
52
+ end
53
+
54
+ # Returns the compact text notification
55
+ #
56
+ def compact
57
+ "#{msg_worker}\n#{msg_payload}\n#{msg_exception}"
58
+ end
59
+
60
+ # Returns the minimal text notification
61
+ #
62
+ def minimal
63
+ "#{msg_worker}\n#{msg_payload}"
64
+ end
65
+
66
+ def format_message(obj)
67
+ obj.map{ |l| "\t" + l }.join('\n')
68
+ end
69
+
70
+ def exception
71
+ @failure.exception
72
+ end
73
+ end
74
+ end
75
+ end
76
+
@@ -62,47 +62,9 @@ module Resque
62
62
  # Text to be displayed in the Slack notification
63
63
  #
64
64
  def text
65
- send("text_#{self.class.level}")
65
+ Notification.generate(self, self.class.level)
66
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
67
  end
107
68
  end
108
69
  end
70
+
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'resque'
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'resque', 'failure', 'slack'))
4
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'resque', 'failure', 'notification'))
4
5
 
5
6
  RSpec.configure do |config|
6
7
  config.mock_framework = :rspec
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Blanchard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-28 00:00:00.000000000 Z
11
+ date: 2019-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque
@@ -48,6 +48,7 @@ files:
48
48
  - LICENSE
49
49
  - README.markdown
50
50
  - Rakefile
51
+ - lib/resque/failure/notification.rb
51
52
  - lib/resque/failure/slack.rb
52
53
  - spec/spec_helper.rb
53
54
  homepage: https://www.github.com/julienXX/resque-slack
@@ -68,8 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
69
  - !ruby/object:Gem::Version
69
70
  version: '0'
70
71
  requirements: []
71
- rubyforge_project: resque-slack
72
- rubygems_version: 2.2.2
72
+ rubygems_version: 3.0.0
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: Post Slack notifications whenever one of your Resque jobs fails