rails_failover 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/rails_failover/redis/handler.rb +19 -3
- data/lib/rails_failover/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b0f3e010743d83bd67b2cce785fde0952ba32c82c8c1ab5fef3aa56e5baa520
|
4
|
+
data.tar.gz: 26cc2466069dfe48b691d8676078b3ed9ee3ce82e7a8d4447fa327436741fd39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ce28a0d758dde383537bce455502edfcbf9388ad4c2835edc17b2e259156affc885153f728e39fa66c8c25d3f9dfea34a8f489b663e7738fc092dc6c76dccb8
|
7
|
+
data.tar.gz: 0f0c08446e0e64c5eb6ee972e80e8776e58fbd32877254e50098a17a4d4475db64379d7ad237933b054e5eaf7c54df72785c69253e7d31be1b28d38028fcaf11
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ end
|
|
53
53
|
|
54
54
|
#### Multiple connection handlers
|
55
55
|
|
56
|
-
Note: This API is unstable and is likely to
|
56
|
+
Note: This API is unstable and is likely to change when Rails 6.1 is released with sharding support.
|
57
57
|
|
58
58
|
```
|
59
59
|
# config/database.yml
|
@@ -169,7 +169,7 @@ module RailsFailover
|
|
169
169
|
# Calling .disconnect can cause a running subscribe() to block forever
|
170
170
|
# Therefore try to acquire the lock
|
171
171
|
def soft_disconnect(redis, client, role)
|
172
|
-
has_lock = redis
|
172
|
+
has_lock = redis_mon_try_enter(redis)
|
173
173
|
|
174
174
|
if !has_lock
|
175
175
|
begin
|
@@ -180,7 +180,7 @@ module RailsFailover
|
|
180
180
|
|
181
181
|
waiting_since = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
182
182
|
loop do # Keep trying
|
183
|
-
break if has_lock = redis
|
183
|
+
break if has_lock = redis_mon_try_enter(redis)
|
184
184
|
break if !client.connection.connected? # Disconnected by other thread
|
185
185
|
break if client.connection.rails_failover_role != role # Reconnected by other thread
|
186
186
|
time_now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
@@ -191,12 +191,28 @@ module RailsFailover
|
|
191
191
|
|
192
192
|
client.disconnect if client.connection&.rails_failover_role == role
|
193
193
|
ensure
|
194
|
-
redis
|
194
|
+
redis_mon_exit(redis) if has_lock
|
195
195
|
end
|
196
196
|
|
197
197
|
def logger
|
198
198
|
RailsFailover::Redis.logger
|
199
199
|
end
|
200
|
+
|
201
|
+
def redis_mon_try_enter(redis)
|
202
|
+
if redis.respond_to? :mon_try_enter
|
203
|
+
redis.mon_try_enter
|
204
|
+
else
|
205
|
+
redis.instance_variable_get(:@monitor).mon_try_enter
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def redis_mon_exit(redis)
|
210
|
+
if redis.respond_to? :mon_exit
|
211
|
+
redis.mon_exit
|
212
|
+
else
|
213
|
+
redis.instance_variable_get(:@monitor).mon_exit
|
214
|
+
end
|
215
|
+
end
|
200
216
|
end
|
201
217
|
end
|
202
218
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_failover
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan Tan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|