process_handler 2.0.0 → 2.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: 503d8ce446eeb4caa121a37d828f72c7662ac37d
4
- data.tar.gz: fb470e66c0e819f29ccc74238ece33fe8cb4ea00
3
+ metadata.gz: 98fd113311c50811df459fd962cd08d07a1370ba
4
+ data.tar.gz: f1dc5496c0752acccb0edf3860cd4bfe0492b7f9
5
5
  SHA512:
6
- metadata.gz: e509844d303791e07770096198abb40a9dae45c9de590b96ca38b96c3d896d03b52e0d426bba7ea4d3b3b542363bd91f8880d881c1272a8e22f2177d98161590
7
- data.tar.gz: 7154af8b659b52b3aca64c12011dc92d7599115bcebadd769eb1fd79f9e1a9b96fc14d1014b410a30be3efb29d510950201c3b8525a45d62c133272069389bb7
6
+ metadata.gz: 6b063ea89548353200881c51d71f65eccb5255e5e325f9d03f7920b2a7ae842f6963c40b26c7d0fcd6e6dce598f81514ba3dbab5fc6a9ca047cde23ab219993d
7
+ data.tar.gz: 25dd37e89cd5656b7dc6988d519c8f933ecd6a3add4389da80051eb8aa7790cb32de6b0ac0681231ddee6e1ed8cf7b06bb86348c4a0c623ec1b758a7dd2fef8a
@@ -33,6 +33,7 @@ module Salemove
33
33
  notifier_factory: NotifierFactory,
34
34
  process_monitor: ProcessMonitor.new,
35
35
  process_name: 'Unknown process',
36
+ log_error_as_string: false,
36
37
  execution_time_key: DEFAULT_EXECUTION_TIME_KEY,
37
38
  exit_enforcer: nil)
38
39
  @freddy = freddy
@@ -46,6 +47,7 @@ module Salemove
46
47
  @exception_notifier = notifier_factory.get_notifier(process_name, notifier)
47
48
  # Needed for forcing exit from jruby with exit(0)
48
49
  @exit_enforcer = exit_enforcer || Proc.new {}
50
+ @log_error_as_string = log_error_as_string
49
51
  end
50
52
 
51
53
  def spawn(service, blocking: true)
@@ -63,7 +65,8 @@ module Salemove
63
65
  freddy: @freddy,
64
66
  logger: @logger,
65
67
  benchmarker: @benchmarker,
66
- exception_notifier: @exception_notifier
68
+ exception_notifier: @exception_notifier,
69
+ log_error_as_string: @log_error_as_string
67
70
  ).spawn
68
71
  ]
69
72
  else
@@ -131,12 +134,13 @@ module Salemove
131
134
  class ServiceSpawner
132
135
  PROCESSED_REQUEST_LOG_KEYS = [:error, :success]
133
136
 
134
- def initialize(service, freddy:, logger:, benchmarker:, exception_notifier:)
137
+ def initialize(service, freddy:, logger:, benchmarker:, exception_notifier:, log_error_as_string:)
135
138
  @service = service
136
139
  @freddy = freddy
137
140
  @logger = logger
138
141
  @benchmarker = benchmarker
139
142
  @exception_notifier = exception_notifier
143
+ @log_error_as_string = log_error_as_string
140
144
  end
141
145
 
142
146
  def spawn
@@ -200,6 +204,9 @@ module Salemove
200
204
  .merge(type: input[:type])
201
205
  .merge(PivotProcess.trace_information)
202
206
 
207
+ if @log_error_as_string
208
+ attributes[:error] = attributes[:error].to_s if attributes.has_key?(:error)
209
+ end
203
210
  @logger.info 'Processed request', attributes
204
211
  end
205
212
 
@@ -1,5 +1,5 @@
1
1
  module Salemove
2
2
  module ProcessHandler
3
- VERSION = '2.0.0'
3
+ VERSION = '2.1.0'
4
4
  end
5
5
  end
@@ -12,6 +12,7 @@ describe ProcessHandler::PivotProcess do
12
12
  let(:responder) { double(shutdown: true) }
13
13
  let(:logger) { Logasm.build('test-app', []) }
14
14
  let(:application) { 'my-app' }
15
+ let(:log_error_as_string) { false }
15
16
 
16
17
  let(:process) do
17
18
  ProcessHandler::PivotProcess.new(
@@ -20,7 +21,8 @@ describe ProcessHandler::PivotProcess do
20
21
  statsd: statsd,
21
22
  process_monitor: monitor,
22
23
  process_name: application,
23
- notifier_factory: notifier_factory
24
+ notifier_factory: notifier_factory,
25
+ log_error_as_string: log_error_as_string
24
26
  )
25
27
  end
26
28
 
@@ -96,6 +98,38 @@ describe ProcessHandler::PivotProcess do
96
98
  end
97
99
  end
98
100
 
101
+ describe 'when service responds with an error object' do
102
+ let(:result) { { success: false, error: {error: 'hey', message: 'message' } } }
103
+
104
+ before do
105
+ expect(service).to receive(:call).with(input) { result }
106
+ end
107
+
108
+ it 'logs the message as an object' do
109
+ expect(logger).to receive(:info).with("Received request", {})
110
+ expect(logger).to receive(:info)
111
+ .with(
112
+ "Processed request",
113
+ { success: false, error: {error: 'hey', message: 'message'}, type: nil }
114
+ )
115
+ subject()
116
+ end
117
+
118
+ describe 'when log_error_as_string' do
119
+ let(:log_error_as_string) { true }
120
+
121
+ it 'logs the message as string' do
122
+ expect(logger).to receive(:info).with("Received request", {})
123
+ expect(logger).to receive(:info)
124
+ .with(
125
+ "Processed request",
126
+ { success: false, error: "{:error=>\"hey\", :message=>\"message\"}", type: nil }
127
+ )
128
+ subject()
129
+ end
130
+ end
131
+ end
132
+
99
133
  shared_examples 'an error_handler' do
100
134
 
101
135
  it 'logs error' 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.0.0
4
+ version: 2.1.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-02-26 00:00:00.000000000 Z
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: airbrake