process_handler 1.0.0 → 1.1.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: a4a0b0712332a3351be93705ac3d10cb25aac695
4
- data.tar.gz: 04ef8921eeafe7704d6239252f81f6cf992cc723
3
+ metadata.gz: ec9bd732b3d29be5ca5a8ff8b9376be37edf5ea5
4
+ data.tar.gz: f37c3dc1f7f4b3b82bf029a274e7154bbdc268f5
5
5
  SHA512:
6
- metadata.gz: 5eedc6fa3ecc33d660884c3db2260b06e78ea20c61bf3305f20cb412c7c426d55e9834ddf8ba822076e77715cfb93ed9357e4d390dd79ab2ae464c6eee0832de
7
- data.tar.gz: efbe06f03d975f036c7a80f8beb3af369cd1f0a273b5c3a00e3cc8da208cba7995933b69d56fab224a122a13f84dd137892dded74f2205c24da57c1ccfd8a09c
6
+ metadata.gz: cb2d95bee09bba68cb7c50a03aba26444098dc13db709077facd48cd10120a006c19822c961b3bc4782a297f98360a514c16a4d9fd07c013fd13a7aef88bb90e
7
+ data.tar.gz: 0ca27cf5ea6d3d574095ee36d38acb3a6dab71b018cabec691e9060ff8f4d0538e05778ec96375cc94d70a58b76f5973bdcf88feededac08ea404a23a1d231bd
@@ -20,13 +20,21 @@ module Salemove
20
20
  @logger = logger
21
21
  end
22
22
 
23
- def initialize(messenger,
23
+ def self.trace_information
24
+ if defined?(Freddy) && Freddy.respond_to?(:trace)
25
+ {trace: Freddy.trace.to_h}
26
+ else
27
+ {}
28
+ end
29
+ end
30
+
31
+ def initialize(freddy,
24
32
  notifier: nil,
25
33
  notifier_factory: NotifierFactory,
26
34
  process_monitor: ProcessMonitor.new,
27
35
  process_name: 'Unknown process',
28
36
  exit_enforcer: nil)
29
- @messenger = messenger
37
+ @freddy = freddy
30
38
  @process_monitor = process_monitor
31
39
  @exception_notifier = notifier_factory.get_notifier(process_name, notifier)
32
40
  # Needed for forcing exit from jruby with exit(0)
@@ -42,7 +50,7 @@ module Salemove
42
50
 
43
51
  def spawn_queue_threads(service)
44
52
  if service.class.const_defined?(:QUEUE)
45
- [ServiceSpawner.spawn(service, @messenger, @exception_notifier)]
53
+ [ServiceSpawner.spawn(service, @freddy, @exception_notifier)]
46
54
  else
47
55
  []
48
56
  end
@@ -51,7 +59,7 @@ module Salemove
51
59
  def spawn_tap_threads(service)
52
60
  if service.class.const_defined?(:TAPPED_QUEUES)
53
61
  service.class::TAPPED_QUEUES.map do |queue|
54
- spawner = TapServiceSpawner.new(service, @messenger, @exception_notifier)
62
+ spawner = TapServiceSpawner.new(service, @freddy, @exception_notifier)
55
63
  spawner.spawn(queue)
56
64
  end
57
65
  else
@@ -67,9 +75,9 @@ module Salemove
67
75
 
68
76
  bm = Benchmark.measure { result = block.call }
69
77
  if defined?(Logasm) && PivotProcess.logger.is_a?(Logasm)
70
- PivotProcess.logger.info "Execution time",
71
- request_id: input[:request_id], type: type,
72
- real: bm.real, user: bm.utime, system: bm.stime
78
+ PivotProcess.logger.info "Execution time", {
79
+ type: type, real: bm.real, user: bm.utime, system: bm.stime
80
+ }.merge(PivotProcess.trace_information)
73
81
  end
74
82
  result
75
83
  end
@@ -82,28 +90,27 @@ module Salemove
82
90
  end
83
91
 
84
92
  class TapServiceSpawner
85
- def initialize(service, messenger, exception_notifier)
93
+ def initialize(service, freddy, exception_notifier)
86
94
  @service = service
87
- @messenger = messenger
95
+ @freddy = freddy
88
96
  @exception_notifier = exception_notifier
89
97
  end
90
98
 
91
99
  def spawn(queue)
92
- @messenger.tap_into(queue) do |input|
93
- request_id = SecureRandom.hex(5)
94
- delegate_to_service(input.merge(type: queue, request_id: request_id))
100
+ @freddy.tap_into(queue) do |input|
101
+ delegate_to_service(input.merge(type: queue))
95
102
  end
96
103
  end
97
104
 
98
105
  def delegate_to_service(input)
99
- PivotProcess.logger.info "Received request", input
106
+ PivotProcess.logger.info "Received request", PivotProcess.trace_information.merge(input)
100
107
  PivotProcess.benchmark(input) { @service.call(input) }
101
108
  rescue => exception
102
109
  handle_exception(exception, input)
103
110
  end
104
111
 
105
112
  def handle_exception(e, input)
106
- PivotProcess.logger.error(e.inspect + "\n" + e.backtrace.join("\n"), request_id: input[:request_id])
113
+ PivotProcess.logger.error(e.inspect + "\n" + e.backtrace.join("\n"), PivotProcess.trace_information)
107
114
  if @exception_notifier
108
115
  @exception_notifier.notify_or_ignore(e, cgi_data: ENV.to_hash, parameters: input)
109
116
  end
@@ -113,21 +120,19 @@ module Salemove
113
120
  class ServiceSpawner
114
121
  PROCESSED_REQUEST_LOG_KEYS = [:error, :success]
115
122
 
116
- def self.spawn(service, messenger, exception_notifier)
117
- new(service, messenger, exception_notifier).spawn
123
+ def self.spawn(service, freddy, exception_notifier)
124
+ new(service, freddy, exception_notifier).spawn
118
125
  end
119
126
 
120
- def initialize(service, messenger, exception_notifier)
127
+ def initialize(service, freddy, exception_notifier)
121
128
  @service = service
122
- @messenger = messenger
129
+ @freddy = freddy
123
130
  @exception_notifier = exception_notifier
124
131
  end
125
132
 
126
133
  def spawn
127
- @messenger.respond_to(@service.class::QUEUE) do |input, handler|
128
- request_id = SecureRandom.hex(5)
129
-
130
- response = handle_request(input.merge(request_id: request_id))
134
+ @freddy.respond_to(@service.class::QUEUE) do |input, handler|
135
+ response = handle_request(input)
131
136
  if response.respond_to?(:fulfilled?)
132
137
  handle_fulfillable_response(input, handler, response)
133
138
  else
@@ -161,7 +166,7 @@ module Salemove
161
166
  end
162
167
 
163
168
  def handle_request(input)
164
- PivotProcess.logger.debug "Received request", input
169
+ PivotProcess.logger.debug "Received request", PivotProcess.trace_information.merge(input)
165
170
  if input.has_key?(:ping)
166
171
  { success: true, pong: 'pong' }
167
172
  else
@@ -183,13 +188,14 @@ module Salemove
183
188
  def log_processed_request(input, result)
184
189
  attributes = result
185
190
  .select {|k, _| PROCESSED_REQUEST_LOG_KEYS.include?(k)}
186
- .merge(request_id: input[:request_id], type: input[:type])
191
+ .merge(type: input[:type])
192
+ .merge(PivotProcess.trace_information)
187
193
 
188
194
  PivotProcess.logger.info "Processed request", attributes
189
195
  end
190
196
 
191
197
  def handle_exception(e, input)
192
- PivotProcess.logger.error(e.inspect + "\n" + e.backtrace.join("\n"), request_id: input[:request_id])
198
+ PivotProcess.logger.error(e.inspect + "\n" + e.backtrace.join("\n"), PivotProcess.trace_information)
193
199
  if @exception_notifier
194
200
  @exception_notifier.notify_or_ignore(e, cgi_data: ENV.to_hash, parameters: input)
195
201
  end
@@ -1,5 +1,5 @@
1
1
  module Salemove
2
2
  module ProcessHandler
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
@@ -6,8 +6,8 @@ require 'salemove/process_handler/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'process_handler'
8
8
  spec.version = Salemove::ProcessHandler::VERSION
9
- spec.authors = ['Indrek Juhkam']
10
- spec.email = ['indrek@salemove.com']
9
+ spec.authors = ['SaleMove TechMovers']
10
+ spec.email = ['techmovers@salemove.com']
11
11
  spec.description = %q{This gem helps to monitor and manage processes}
12
12
  spec.summary = %q{}
13
13
  spec.homepage = ''
@@ -3,11 +3,11 @@ require 'spec_helper'
3
3
  require 'salemove/process_handler/pivot_process'
4
4
 
5
5
  describe ProcessHandler::PivotProcess do
6
- let(:monitor) { double('Monitor') }
7
- let(:messenger) { double('Messenger') }
8
- let(:handler) { double('Handler') }
9
- let(:thread) { double('Thread') }
10
- let(:process) { ProcessHandler::PivotProcess.new(messenger, process_params) }
6
+ let(:monitor) { double('Monitor') }
7
+ let(:freddy) { double('Freddy') }
8
+ let(:handler) { double('Handler') }
9
+ let(:thread) { double('Thread') }
10
+ let(:process) { ProcessHandler::PivotProcess.new(freddy, process_params) }
11
11
  let(:process_params) {{ process_monitor: monitor , notifier_factory: notifier_factory}}
12
12
  let(:notifier_factory) { double('NotifierFactory') }
13
13
  let(:responder) { double(shutdown: true) }
@@ -43,7 +43,7 @@ describe ProcessHandler::PivotProcess do
43
43
  end
44
44
 
45
45
  def expect_message
46
- expect(messenger).to receive(:respond_to) {|destination, &callback|
46
+ expect(freddy).to receive(:respond_to) {|destination, &callback|
47
47
  callback.call(input, handler)
48
48
  }.and_return(responder)
49
49
  end
@@ -51,14 +51,14 @@ describe ProcessHandler::PivotProcess do
51
51
  before do
52
52
  expect_message
53
53
  expect_handler_thread_to_behave
54
- allow(service).to receive(:call).with(input.merge(request_id: anything)) { result }
54
+ allow(service).to receive(:call).with(input) { result }
55
55
  end
56
56
 
57
57
  describe 'when service responds correctly' do
58
58
 
59
59
  it 'can be executed with logger' do
60
60
  expect(handler).to receive(:success).with(result)
61
- expect(service).to receive(:call).with(input.merge(request_id: anything))
61
+ expect(service).to receive(:call).with(input)
62
62
  subject()
63
63
  end
64
64
 
@@ -68,7 +68,7 @@ describe ProcessHandler::PivotProcess do
68
68
  let(:result) { { success: false, error: 'hey' } }
69
69
 
70
70
  before do
71
- expect(service).to receive(:call).with(input.merge(request_id: anything)) { result }
71
+ expect(service).to receive(:call).with(input) { result }
72
72
  end
73
73
 
74
74
  it 'acks the message properly' do
@@ -106,7 +106,7 @@ describe ProcessHandler::PivotProcess do
106
106
  let(:exception) { "what an unexpected exception!" }
107
107
 
108
108
  before do
109
- expect(service).to receive(:call).with(input.merge(request_id: anything)) { raise exception }
109
+ expect(service).to receive(:call).with(input) { raise exception }
110
110
  end
111
111
 
112
112
  it 'acks the message properly' do
@@ -190,7 +190,7 @@ describe ProcessHandler::PivotProcess do
190
190
  let(:input) {{}}
191
191
 
192
192
  def expect_tap_into
193
- expect(messenger).to receive(:tap_into) do |destination, &callback|
193
+ expect(freddy).to receive(:tap_into) do |destination, &callback|
194
194
  callback.call(input)
195
195
  end
196
196
  .exactly(tap_count).times
@@ -205,8 +205,8 @@ describe ProcessHandler::PivotProcess do
205
205
 
206
206
  describe 'when service handles the input correctly' do
207
207
  it 'can be executed' do
208
- expect(service).to receive(:call).with(input.merge(type: 'one', request_id: anything))
209
- expect(service).to receive(:call).with(input.merge(type: 'two', request_id: anything))
208
+ expect(service).to receive(:call).with(input.merge(type: 'one'))
209
+ expect(service).to receive(:call).with(input.merge(type: 'two'))
210
210
  subject()
211
211
  end
212
212
  end
@@ -237,8 +237,8 @@ describe ProcessHandler::PivotProcess do
237
237
  let(:exception) { "what an unexpected exception!" }
238
238
 
239
239
  before do
240
- expect(service).to receive(:call).with(input.merge(type: 'one', request_id: anything)) {}
241
- expect(service).to receive(:call).with(input.merge(type: 'two', request_id: anything)) { raise exception }
240
+ expect(service).to receive(:call).with(input.merge(type: 'one')) {}
241
+ expect(service).to receive(:call).with(input.merge(type: 'two')) { raise exception }
242
242
  end
243
243
 
244
244
  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: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Indrek Juhkam
7
+ - SaleMove TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-23 00:00:00.000000000 Z
11
+ date: 2017-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: airbrake
@@ -68,7 +68,7 @@ dependencies:
68
68
  version: '0'
69
69
  description: This gem helps to monitor and manage processes
70
70
  email:
71
- - indrek@salemove.com
71
+ - techmovers@salemove.com
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []