knockoff 0.2.1 → 0.2.2
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/.gitignore +1 -0
- data/README.md +14 -2
- data/lib/knockoff/base.rb +10 -7
- data/lib/knockoff/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e5db34168c3328cc0f1103d49f8dc3afe1f1e52
|
4
|
+
data.tar.gz: 76763a62ba7a2a5328c643b2de5746349237aba1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91a853b868fe982e37356c308d1ba9d882818f5294dc1fb2ba8ec8fef1414dacb6575f9c028186b46468ca6280343223812d34e498501b04508f7a769478a53b
|
7
|
+
data.tar.gz: 9492b0d7391ffabc493ff88b01950ff86c58a923c23350ad35756b1e1663ceb51eebede052754b3305aa505497287bcc64cd18ff65ba99865c2cd204d023ec0b
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](https://travis-ci.org/sgringwe/knockoff)
|
4
4
|
[](https://badge.fury.io/rb/knockoff)
|
5
5
|
|
6
|
-
A gem for easily using read replicas.
|
6
|
+
A gem for easily using read replicas.
|
7
7
|
|
8
8
|
## Library Goals
|
9
9
|
|
@@ -165,6 +165,15 @@ Knockoff.establish_new_connections!({ 'pool' => db_pool })
|
|
165
165
|
|
166
166
|
For forking servers, you may disconnect all replicas before forking with `Knockoff.disconnect_all!`.
|
167
167
|
|
168
|
+
```
|
169
|
+
# puma.rb
|
170
|
+
|
171
|
+
before_fork do
|
172
|
+
ActiveRecord::Base.connection_pool.disconnect!
|
173
|
+
Knockoff.disconnect_all!
|
174
|
+
end
|
175
|
+
```
|
176
|
+
|
168
177
|
### Other Cases
|
169
178
|
|
170
179
|
There are likely other cases specific to each application where it makes sense to force primary database and avoid replication lag. Good candidates are time-based pages (a live calendar, for example), forms, and payments.
|
@@ -173,6 +182,10 @@ There are likely other cases specific to each application where it makes sense t
|
|
173
182
|
|
174
183
|
* Do not use prepared statements with this gem
|
175
184
|
|
185
|
+
## Inspirations
|
186
|
+
|
187
|
+
Heavily based off of https://github.com/kenn/slavery and https://github.com/kickstarter/replica_pools gem.
|
188
|
+
|
176
189
|
## Development
|
177
190
|
|
178
191
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -183,7 +196,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
183
196
|
|
184
197
|
Bug reports and pull requests are welcome on GitHub at https://github.com/sgringwe/knockoff.
|
185
198
|
|
186
|
-
|
187
199
|
## License
|
188
200
|
|
189
201
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/knockoff/base.rb
CHANGED
@@ -11,13 +11,16 @@ module Knockoff
|
|
11
11
|
private
|
12
12
|
|
13
13
|
def decide_with(target)
|
14
|
-
|
14
|
+
calculated_target =
|
15
|
+
if Knockoff.enabled
|
16
|
+
target
|
17
|
+
else
|
18
|
+
:primary
|
19
|
+
end
|
15
20
|
|
16
|
-
if
|
17
|
-
|
18
|
-
|
19
|
-
:primary
|
20
|
-
end
|
21
|
+
# Don't allow setting the target to anything other than primary if we are already in a transaction
|
22
|
+
raise Knockoff::Error.new('on_replica cannot be used inside transaction block!') if calculated_target != :primary && inside_transaction?
|
23
|
+
calculated_target
|
21
24
|
end
|
22
25
|
|
23
26
|
def inside_transaction?
|
@@ -33,4 +36,4 @@ module Knockoff
|
|
33
36
|
RequestLocals.store[:knockoff] = backup
|
34
37
|
end
|
35
38
|
end
|
36
|
-
end
|
39
|
+
end
|
data/lib/knockoff/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knockoff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Ringwelski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|