action_subscriber 4.1.1-java → 4.2.1-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/action_subscriber.gemspec +1 -0
- data/lib/action_subscriber/configuration.rb +4 -0
- data/lib/action_subscriber/middleware/active_record/connection_management.rb +39 -3
- data/lib/action_subscriber/middleware/active_record/query_cache.rb +11 -9
- data/lib/action_subscriber/version.rb +1 -1
- data/spec/lib/action_subscriber/middleware/active_record/connection_management_spec.rb +2 -2
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b80aa9c8134cec3a2430e975fde77a0764035c2d
|
4
|
+
data.tar.gz: 8767dad46211dd3b90d29c40e8a01ecb7e6e2491
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cabe30d24cc2d4f28f3213f09710b4b60bc84064d328bb64c19b15963d41cf445f0c2022c3e362e2272f3a2e610a0588fa2b4cd83596afae07246d5d96956d68
|
7
|
+
data.tar.gz: 7187ba4237d77c7e04421211348a65cca19edae2eb740c6c04eabd41efa707e225207a0df624a3e5b583f6e61bce6c470db546a5897ab3f4d5578ac75ad100fa
|
data/action_subscriber.gemspec
CHANGED
@@ -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
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
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(
|
18
|
+
restore_query_cache_settings(enabled)
|
17
19
|
end
|
18
20
|
|
19
|
-
|
21
|
+
private
|
20
22
|
|
21
|
-
def restore_query_cache_settings(
|
22
|
-
::
|
23
|
-
::
|
24
|
-
::
|
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
|
@@ -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 "
|
13
|
-
expect(ActiveRecord::
|
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.
|
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-
|
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:
|