resque-pagerduty 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
- # v0.0.1 (2012-09-19)
1
+ # v0.1.1 (2013-06-27)
2
2
 
3
- * Initial release
3
+ * Bug fix: truncate descriptions longer than 120 character. See issue #1.
4
4
 
5
5
  # v0.1.0 (2012-09-20)
6
6
 
@@ -9,3 +9,7 @@
9
9
  * Travis CI integration
10
10
 
11
11
  [resque-std]: https://github.com/defunkt/resque/blob/master/docs/PLUGINS.md
12
+
13
+ # v0.0.1 (2012-09-19)
14
+
15
+ * Initial release
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in resque_pagerduty.gemspec
4
4
  gemspec
5
+
6
+ gem 'pry'
@@ -0,0 +1,32 @@
1
+ module Resque
2
+ module Failure
3
+ class GeneratesPagerdutyDesc
4
+ MAX_LENGTH = 120
5
+ OMISSION = '...'
6
+
7
+ def initialize(exception, payload)
8
+ @exception = exception
9
+ @payload = payload
10
+ end
11
+
12
+ def execute
13
+ if full_message.length > MAX_LENGTH
14
+ full_message.slice(0, MAX_LENGTH - OMISSION.length) + OMISSION
15
+ else
16
+ full_message
17
+ end
18
+ end
19
+
20
+ def self.execute(exception, payload)
21
+ new(exception, payload).execute
22
+ end
23
+
24
+ private
25
+
26
+ def full_message
27
+ @full_message ||= "#{@exception.class} in #{@payload['class']}: #{@exception.message}"
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,6 @@
1
1
  require 'resque'
2
2
  require 'redphone/pagerduty'
3
+ require 'resque/failure/generates_pagerduty_desc'
3
4
 
4
5
  module Resque
5
6
  module Failure
@@ -52,7 +53,7 @@ module Resque
52
53
  def save
53
54
  if service_key
