process_handler 2.1.0 → 2.2.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: 98fd113311c50811df459fd962cd08d07a1370ba
4
- data.tar.gz: f1dc5496c0752acccb0edf3860cd4bfe0492b7f9
3
+ metadata.gz: 18bd46cb222d715eb1f2d0000fabc2729e10f572
4
+ data.tar.gz: 48142bddc135aff00600a45cf5953fa011d2f637
5
5
  SHA512:
6
- metadata.gz: 6b063ea89548353200881c51d71f65eccb5255e5e325f9d03f7920b2a7ae842f6963c40b26c7d0fcd6e6dce598f81514ba3dbab5fc6a9ca047cde23ab219993d
7
- data.tar.gz: 25dd37e89cd5656b7dc6988d519c8f933ecd6a3add4389da80051eb8aa7790cb32de6b0ac0681231ddee6e1ed8cf7b06bb86348c4a0c623ec1b758a7dd2fef8a
6
+ metadata.gz: 2f70fec6cbc732807c28be56a8a76730dd5a009033314162ceec96a4d3c32844365db9b301e88d66bbef41f874c20025de3ed8b6375a29612bcc152669972335
7
+ data.tar.gz: 3e22860d47e46de9d1d69e0f890580fae564c6890d9410129576b992efe30de6b5348e04e1aa7f2d67ee2f5372d6e328acdabffaf6f8f6a267bac625e83f032a
@@ -119,14 +119,22 @@ module Salemove
119
119
  def delegate_to_service(input)
120
120
  @logger.info 'Received request', PivotProcess.trace_information.merge(input)
121
121
  @benchmarker.call(input) { @service.call(input) }
122
- rescue => exception
122
+ rescue StandardError => exception
123
123
  handle_exception(exception, input)
124
124
  end
125
125
 
126
- def handle_exception(e, input)
127
- @logger.error(e.inspect + "\n" + e.backtrace.join("\n"), PivotProcess.trace_information)
126
+ def handle_exception(exception, input)
127
+ message = [exception.inspect, *exception.backtrace].join("\n")
128
+ metadata = PivotProcess.trace_information.merge(input)
129
+
130
+ @logger.error(message, metadata)
131
+
128
132
  if @exception_notifier
129
- @exception_notifier.notify_or_ignore(e, cgi_data: ENV.to_hash, parameters: input)
133
+ @exception_notifier.notify_or_ignore(
134
+ exception,
135
+ cgi_data: ENV.to_hash,
136
+ parameters: input
137
+ )
130
138
  end
131
139
  end
132
140
  end
@@ -185,13 +193,14 @@ module Salemove
185
193
  else
186
194
  delegate_to_service(input)
187
195
  end
188
- rescue => exception
196
+ rescue StandardError => exception
189
197
  handle_exception(exception, input)
190
198
  end
191
199
 
192
200
  def delegate_to_service(input)
193
201
  result = @benchmarker.call(input) { @service.call(input) }
194
- if !result.respond_to?(:fulfilled?)
202
+
203
+ unless result.respond_to?(:fulfilled?)
195
204
  log_processed_request(input, result)
196
205
  end
197
206
 
@@ -200,22 +209,32 @@ module Salemove
200
209
 
201
210
  def log_processed_request(input, result)
202
211
  attributes = result
203
- .select {|k, _| PROCESSED_REQUEST_LOG_KEYS.include?(k)}
204
- .merge(type: input[:type])
212
+ .select { |k, _| PROCESSED_REQUEST_LOG_KEYS.include?(k) }
213
+ .merge(input)
205
214
  .merge(PivotProcess.trace_information)
206
215
 
207
216
  if @log_error_as_string
208
217
  attributes[:error] = attributes[:error].to_s if attributes.has_key?(:error)
209
218
  end
219
+
210
220
  @logger.info 'Processed request', attributes
211
221
  end
212
222
 
213
- def handle_exception(e, input)
214
- @logger.error(e.inspect + "\n" + e.backtrace.join("\n"), PivotProcess.trace_information)
223
+ def handle_exception(exception, input)
224
+ message = [exception.inspect, *exception.backtrace].join("\n")
225
+ metadata = PivotProcess.trace_information.merge(input)
226
+
227
+ @logger.error(message, metadata)
228
+
215
229
  if @exception_notifier
