action_subscriber 4.4.0.pre2-java → 4.5.0-java
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 +4 -4
- data/lib/action_subscriber/configuration.rb +7 -1
- data/lib/action_subscriber/middleware/error_handler.rb +11 -18
- data/lib/action_subscriber/version.rb +1 -1
- data/spec/lib/action_subscriber/configuration_spec.rb +17 -0
- data/spec/lib/action_subscriber/middleware/error_handler_spec.rb +0 -15
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e5ccb8aef3395279c11bfafe6dcac47c88d653981dee2935b67234918978327
|
4
|
+
data.tar.gz: 3111f0950b69c540cf101c6d9ed9ded217d2d1f8c1d7fe808fbaf1ec5f106b2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d497d0bc6eeeffc3b5f06c159ae782a3767cf351f1e7542f79f98c04d4226230edcedfa25b668b3f3826a886b1ba707ba36050fa2cf6629e98f41da6a290c16
|
7
|
+
data.tar.gz: 3dac444e91c7bfb63aa77b5cff0c94c6ba1244d2e5669d6d7b4b1c5f974343087cc44f823cc4329738de16fc724f308a77cd751018b1838763435e655067a767
|
@@ -85,7 +85,13 @@ module ActionSubscriber
|
|
85
85
|
'text/plain' => lambda { |payload| payload.dup }
|
86
86
|
}
|
87
87
|
|
88
|
-
self.error_handler = lambda
|
88
|
+
self.error_handler = lambda do |error, env_hash|
|
89
|
+
logger = ::ActionSubscriber::Logging.logger
|
90
|
+
|
91
|
+
logger.error(error.message)
|
92
|
+
logger.error(error.class.to_s)
|
93
|
+
logger.error(error.backtrace.join("\n")) if error.try(:backtrace) && error.backtrace.is_a?(::Array)
|
94
|
+
end
|
89
95
|
|
90
96
|
DEFAULTS.each_pair do |key, value|
|
91
97
|
self.__send__("#{key}=", value)
|
@@ -8,25 +8,18 @@ module ActionSubscriber
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
11
|
-
|
12
|
-
|
11
|
+
@app.call(env)
|
12
|
+
rescue => error
|
13
|
+
logger.error "FAILED #{env.message_id}"
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
ensure
|
23
|
-
job_complete.signal
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# TODO we might want to pass a timeout to this wait so we can handle jobs that get frozen
|
29
|
-
job_complete.wait(job_mutex)
|
15
|
+
# There is more to this rescue than meets the eye. MarchHare's java library will rescue errors
|
16
|
+
# and attempt to close the channel with its default exception handler. To avoid this, we will
|
17
|
+
# stop errors right here. If you want to handle errors, you must do it in the error handler and
|
18
|
+
# it should not re-raise. As a bonus, not killing these threads is better for your runtime :).
|
19
|
+
begin
|
20
|
+
::ActionSubscriber.configuration.error_handler.call(error, env.to_h)
|
21
|
+
rescue => error
|
22
|
+
logger.error "ActionSubscriber error handler raised error, but should never raise. Error: #{error}"
|
30
23
|
end
|
31
24
|
end
|
32
25
|
end
|
@@ -43,4 +43,21 @@ describe ::ActionSubscriber::Configuration do
|
|
43
43
|
expect(subject.virtual_host).to eq("vhost")
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
describe "error_handler" do
|
48
|
+
let(:logger) { ::ActionSubscriber::Logging.logger }
|
49
|
+
|
50
|
+
it "by default logs the error" do
|
51
|
+
expect(logger).to receive(:error).with("I'm confused")
|
52
|
+
expect(logger).to receive(:error).with("ArgumentError")
|
53
|
+
# Lame way of looking for the backtrace.
|
54
|
+
expect(logger).to receive(:error).with(/\.rb/)
|
55
|
+
|
56
|
+
begin
|
57
|
+
fail ::ArgumentError, "I'm confused"
|
58
|
+
rescue => error
|
59
|
+
subject.error_handler.call(error, {})
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
46
63
|
end
|
@@ -19,19 +19,4 @@ describe ActionSubscriber::Middleware::ErrorHandler do
|
|
19
19
|
subject.call(env)
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
23
|
-
context "many concurrent threads" do
|
24
|
-
it "handles the race conditions without raising exceptions" do
|
25
|
-
no_op = lambda{ nil }
|
26
|
-
threads = 1.upto(100).map do
|
27
|
-
::Thread.new do
|
28
|
-
::Thread.current.abort_on_exception = true
|
29
|
-
100.times do
|
30
|
-
described_class.new(no_op).call(env)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
threads.each(&:join)
|
35
|
-
end
|
36
|
-
end
|
37
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_subscriber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.5.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Brian Stien
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2017-
|
15
|
+
date: 2017-08-15 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
@@ -277,9 +277,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
277
277
|
version: '0'
|
278
278
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
279
279
|
requirements:
|
280
|
-
- - "
|
280
|
+
- - ">="
|
281
281
|
- !ruby/object:Gem::Version
|
282
|
-
version:
|
282
|
+
version: '0'
|
283
283
|
requirements: []
|
284
284
|
rubyforge_project:
|
285
285
|
rubygems_version: 2.6.11
|