action_subscriber 4.4.0 → 4.5.0.pre0

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: 46659405baa83f5d13af35a5c014ff900baf3cfb
4
- data.tar.gz: c765ee1c9d142ead34a174ea520e6eb612bec05d
3
+ metadata.gz: 4ff445afc60cb441e3af5c2e9e65f13826fa02d8
4
+ data.tar.gz: 5346ff383fa7ebd1b0047cd9d5392e30ce492d4d
5
5
  SHA512:
6
- metadata.gz: f7a3f0bd6b3225076fe4e0336596dfbf746b1a8b0896ab9f040cb0d6eda368e3d0008ad4c5e8cc7573823042351f468dfa83f611aae95d727e2f5caa4e053c65
7
- data.tar.gz: ccc68611930161add63d253d2efd5460b8da17672247f24a7f6ccea9e1a7617e225e7d8ec8f897a77e1d839fa01a7ccfce6560e74b9d57e49b66927e56d31fb6
6
+ metadata.gz: 52b19ec1002942aa27c185aee22ec1a13d8e9ec1db7648db4c04621e8d3a8baa6aa66d82c7dcf6dcb6d1d5843f23e48ffe4d80c318004b256216c5695ef9861b
7
+ data.tar.gz: 13b671f299f909e1f05b8e81dc26c9f8be8957d511ab79d6fed98d5c3ba2b77c6b5337356d98d1e4af600dc6bf9be7ff661fc29e5cb1ee15ba6530f7c543758a
@@ -85,7 +85,13 @@ module ActionSubscriber
85
85
  'text/plain' => lambda { |payload| payload.dup }
86
86
  }
87
87
 
88
- self.error_handler = lambda { |error, env_hash| raise }
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
- job_mutex = ::Mutex.new
12
- job_complete = ::ConditionVariable.new
11
+ @app.call(env)
12
+ rescue => error
13
+ logger.error "FAILED #{env.message_id}"
13
14
 
14
- job_mutex.synchronize do
15
- ::Thread.new do
16
- job_mutex.synchronize do
17
- begin
18
- @app.call(env)
19
- rescue => error
20
- logger.error "FAILED #{env.message_id}"
21
- ::ActionSubscriber.configuration.error_handler.call(error, env.to_h)
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
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "4.4.0"
2
+ VERSION = "4.5.0.pre0"
3
3
  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.0
4
+ version: 4.5.0.pre0
5
5
  platform: ruby
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-07-28 00:00:00.000000000 Z
15
+ date: 2017-08-09 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
@@ -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: '0'
282
+ version: 1.3.1
283
283
  requirements: []
284
284
  rubyforge_project:
285
285
  rubygems_version: 2.5.2