distribute_reads 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/distribute_reads.rb +6 -1
- data/lib/distribute_reads/global_methods.rb +5 -1
- data/lib/distribute_reads/job_methods.rb +2 -2
- data/lib/distribute_reads/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 731daba05fd408780f3548cac44ddeda0d4c0c7c
|
4
|
+
data.tar.gz: 403b13ce349e56794b0bdc3457222724f1da4f8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76250c6a063c2797328938254bdc0b9c18508929c11a969f9f03d05ada6fe419038d1d25b0772ba536a486f3daf2cfa58673c5ec637324d49ebcddfb04e625d5
|
7
|
+
data.tar.gz: 4e7289ee561734260874b0a4098f1f991d2ee4965132b59a2257530a3ad54d13510bf6ad3de9fb2c0498b1b9a058cd5f25b29995bc577891178dff05d32504c6
|
data/CHANGELOG.md
CHANGED
data/lib/distribute_reads.rb
CHANGED
@@ -14,7 +14,12 @@ module DistributeReads
|
|
14
14
|
def self.lag
|
15
15
|
conn = ActiveRecord::Base.connection
|
16
16
|
if %w(PostgreSQL PostGIS).include?(conn.adapter_name)
|
17
|
-
conn.execute(
|
17
|
+
conn.execute(
|
18
|
+
"SELECT CASE
|
19
|
+
WHEN pg_last_xlog_receive_location() = pg_last_xlog_replay_location() THEN 0
|
20
|
+
ELSE EXTRACT (EPOCH FROM NOW() - pg_last_xact_replay_timestamp())
|
21
|
+
END AS lag"
|
22
|
+
).first["lag"].to_f
|
18
23
|
else
|
19
24
|
raise "Option not supported with this adapter"
|
20
25
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module DistributeReads
|
2
2
|
module GlobalMethods
|
3
3
|
def distribute_reads(max_lag: nil)
|
4
|
+
raise ArgumentError, "Missing block" unless block_given?
|
5
|
+
|
4
6
|
if max_lag && DistributeReads.lag > max_lag
|
5
7
|
raise DistributeReads::TooMuchLag, "Replica lag over #{max_lag} seconds"
|
6
8
|
end
|
@@ -8,7 +10,9 @@ module DistributeReads
|
|
8
10
|
previous_value = Thread.current[:distribute_reads]
|
9
11
|
begin
|
10
12
|
Thread.current[:distribute_reads] = true
|
11
|
-
yield
|
13
|
+
value = yield
|
14
|
+
warn "[distribute_reads] Call `to_a` inside block to execute query on replica" if value.is_a?(ActiveRecord::Relation) && !previous_value
|
15
|
+
value
|
12
16
|
ensure
|
13
17
|
Thread.current[:distribute_reads] = previous_value
|
14
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: distribute_reads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: makara
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
134
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.6.
|
135
|
+
rubygems_version: 2.6.13
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: Scale database reads with replicas in Rails
|