resilient_reads 0.1.3 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec873d08dc27b40673379ea070233b0aa06ce97f75adc77b9b43b29265be38b1
4
- data.tar.gz: b0fb02179cdf69e5859f2d3ec1e0910d122590a92d876665d9d398414ca56ab7
3
+ metadata.gz: d9a7b3f39e250957ac840a69af135911e9e466e1c1a656eaf965701b63cb5e9b
4
+ data.tar.gz: 14c6ca6f9bd822cafc53e3cfa39562284ca4fffa3e2f8169ae0684fbac7ea1bf
5
5
  SHA512:
6
- metadata.gz: 0d370a34eae6f0a3ff3206547705fd832ecc59a48597661db41cf35f94369140e7d8e0cd68297b98e5db6918cdd3ccca61144d5583612f40a6910cf56f8b9f19
7
- data.tar.gz: 2ca096b7bed1ce980eb914bca296c0d015e2766026f621881a545ef09efbbaa63cbd2cd3151b6409718af145e2065029a7c4223de31fe3cef2393062fc44836b
6
+ metadata.gz: 959af6f366c6bd99e6e37570c450b30746c197a87daa2448b83549cf53b166782e3e73582a740f346768e10d98e84f0bd5424cac39477fbeab630a90f1be0fe3
7
+ data.tar.gz: 7b001e842fb6828491541f565a71b8a952a0435a4ad5de9faafe38076519196a858aa17f1113c9309479711fda07eaf0b2a8f8aa0d26da35a5495fedb0f8b21d
@@ -11,8 +11,6 @@
11
11
  </content>
12
12
  <orderEntry type="jdk" jdkName="RVM: ruby-3.4.2" jdkType="RUBY_SDK" />
13
13
  <orderEntry type="sourceFolder" forTests="false" />
14
- <orderEntry type="library" scope="PROVIDED" name="bundler (v2.7.2, RVM: ruby-3.4.2) [gem]" level="application" />
15
14
  <orderEntry type="library" scope="PROVIDED" name="minitest (v5.25.4, RVM: ruby-3.4.2) [gem]" level="application" />
16
- <orderEntry type="library" scope="PROVIDED" name="rake (v13.3.1, RVM: ruby-3.4.2) [gem]" level="application" />
17
15
  </component>
18
16
  </module>
data/README.md CHANGED
@@ -19,7 +19,7 @@ Drop-in replacement for [distribute_reads](https://github.com/ankane/distribute_
19
19
  Add to your Gemfile:
20
20
 
21
21
  ```ruby
22
- gem "resilient_reads", path: "gems/resilient_reads"
22
+ gem "resilient_reads"
23
23
  ```
24
24
 
25
25
  Remove any previous read-distribution gems:
@@ -214,4 +214,4 @@ config.lag_check_interval = 10 # Cache lag result for 10 seconds
214
214
 
215
215
  ## License
216
216
 
217
- MIT
217
+ MIT
@@ -47,32 +47,30 @@ module ResilientReads
47
47
  def self.lag_for_mysql(conn)
48
48
  # Prefer SHOW REPLICA STATUS (MySQL 8.0.22+, MariaDB 10.5.1+)
49
49
  # and fall back to the deprecated SHOW SLAVE STATUS.
50
- result =
50
+ ResilientReads.log(:debug, "MySQL Replica Lag Start")
51
+ lag =
51
52
  begin
52
- conn.execute("SHOW REPLICA STATUS")
53
+ result = conn.execute("SHOW REPLICA STATUS")
54
+ if result.present? && result.rows.present?
55
+ result.rows.first[result.fields.index("Seconds_Behind_Source")]
56
+ else
57
+ nil
58
+ end
53
59
  rescue ActiveRecord::StatementInvalid
54
- conn.execute("SHOW SLAVE STATUS")
60
+ result = conn.execute("SHOW SLAVE STATUS")
61
+ if result.present? && result.rows.present?
62
+ result.rows.first[result.fields.index("Seconds_Behind_Master")]
63
+ else
64
+ nil
65
+ end
55
66
  end
56
-
57
- row = if result.respond_to?(:first)
58
- result.first
59
- elsif result.respond_to?(:to_a)
60
- result.to_a.first
61
- end
62
-
63
- return nil unless row
64
-
65
- # Seconds_Behind_Source (MySQL 8.0.22+) / Seconds_Behind_Master (legacy)
66
- lag = if row.is_a?(Hash)
67
- row["Seconds_Behind_Source"] || row["Seconds_Behind_Master"]
68
- elsif row.respond_to?(:[])
69
- row["Seconds_Behind_Source"] || row["Seconds_Behind_Master"]
70
- end
67
+ ResilientReads.log(:debug, "MySQL Replica Lag: #{lag}")
71
68
 
72
69
  lag&.to_f
73
70
  rescue => e
74
71
  ResilientReads.log(:debug, "MySQL lag check failed: #{e.message}")
75
72
  nil
76
73
  end
74
+
77
75
  end
78
- end
76
+ end
@@ -85,8 +85,16 @@ module ResilientReads
85
85
  end
86
86
 
87
87
  # Verify the replica is reachable. Returns true/false and updates health.
88
+ # Uses the raw connection to avoid ActiveRecord SQL instrumentation/logging.
88
89
  def check_health!
89
- @connection_class.connection.execute("SELECT 1")
90
+ raw = @connection_class.connection.raw_connection
91
+ if raw.respond_to?(:exec) # PG::Connection
92
+ raw.exec("SELECT 1")
93
+ elsif raw.respond_to?(:ping) # Mysql2::Client / Trilogy
94
+ raw.ping
95
+ else
96
+ @connection_class.connection.execute("SELECT 1")
97
+ end
90
98
  mark_healthy!
91
99
  true
92
100
  rescue => e
@@ -1,3 +1,3 @@
1
1
  module ResilientReads
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -111,7 +111,7 @@ module ResilientReads
111
111
  logger = config.logger
112
112
  return unless logger
113
113
 
114
- logger.public_send(level, "[ResilientReads] #{message}")
114
+ # logger.public_send(level, "[ResilientReads] #{message}")
115
115
  rescue
116
116
  # Never let logging break query flow.
117
117
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resilient_reads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Puckett
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-06-09 00:00:00.000000000 Z
10
+ date: 2026-06-19 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Distribute database reads across multiple replicas in Rails with automatic
13
13
  load balancing, health checking, and graceful failover to primary.