54
55
  pagerduty_client.trigger_incident(
55
- :description => "#{exception.class} in #{payload['class']}: #{exception.message}",
56
+ :description => description,
56
57
  :details => {:queue => queue,
57
58
  :worker => worker.to_s,
58
59
  :payload => payload,
@@ -64,6 +65,11 @@ module Resque
64
65
  end
65
66
 
66
67
  private
68
+
69
+ def description
70
+ @description ||= GeneratesPagerdutyDesc.execute(exception, payload)
71
+ end
72
+
67
73
  def pagerduty_client
68
74
  Redphone::Pagerduty.new(
69
75
  :service_key => service_key,
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "resque-pagerduty"
6
- s.version = "0.1.0"
6
+ s.version = "0.1.1"
7
7
  s.authors = ["Maeve Revels"]
8
8
  s.email = ["maeve.revels@g5platform.com"]
9
9
  s.homepage = "http://github.com/maeve/resque-pagerduty"
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Resque::Failure::GeneratesPagerdutyDesc do
4
+ describe '.execute' do
5
+ let(:payload) { {'class' => 'PayloadClass'} }
6
+
7
+ context 'the complete description is 118 characters or more' do
8
+ let(:exception) { ArgumentError.new('very long message'*8) }
9
+
10
+ it 'should return a truncated description ending with an ellipsis' do
11
+ message = described_class.execute(exception, payload)
12
+ expect(message).to include('ArgumentError in PayloadClass: very long message')
13
+ expect(message).to match(/\.{3}$/)
14
+ expect(message.length).to eq(120)
15
+ end
16
+ end
17
+
18
+ context 'the complete description is less than 118 characters' do
19
+ let(:exception) { ArgumentError.new('My message') }
20
+
21
+ it 'should return the complete description' do
22
+ expect(described_class.execute(exception, payload)).
23
+ to eq('ArgumentError in PayloadClass: My message')
24
+ end
25
+ end
26
+ end
27
+ end
@@ -154,6 +154,35 @@ describe Resque::Failure::Pagerduty do
154
154
  a_request(:any, /.*\.pagerduty\.com/).with(:body => /"details":\{.*"exception":\{.*"backtrace":\["dummy_file.rb:23","dummy_file.rb:42"\].*\}.*\}/).should have_been_made
155
155
  end
156
156
 
157
+ it 'should trigger an incident with a description and details' do
158
+ pagerduty_client = double
159
+ Redphone::Pagerduty.stub(:new).with(hash_including(
160
+ :service_key => service_key,
161
+ :subdomain => '',
162
+ :user => '',
163
+ :password => ''
164
+ )).and_return(pagerduty_client)
165
+
166
+ Resque::Failure::GeneratesPagerdutyDesc.stub(:execute).
167
+ with(exception, payload).and_return('Generated description')
168
+
169
+ pagerduty_client.should_receive(:trigger_incident).with(hash_including(
170
+ :description => 'Generated description',
171
+ :details => {
172
+ :queue => queue,
173
+ :worker => worker.to_s,
174
+ :payload => payload,
175
+ :exception => {
176
+ :class => exception.class.name,
177
+ :message => exception.message,
178
+ :backtrace => exception.backtrace
179
+ }
180
+ }
181
+ ))
182
+
183
+ save
184
+ end
185
+
157
186
  end
158
187
 
159
188
  context 'when there is no service key' do
@@ -162,7 +191,7 @@ describe Resque::Failure::Pagerduty do
162
191
  a_request(:any, /.*.pagerduty.com/).should_not have_been_made
163
192
  end
164
193
  end
165
- end
194
+ end # end describe #save
166
195
 
167
196
  it { should respond_to(:log) }
168
197
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-pagerduty
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Maeve Revels
@@ -15,10 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-09-21 00:00:00 Z
18
+ date: 2013-06-27 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
21
+ name: resque
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
22
24
  none: false
23
25
  requirements:
24
26
  - - ~>
@@ -28,12 +30,12 @@ dependencies:
28
30
  - 1
29
31
  - 7
30
32
  version: "1.7"
31
- prerelease: false
32
33
  type: :runtime
33
- name: resque
34
- requirement: *id001
34
+ version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ name: redphone
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
37
39
  none: false
38
40
  requirements:
39
41
  - - ~>
@@ -44,12 +46,12 @@ dependencies:
44
46
  - 0
45
47
  - 6
46
48
  version: 0.0.6
47
- prerelease: false
48
49
  type: :runtime
49
- name: redphone
50
- requirement: *id002
50
+ version_requirements: *id002
51
51
  - !ruby/object:Gem::Dependency
52
- version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ name: rake
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
53
55
  none: false
54
56
  requirements:
55
57
  - - ">="
@@ -58,12 +60,12 @@ dependencies:
58
60
  segments:
59
61
  - 0
60
62
  version: "0"
61
- prerelease: false
62
63
  type: :development
63
- name: rake
64
- requirement: *id003
64
+ version_requirements: *id003
65
65
  - !ruby/object:Gem::Dependency
66
- version_requirements: &id004 !ruby/object:Gem::Requirement
66
+ name: rspec
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
67
69
  none: false
68
70
  requirements:
69
71
  - - ~>
@@ -73,12 +75,12 @@ dependencies:
73
75
  - 2
74
76
  - 11
75
77
  version: "2.11"
76
- prerelease: false
77
78
  type: :development
78
- name: rspec
79
- requirement: *id004
79
+ version_requirements: *id004
80
80
  - !ruby/object:Gem::Dependency
81
- version_requirements: &id005 !ruby/object:Gem::Requirement
81
+ name: webmock
82
+ prerelease: false
83
+ requirement: &id005 !ruby/object:Gem::Requirement
82
84
  none: false
83
85
  requirements:
84
86
  - - ~>
@@ -88,12 +90,12 @@ dependencies:
88
90
  - 1
89
91
  - 7
90
92
  version: "1.7"
91
- prerelease: false
92
93
  type: :development
93
- name: webmock
94
- requirement: *id005
94
+ version_requirements: *id005
95
95
  - !ruby/object:Gem::Dependency
96
- version_requirements: &id006 !ruby/object:Gem::Requirement
96
+ name: yard
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
97
99
  none: false
98
100
  requirements:
99
101
  - - ~>
@@ -103,12 +105,12 @@ dependencies:
103
105
  - 0
104
106
  - 8
105
107
  version: "0.8"
106
- prerelease: false
107
108
  type: :development
108
- name: yard
109
- requirement: *id006
109
+ version_requirements: *id006
110
110
  - !ruby/object:Gem::Dependency
111
- version_requirements: &id007 !ruby/object:Gem::Requirement
111
+ name: redcarpet
112
+ prerelease: false
113
+ requirement: &id007 !ruby/object:Gem::Requirement
112
114
  none: false
113
115
  requirements:
114
116
  - - ">="
@@ -117,10 +119,8 @@ dependencies:
117
119
  segments:
118
120
  - 0
119
121
  version: "0"
120
- prerelease: false
121
122
  type: :development
122
- name: redcarpet
123
- requirement: *id007
123
+ version_requirements: *id007
124
124
  description: " resque-pagerduty provides a Resque failure backend that triggers a Pagerduty\n incident when an exception is raised by a job.\n"
125
125
  email:
126
126
  - maeve.revels@g5platform.com
@@ -141,9 +141,11 @@ files:
141
141
  - LICENSE.md
142
142
  - README.md
143
143
  - Rakefile
144
+ - lib/resque/failure/generates_pagerduty_desc.rb
144
145
  - lib/resque/failure/pagerduty.rb
145
146
  - lib/resque_pagerduty.rb
146
147
  - resque-pagerduty.gemspec
148
+ - spec/resque/failure/generates_pagerduty_desc_spec.rb
147
149
  - spec/resque/failure/pagerduty_spec.rb
148
150
  - spec/spec_helper.rb
149
151
  homepage: http://github.com/maeve/resque-pagerduty
@@ -175,11 +177,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
177
  requirements: []
176
178
 
177
179
  rubyforge_project: resque-pagerduty
178
- rubygems_version: 1.8.24
180
+ rubygems_version: 1.8.25
179
181
  signing_key:
180
182
  specification_version: 3
181
183
  summary: A Resque failure backend for Pagerduty
182
184
  test_files:
185
+ - spec/resque/failure/generates_pagerduty_desc_spec.rb
183
186
  - spec/resque/failure/pagerduty_spec.rb
184
187
  - spec/spec_helper.rb
185
188
  has_rdoc: