process_handler 0.1.5 → 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
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81202c6d556c0fca525065d69f4861a2f3d49eb9
|
4
|
+
data.tar.gz: 84f98a062e9b9e87dc67dc5345a6b03f5374cd8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5f5c704431e9fab040bb0a0e84f96cfd0202608b8e3226c4f31e6dd034e4533544d2545e8a30047d1dd07837e38205b3d0985f5a2899df21de5f64b86837b6f
|
7
|
+
data.tar.gz: 989bfbb942d69afaf31a8944dfd04874941a8f5d3438429de528f76d5908efeac97c742e1fe96e4f0dc3ed8e9bb4836fe0cb2dcd0259e69f8220d309c99b494d
|
data/Gemfile.lock
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'benchmark'
|
3
|
+
require 'securerandom'
|
3
4
|
require_relative 'process_monitor'
|
4
5
|
require_relative 'notifier_factory'
|
5
6
|
|
@@ -67,8 +68,9 @@ module Salemove
|
|
67
68
|
|
68
69
|
bm = Benchmark.measure { result = block.call }
|
69
70
|
if defined?(Logasm) && PivotProcess.logger.is_a?(Logasm)
|
70
|
-
PivotProcess.logger.
|
71
|
-
|
71
|
+
PivotProcess.logger.info "Execution time",
|
72
|
+
request_id: input[:request_id], type: type,
|
73
|
+
real: bm.real, user: bm.utime, system: bm.stime
|
72
74
|
end
|
73
75
|
result
|
74
76
|
end
|
@@ -92,18 +94,20 @@ module Salemove
|
|
92
94
|
|
93
95
|
def spawn(queue)
|
94
96
|
@messenger.tap_into(queue) do |input|
|
95
|
-
|
97
|
+
request_id = SecureRandom.hex(5)
|
98
|
+
delegate_to_service(input.merge(type: queue, request_id: request_id))
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
99
102
|
def delegate_to_service(input)
|
103
|
+
PivotProcess.logger.info "Received request", input
|
100
104
|
PivotProcess.benchmark(input) { @service.call(input) }
|
101
105
|
rescue => exception
|
102
106
|
handle_exception(exception, input)
|
103
107
|
end
|
104
108
|
|
105
109
|
def handle_exception(e, input)
|
106
|
-
PivotProcess.logger.error(e.inspect + "\n" + e.backtrace.join("\n"))
|
110
|
+
PivotProcess.logger.error(e.inspect + "\n" + e.backtrace.join("\n"), request_id: input[:request_id])
|
107
111
|
if @exception_notifier
|
108
112
|
@exception_notifier.notify_or_ignore(e, cgi_data: ENV.to_hash, parameters: input)
|
109
113
|
end
|
@@ -123,7 +127,9 @@ module Salemove
|
|
123
127
|
|
124
128
|
def spawn
|
125
129
|
@messenger.respond_to(@service.class::QUEUE) do |input, handler|
|
126
|
-
|
130
|
+
request_id = SecureRandom.hex(5)
|
131
|
+
|
132
|
+
response = handle_request(input.merge(request_id: request_id))
|
127
133
|
if response.respond_to?(:fulfilled?)
|
128
134
|
handle_fulfillable_response(handler, response)
|
129
135
|
else
|
@@ -165,13 +171,14 @@ module Salemove
|
|
165
171
|
end
|
166
172
|
|
167
173
|
def delegate_to_service(input)
|
174
|
+
request_id = input[:request_id]
|
168
175
|
result = PivotProcess.benchmark(input) { @service.call(input) }
|
169
|
-
PivotProcess.logger.info "
|
176
|
+
PivotProcess.logger.info "Processed request", result.merge(request_id: request_id)
|
170
177
|
result
|
171
178
|
end
|
172
179
|
|
173
180
|
def handle_exception(e, input)
|
174
|
-
PivotProcess.logger.error(e.inspect + "\n" + e.backtrace.join("\n"))
|
181
|
+
PivotProcess.logger.error(e.inspect + "\n" + e.backtrace.join("\n"), request_id: input[:request_id])
|
175
182
|
if @exception_notifier
|
176
183
|
@exception_notifier.notify_or_ignore(e, cgi_data: ENV.to_hash, parameters: input)
|
177
184
|
end
|
@@ -25,7 +25,6 @@ describe ProcessHandler::PivotProcess do
|
|
25
25
|
expect_monitor_to_behave
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
28
|
describe 'responding services' do
|
30
29
|
class ResultService
|
31
30
|
QUEUE = 'Dummy'
|
@@ -44,7 +43,6 @@ describe ProcessHandler::PivotProcess do
|
|
44
43
|
expect(responder).to receive(:join)
|
45
44
|
end
|
46
45
|
|
47
|
-
|
48
46
|
def expect_message
|
49
47
|
expect(messenger).to receive(:respond_to) {|destination, &callback|
|
50
48
|
callback.call(input, handler)
|
@@ -54,14 +52,14 @@ describe ProcessHandler::PivotProcess do
|
|
54
52
|
before do
|
55
53
|
expect_message
|
56
54
|
expect_handler_thread_to_behave
|
57
|
-
allow(service).to receive(:call).with(input) { result }
|
55
|
+
allow(service).to receive(:call).with(input.merge(request_id: anything)) { result }
|
58
56
|
end
|
59
57
|
|
60
58
|
describe 'when service responds correctly' do
|
61
59
|
|
62
60
|
it 'can be executed with logger' do
|
63
61
|
expect(handler).to receive(:success).with(result)
|
64
|
-
expect(service).to receive(:call).with(input)
|
62
|
+
expect(service).to receive(:call).with(input.merge(request_id: anything))
|
65
63
|
subject()
|
66
64
|
end
|
67
65
|
|
@@ -71,7 +69,7 @@ describe ProcessHandler::PivotProcess do
|
|
71
69
|
let(:result) { { success: false, error: 'hey' } }
|
72
70
|
|
73
71
|
before do
|
74
|
-
expect(service).to receive(:call).with(input) { result }
|
72
|
+
expect(service).to receive(:call).with(input.merge(request_id: anything)) { result }
|
75
73
|
end
|
76
74
|
|
77
75
|
it 'acks the message properly' do
|
@@ -109,7 +107,7 @@ describe ProcessHandler::PivotProcess do
|
|
109
107
|
let(:exception) { "what an unexpected exception!" }
|
110
108
|
|
111
109
|
before do
|
112
|
-
expect(service).to receive(:call).with(input) { raise exception }
|
110
|
+
expect(service).to receive(:call).with(input.merge(request_id: anything)) { raise exception }
|
113
111
|
end
|
114
112
|
|
115
113
|
it 'acks the message properly' do
|
@@ -121,25 +119,8 @@ describe ProcessHandler::PivotProcess do
|
|
121
119
|
|
122
120
|
end
|
123
121
|
|
124
|
-
describe 'when exception raises after service call' do
|
125
|
-
|
126
|
-
let(:result) { { success: false, output: exception } }
|
127
|
-
let(:exception) { "no no no ... no inspect for you!" }
|
128
|
-
|
129
|
-
before do
|
130
|
-
expect(result).to receive(:inspect) { raise exception }
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'still acks the message properly' do
|
134
|
-
subject()
|
135
|
-
end
|
136
|
-
|
137
|
-
it_behaves_like 'an error_handler'
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
122
|
describe 'when result is fulfillable' do
|
142
|
-
let(:result) {
|
123
|
+
let(:result) { {} }
|
143
124
|
|
144
125
|
context 'and its already fulfilled' do
|
145
126
|
let(:value) { { success: true, output: { result: 'R'} } }
|
@@ -216,11 +197,10 @@ describe ProcessHandler::PivotProcess do
|
|
216
197
|
allow(service).to receive(:call).with(input)
|
217
198
|
end
|
218
199
|
|
219
|
-
|
220
200
|
describe 'when service handles the input correctly' do
|
221
201
|
it 'can be executed' do
|
222
|
-
expect(service).to receive(:call).with(input.merge(type: 'one'))
|
223
|
-
expect(service).to receive(:call).with(input.merge(type: 'two'))
|
202
|
+
expect(service).to receive(:call).with(input.merge(type: 'one', request_id: anything))
|
203
|
+
expect(service).to receive(:call).with(input.merge(type: 'two', request_id: anything))
|
224
204
|
subject()
|
225
205
|
end
|
226
206
|
end
|
@@ -251,8 +231,8 @@ describe ProcessHandler::PivotProcess do
|
|
251
231
|
let(:exception) { "what an unexpected exception!" }
|
252
232
|
|
253
233
|
before do
|
254
|
-
expect(service).to receive(:call).with(input.merge(type: 'one')) {}
|
255
|
-
expect(service).to receive(:call).with(input.merge(type: 'two')) { raise exception }
|
234
|
+
expect(service).to receive(:call).with(input.merge(type: 'one', request_id: anything)) {}
|
235
|
+
expect(service).to receive(:call).with(input.merge(type: 'two', request_id: anything)) { raise exception }
|
256
236
|
end
|
257
237
|
|
258
238
|
it_behaves_like 'an error_handler'
|
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: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Indrek Juhkam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: airbrake
|
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
118
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.
|
119
|
+
rubygems_version: 2.2.2
|
120
120
|
signing_key:
|
121
121
|
specification_version: 4
|
122
122
|
summary: ''
|