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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18bd46cb222d715eb1f2d0000fabc2729e10f572
|
4
|
+
data.tar.gz: 48142bddc135aff00600a45cf5953fa011d2f637
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
127
|
-
|
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(
|
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
|
-
|
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(
|
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(
|
214
|
-
|
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(
|
230
|
+
@exception_notifier.notify_or_ignore(
|
231
|
+
exception,
|
232
|
+
cgi_data: ENV.to_hash,
|
233
|
+
parameters: input
|
234
|
+
)
|
217
235
|
end
|
218
|
-
|
236
|
+
|
237
|
+
{ success: false, error: exception.message }
|
219
238
|
end
|
220
239
|
end
|
221
240
|
|
@@ -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(
|
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
|
-
|
113
|
-
{
|
114
|
+
'Processed request',
|
115
|
+
{
|
116
|
+
success: false,
|
117
|
+
error: { error: 'hey', message: 'message' }
|
118
|
+
}.merge(input)
|
114
119
|
)
|
115
|
-
|
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(
|
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
|
-
|
126
|
-
{
|
132
|
+
'Processed request',
|
133
|
+
{
|
134
|
+
success: false,
|
135
|
+
error: '{:error=>"hey", :message=>"message"}'
|
136
|
+
}.merge(input)
|
127
137
|
)
|
128
|
-
|
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) {
|
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.
|
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-
|
11
|
+
date: 2018-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: airbrake
|