216
- @exception_notifier.notify_or_ignore(e, cgi_data: ENV.to_hash, parameters: input)
230
+ @exception_notifier.notify_or_ignore(
231
+ exception,
232
+ cgi_data: ENV.to_hash,
233
+ parameters: input
234
+ )
217
235
  end
218
- { success: false, error: e.message }
236
+
237
+ { success: false, error: exception.message }
219
238
  end
220
239
  end
221
240
 
@@ -1,5 +1,5 @@
1
1
  module Salemove
2
2
  module ProcessHandler
3
- VERSION = '2.1.0'
3
+ VERSION = '2.2.0'
4
4
  end
5
5
  end
@@ -99,46 +99,55 @@ describe ProcessHandler::PivotProcess do
99
99
  end
100
100
 
101
101
  describe 'when service responds with an error object' do
102
- let(:result) { { success: false, error: {error: 'hey', message: 'message' } } }
102
+ let(:result) { { success: false, error: { error: 'hey', message: 'message' } } }
103
+ let(:input) { { type: :update, value: 42 } }
103
104
 
104
105
  before do
105
106
  expect(service).to receive(:call).with(input) { result }
106
107
  end
107
108
 
108
- it 'logs the message as an object' do
109
- expect(logger).to receive(:info).with("Received request", {})
109
+ it 'logs the message as an object and includes input' do
110
+ expect(logger).to receive(:info).with('Received request', input)
111
+
110
112
  expect(logger).to receive(:info)
111
113
  .with(
112
- "Processed request",
113
- { success: false, error: {error: 'hey', message: 'message'}, type: nil }
114
+ 'Processed request',
115
+ {
116
+ success: false,
117
+ error: { error: 'hey', message: 'message' }
118
+ }.merge(input)
114
119
  )
115
- subject()
120
+
121
+ subject
116
122
  end
117
123
 
118
124
  describe 'when log_error_as_string' do
119
125
  let(:log_error_as_string) { true }
120
126
 
121
- it 'logs the message as string' do
122
- expect(logger).to receive(:info).with("Received request", {})
127
+ it 'logs the message as string and includes input' do
128
+ expect(logger).to receive(:info).with('Received request', input)
129
+
123
130
  expect(logger).to receive(:info)
124
131
  .with(
125
- "Processed request",
126
- { success: false, error: "{:error=>\"hey\", :message=>\"message\"}", type: nil }
132
+ 'Processed request',
133
+ {
134
+ success: false,
135
+ error: '{:error=>"hey", :message=>"message"}'
136
+ }.merge(input)
127
137
  )
128
- subject()
138
+
139
+ subject
129
140
  end
130
141
  end
131
142
  end
132
143
 
133
144
  shared_examples 'an error_handler' do
134
-
135
145
  it 'logs error' do
136
- expect(logger).to receive(:error)
137
- subject()
146
+ expect(logger).to receive(:error).with(an_instance_of(String), input)
147
+ subject
138
148
  end
139
149
 
140
150
  describe 'with exception_notifier' do
141
-
142
151
  let(:exception_notifier) { double('Airbrake') }
143
152
 
144
153
  before do
@@ -147,16 +156,15 @@ describe ProcessHandler::PivotProcess do
147
156
 
148
157
  it 'triggers exception_notifier' do
149
158
  expect(exception_notifier).to receive(:notify_or_ignore)
150
- subject()
159
+ subject
151
160
  end
152
161
  end
153
-
154
162
  end
155
163
 
156
164
  describe 'when service raises exception' do
157
-
165
+ let(:input) { { type: :update, value: 42 } }
158
166
  let(:result) { { success: false, error: exception } }
159
- let(:exception) { "what an unexpected exception!" }
167
+ let(:exception) { 'what an unexpected exception!' }
160
168
 
161
169
  before do
162
170
  expect(service).to receive(:call).with(input) { raise exception }
@@ -164,11 +172,10 @@ describe ProcessHandler::PivotProcess do
164
172
 
165
173
  it 'acks the message properly' do
166
174
  expect(handler).to receive(:error).with(result)
167
- subject()
175
+ subject
168
176
  end
169
177
 
170
178
  it_behaves_like 'an error_handler'
171
-
172
179
  end
173
180
 
174
181
  describe 'when result is fulfillable' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: process_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SaleMove TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-22 00:00:00.000000000 Z
11
+ date: 2018-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: airbrake