action_subscriber 4.1.1-java → 4.2.1-java

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: 1e29f39ca4de3db34bdeac3a4e2f73eb6165995b
4
- data.tar.gz: e63de147b4f3e6104e92a9be894ae0d31f8a839f
3
+ metadata.gz: b80aa9c8134cec3a2430e975fde77a0764035c2d
4
+ data.tar.gz: 8767dad46211dd3b90d29c40e8a01ecb7e6e2491
5
5
  SHA512:
6
- metadata.gz: 482d9c48efb799c8db3a33cc6b36cc9fab2a04b569df918b0047a4a2ac151716af37e4da615922e3eea5808f3f563fbba87529628f70bb9e22961975bfeaec17
7
- data.tar.gz: 90fd322dd4b232af7f9e63035944a12d38beca4c1e27e3231cd17faa78fa4456710db672107e28a6dbd71fcbdfc16301e4c4afbab396fb85cfbb6957a648fbb3
6
+ metadata.gz: cabe30d24cc2d4f28f3213f09710b4b60bc84064d328bb64c19b15963d41cf445f0c2022c3e362e2272f3a2e610a0588fa2b4cd83596afae07246d5d96956d68
7
+ data.tar.gz: 7187ba4237d77c7e04421211348a65cca19edae2eb740c6c04eabd41efa707e225207a0df624a3e5b583f6e61bce6c470db546a5897ab3f4d5578ac75ad100fa
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  else
27
27
  spec.add_dependency 'bunny', '>= 1.5.0'
28
28
  end
29
+ spec.add_dependency 'concurrent-ruby'
29
30
  spec.add_dependency 'middleware'
30
31
  spec.add_dependency 'thor'
31
32
 
@@ -4,6 +4,8 @@ require "action_subscriber/uri"
4
4
  module ActionSubscriber
5
5
  class Configuration
6
6
  attr_accessor :allow_low_priority_methods,
7
+ :connection_reaping_interval,
8
+ :connection_reaping_timeout_interval,
7
9
  :decoder,
8
10
  :default_exchange,
9
11
  :error_handler,
@@ -28,6 +30,8 @@ module ActionSubscriber
28
30
 
29
31
  DEFAULTS = {
30
32
  :allow_low_priority_methods => false,
33
+ :connection_reaping_interval => 6,
34
+ :connection_reaping_timeout_interval => 5,
31
35
  :default_exchange => 'events',
32
36
  :heartbeat => 5,
33
37
  :host => 'localhost',
@@ -1,16 +1,52 @@
1
+ require "concurrent"
2
+ require "thread"
3
+
1
4
  module ActionSubscriber
2
5
  module Middleware
3
6
  module ActiveRecord
4
7
  class ConnectionManagement
8
+ START_MUTEX = ::Mutex.new
9
+
10
+ def self.start_timed_task!
11
+ if timed_task_started.false?
12
+ START_MUTEX.synchronize do
13
+ return if timed_task_started.true?
14
+
15
+ timed_task = ::Concurrent::TimerTask.new(
16
+ :execution_interval => ::ActionSubscriber.config.connection_reaping_interval,
17
+ :timeout_interval => ::ActionSubscriber.config.connection_reaping_timeout_interval) do
18
+
19
+ ::ActiveRecord::Base.clear_active_connections!
20
+ end
21
+
22
+ timed_task.execute
23
+ timed_task_started.make_true
24
+ end
25
+ end
26
+ end
27
+
28
+ def self.timed_task_started
29
+ if @timed_task_started.nil?
30
+ @timed_task_started = ::Concurrent::AtomicBoolean.new(false)
31
+ end
32
+
33
+ @timed_task_started
34
+ end
35
+
5
36
  def initialize(app)
6
37
  @app = app
7
38
  end
8
39
 
9
40
  def call(env)
10
- @app.call(env)
11
- ensure
12
- ::ActiveRecord::Base.clear_active_connections!
41
+ def call(env)
42
+ @app.call(env)
43
+ end
44
+
45
+ self.class.start_timed_task!
46
+ call(env)
13
47
  end
48
+
49
+ timed_task_started
14
50
  end
15
51
  end
16
52
  end
@@ -2,26 +2,28 @@ module ActionSubscriber
2
2
  module Middleware
3
3
  module ActiveRecord
4
4
  class QueryCache
5
+ CURRENT_CONNECTION = "_action_subscriber_query_cache_current_connection".freeze
6
+
5
7
  def initialize(app)
6
8
  @app = app
7
9
  end
8
10
 
9
11
  def call(env)
10
- enabled = ::ActiveRecord::Base.connection.query_cache_enabled
11
- connection_id = ::ActiveRecord::Base.connection_id
12
- ::ActiveRecord::Base.connection.enable_query_cache!
12
+ connection = ::Thread.current[CURRENT_CONNECTION] = ::ActiveRecord::Base.connection
13
+ enabled = connection.query_cache_enabled
14
+ connection.enable_query_cache!
13
15
 
14
16
  @app.call(env)
15
17
  ensure
16
- restore_query_cache_settings(connection_id, enabled)
18
+ restore_query_cache_settings(enabled)
17
19
  end
18
20
 
19
- private
21
+ private
20
22
 
21
- def restore_query_cache_settings(connection_id, enabled)
22
- ::ActiveRecord::Base.connection_id = connection_id
23
- ::ActiveRecord::Base.connection.clear_query_cache
24
- ::ActiveRecord::Base.connection.disable_query_cache! unless enabled
23
+ def restore_query_cache_settings(enabled)
24
+ ::Thread.current[CURRENT_CONNECTION].clear_query_cache
25
+ ::Thread.current[CURRENT_CONNECTION].disable_query_cache! unless enabled
26
+ ::Thread.current[CURRENT_CONNECTION] = nil
25
27
  end
26
28
  end
27
29
  end
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "4.1.1"
2
+ VERSION = "4.2.1"
3
3
  end
@@ -9,8 +9,8 @@ describe ActionSubscriber::Middleware::ActiveRecord::ConnectionManagement do
9
9
 
10
10
  it_behaves_like 'an action subscriber middleware'
11
11
 
12
- it "clears active connections" do
13
- expect(ActiveRecord::Base).to receive(:clear_active_connections!)
12
+ it "starts async task to clear connections" do
13
+ expect(ActionSubscriber::Middleware::ActiveRecord::ConnectionManagement).to receive(:start_timed_task!)
14
14
  subject.call(env)
15
15
  end
16
16
  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.1.1
4
+ version: 4.2.1
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-02-03 00:00:00.000000000 Z
15
+ date: 2017-03-11 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  requirement: !ruby/object:Gem::Requirement
@@ -42,6 +42,20 @@ dependencies:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
44
  version: 2.7.0
45
+ - !ruby/object:Gem::Dependency
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ name: concurrent-ruby
52
+ prerelease: false
53
+ type: :runtime
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
45
59
  - !ruby/object:Gem::Dependency
46
60
  requirement: !ruby/object:Gem::Requirement
47
61
  requirements: