saseo 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/saseo/extensions/active_record/adapter_mixin.rb +55 -0
- data/lib/saseo/extensions/active_record.rb +6 -7
- data/lib/saseo/publishing/publisher.rb +2 -43
- data/lib/saseo/version.rb +1 -1
- metadata +3 -7
- data/lib/saseo/extensions/active_record/patcher.rb +0 -32
- data/lib/saseo/extensions/active_record/v_3/connection_adapters/postgresql_adapter.rb +0 -26
- data/lib/saseo/extensions/active_record/v_3.rb +0 -11
- data/lib/saseo/extensions/active_record/v_4/connection_adapters/postgresql/database_statements.rb +0 -29
- data/lib/saseo/extensions/active_record/v_4.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 870d97ea47c29c3c88bc485148418518159c1223
|
4
|
+
data.tar.gz: b53a277d7db97fec52f4844d298af35bc3b01abf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbdef412fd9e9b1d0a539178016a6687efd44293e560fb05fb12955819ffa36e25d91e97617491b382649aa3d05a3b448276f525b4f8e08764200198b3ae1f2f
|
7
|
+
data.tar.gz: 83ee5c66b3a9d72cf594072999efc04de69ebc5434b04a3dcaefac23ecdadc8f844c4098d9f156f0c3c1d0e6621f6db920fc957fa845a19b2f0582755c52ff8f
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'active_record/base'
|
2
|
+
|
3
|
+
module Saseo
|
4
|
+
module Extensions
|
5
|
+
module ActiveRecord
|
6
|
+
module AdapterMixin
|
7
|
+
extend self
|
8
|
+
|
9
|
+
def begin_db_transaction
|
10
|
+
execute 'BEGIN'
|
11
|
+
Saseo::Whodunnit.set_db_whodunnit
|
12
|
+
end
|
13
|
+
|
14
|
+
def notify(channel, payload)
|
15
|
+
conn = instance_variable_get(:@connection)
|
16
|
+
conn.async_exec "SELECT pg_notify('#{channel}', '#{payload.to_s}')"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Heavily cribbed from Sequel:
|
20
|
+
# https://github.com/jeremyevans/sequel/blob/c6678741ce34aac52cff966ff6a6288ccb8d5b75/lib/sequel/adapters/postgres.rb#L440
|
21
|
+
def listen(channels:, after_listen: nil, timeout: nil, loop: false, &block)
|
22
|
+
if loop && !block
|
23
|
+
raise ArgumentError, 'calling #listen with :loop requires a block'
|
24
|
+
end
|
25
|
+
channels = Array(channels)
|
26
|
+
|
27
|
+
timeout_block = timeout.respond_to?(:call) ? timeout : proc { timeout }
|
28
|
+
loop_callable = loop.respond_to?(:call)
|
29
|
+
begin
|
30
|
+
conn = instance_variable_get(:@connection)
|
31
|
+
channels.each do |channel|
|
32
|
+
conn.async_exec "LISTEN \"#{channel}\""
|
33
|
+
::ActiveRecord::Base.logger.try(:debug) { "listening to #{channel}..." }
|
34
|
+
|
35
|
+
end
|
36
|
+
after_listen.call(conn) if after_listen
|
37
|
+
|
38
|
+
if loop
|
39
|
+
catch(:stop) do
|
40
|
+
loop do
|
41
|
+
conn.wait_for_notify(timeout_block.call, &block)
|
42
|
+
loop.call(conn) if loop_callable
|
43
|
+
end
|
44
|
+
end
|
45
|
+
else
|
46
|
+
conn.wait_for_notify(timeout_block.call, &block)
|
47
|
+
end
|
48
|
+
ensure
|
49
|
+
conn.async_exec 'UNLISTEN *'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'saseo/extensions/active_record/detector'
|
2
|
-
require 'saseo/extensions/active_record/patcher'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
3
|
+
if Saseo::Extensions::ActiveRecord::Detector.active_record_detected? && Saseo::Extensions::ActiveRecord::Detector.active_record_version >= 3
|
4
|
+
require 'active_record/connection_adapters/postgresql_adapter'
|
5
|
+
require 'saseo/extensions/active_record/adapter_mixin'
|
6
|
+
|
7
|
+
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend ::Saseo::Extensions::ActiveRecord::AdapterMixin
|
8
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_record'
|
2
|
+
require 'saseo/extensions/active_record'
|
2
3
|
require 'saseo/config'
|
3
4
|
require 'saseo/publishing/data_change_message'
|
4
5
|
require 'saseo/models/source/version'
|
@@ -36,7 +37,7 @@ module Saseo
|
|
36
37
|
|
37
38
|
def run(channels: :all, loop: true, timeout: nil)
|
38
39
|
self.channels = channels
|
39
|
-
listen channels: self.channels, loop: loop, timeout: timeout do |channel, pid, payload|
|
40
|
+
db_connection.listen channels: self.channels, loop: loop, timeout: timeout do |channel, pid, payload|
|
40
41
|
uuid = payload
|
41
42
|
logger.debug { "received NOTIFY for source version: #{uuid}" }
|
42
43
|
|
@@ -50,48 +51,6 @@ module Saseo
|
|
50
51
|
def db_connection
|
51
52
|
Saseo::Models::Source::Base.connection
|
52
53
|
end
|
53
|
-
|
54
|
-
def notify(channel, payload)
|
55
|
-
conn = db_connection.instance_variable_get(:@connection)
|
56
|
-
conn.async_exec "SELECT pg_notify('#{channel}', '#{payload.to_s}')"
|
57
|
-
end
|
58
|
-
|
59
|
-
# Heavily cribbed from Sequel:
|
60
|
-
# https://github.com/jeremyevans/sequel/blob/c6678741ce34aac52cff966ff6a6288ccb8d5b75/lib/sequel/adapters/postgres.rb#L440
|
61
|
-
def listen(channels:, after_listen: nil, timeout: nil, loop: false, &block)
|
62
|
-
if loop && !block
|
63
|
-
raise ArgumentError, 'calling #listen with :loop requires a block'
|
64
|
-
end
|
65
|
-
channels = Array(channels)
|
66
|
-
|
67
|
-
timeout_block = timeout.respond_to?(:call) ? timeout : proc { timeout }
|
68
|
-
loop_callable = loop.respond_to?(:call)
|
69
|
-
Saseo::Models::Source::Base.connection_pool.with_connection do |connection|
|
70
|
-
begin
|
71
|
-
conn = connection.instance_variable_get(:@connection)
|
72
|
-
channels.each do |channel|
|
73
|
-
conn.async_exec "LISTEN \"#{channel}\""
|
74
|
-
logger.debug { "listening to #{channel}..." }
|
75
|
-
|
76
|
-
end
|
77
|
-
after_listen.call(conn) if after_listen
|
78
|
-
|
79
|
-
if loop
|
80
|
-
|
81
|
-
catch(:stop) do
|
82
|
-
loop do
|
83
|
-
conn.wait_for_notify(timeout_block.call, &block)
|
84
|
-
loop.call(conn) if loop_callable
|
85
|
-
end
|
86
|
-
end
|
87
|
-
else
|
88
|
-
conn.wait_for_notify(timeout_block.call, &block)
|
89
|
-
end
|
90
|
-
ensure
|
91
|
-
conn.async_exec 'UNLISTEN *'
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
54
|
end
|
96
55
|
end
|
97
56
|
end
|
data/lib/saseo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saseo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Keyes
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -218,12 +218,8 @@ files:
|
|
218
218
|
- lib/saseo/config/saseo_source_database.yml
|
219
219
|
- lib/saseo/extensions.rb
|
220
220
|
- lib/saseo/extensions/active_record.rb
|
221
|
+
- lib/saseo/extensions/active_record/adapter_mixin.rb
|
221
222
|
- lib/saseo/extensions/active_record/detector.rb
|
222
|
-
- lib/saseo/extensions/active_record/patcher.rb
|
223
|
-
- lib/saseo/extensions/active_record/v_3.rb
|
224
|
-
- lib/saseo/extensions/active_record/v_3/connection_adapters/postgresql_adapter.rb
|
225
|
-
- lib/saseo/extensions/active_record/v_4.rb
|
226
|
-
- lib/saseo/extensions/active_record/v_4/connection_adapters/postgresql/database_statements.rb
|
227
223
|
- lib/saseo/models/base.rb
|
228
224
|
- lib/saseo/models/source/base.rb
|
229
225
|
- lib/saseo/models/source/version.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'saseo/extensions/active_record/detector'
|
2
|
-
|
3
|
-
module Saseo
|
4
|
-
module Extensions
|
5
|
-
module ActiveRecord
|
6
|
-
module Patcher
|
7
|
-
extend self
|
8
|
-
|
9
|
-
UnsupportedActiveRecordVersion = Class.new(RuntimeError)
|
10
|
-
|
11
|
-
EXTENSIONS = {
|
12
|
-
3 => ['saseo/extensions/active_record/v_3'],
|
13
|
-
4 => ['saseo/extensions/active_record/v_4'],
|
14
|
-
}
|
15
|
-
|
16
|
-
def patch_active_record!
|
17
|
-
return false unless Saseo::Extensions::ActiveRecord::Detector.active_record_detected?
|
18
|
-
version = Saseo::Extensions::ActiveRecord::Detector.active_record_version
|
19
|
-
|
20
|
-
raise UnsupportedActiveRecordVersion.new unless EXTENSIONS.keys.include? version
|
21
|
-
EXTENSIONS[version].each do |version_extension|
|
22
|
-
require version_extension
|
23
|
-
end
|
24
|
-
true
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
patch_active_record!
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'saseo/extensions/active_record/detector'
|
2
|
-
|
3
|
-
require 'saseo/whodunnit'
|
4
|
-
|
5
|
-
module Saseo
|
6
|
-
module Extensions
|
7
|
-
module ActiveRecord
|
8
|
-
module V3
|
9
|
-
module ConnectionAdapters
|
10
|
-
module PostgreSQLAdapter
|
11
|
-
extend self
|
12
|
-
def begin_db_transaction
|
13
|
-
execute "BEGIN"
|
14
|
-
Saseo::Whodunnit.set_db_whodunnit
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
if Saseo::Extensions::ActiveRecord::Detector.active_record_version == 3
|
24
|
-
require 'active_record/connection_adapters/postgresql_adapter'
|
25
|
-
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend ::Saseo::Extensions::ActiveRecord::V3::ConnectionAdapters::PostgreSQLAdapter
|
26
|
-
end
|
data/lib/saseo/extensions/active_record/v_4/connection_adapters/postgresql/database_statements.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'saseo/extensions/active_record/detector'
|
2
|
-
|
3
|
-
require 'saseo/whodunnit'
|
4
|
-
|
5
|
-
module Saseo
|
6
|
-
module Extensions
|
7
|
-
module ActiveRecord
|
8
|
-
module V4
|
9
|
-
module ConnectionAdapters
|
10
|
-
module PostgreSQL
|
11
|
-
module DatabaseStatements
|
12
|
-
extend self
|
13
|
-
|
14
|
-
def begin_db_transaction
|
15
|
-
execute "BEGIN"
|
16
|
-
Saseo::Whodunnit.set_db_whodunnit
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
if Saseo::Extensions::ActiveRecord::Detector.active_record_version == 3
|
27
|
-
require 'active_record/connection_adapters/postgresql_adapter'
|
28
|
-
::ActiveRecord::ConnectionAdapters::PostgreSQL::DatabaseStatements.prepend ::Saseo::Extensions::ActiveRecord::V4::ConnectionAdapters::PostgreSQL::DatabaseStatements
|
29
|
-
end
|