misha-ar-octopus 0.8.5 → 0.8.7

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
  SHA1:
3
- metadata.gz: 4d7aed4e7a1e49c21bb58f7caf135c524213fcb6
4
- data.tar.gz: 19f02f593808210ad8525908a7dad698ddba16b5
3
+ metadata.gz: 281daf3f746620c9c532e375151dc38b60723410
4
+ data.tar.gz: 8ec2145b1f7a5ad70b28eb28afcc6648bb929f35
5
5
  SHA512:
6
- metadata.gz: 6a2c17edad9ba36dc637ed61a7405c7af4d7e90f2f3b670b005352747861107f061a007dba7ebb66121c169af75a903ffbd5f678ae9614e09014947f75ff7925
7
- data.tar.gz: 93cbcc6e5c248f23f7dab52d2e04529c1eff4d894b9d3a1c162a2f416c6bb2bd9b8fb0074084df96951b1cf66f05eba4db5781d0a71441ed3d314138e1bc8c4d
6
+ metadata.gz: 567b3f257582d25174cbc5665de939f606236bf6646049db6fa29b13f0e05bfeb704589fd0182cbb95bc27c2c7dd6f5beb8117395d64c2b31efbbfa1b9e5ba4d
7
+ data.tar.gz: 87817bf90a7e1dc94404440c348c79b670afa4afce2080dbe31b94e1f272131a7ea7ba6613d66560c43b56b796bd74c80f8522161b83a67bc4ccedbd378ca3dd
@@ -117,11 +117,11 @@ module Octopus
117
117
  ActiveRecord::Base.connection.initialize_shards(@config)
118
118
  end
119
119
 
120
- def self.using(shard, options = {}, &block)
120
+ def self.using(shard, &block)
121
121
  conn = ActiveRecord::Base.connection
122
122
 
123
123
  if conn.is_a?(Octopus::Proxy)
124
- conn.run_queries_on_shard(shard, options, &block)
124
+ conn.run_queries_on_shard(shard, &block)
125
125
  else
126
126
  yield
127
127
  end
@@ -10,7 +10,7 @@ module Octopus
10
10
  CURRENT_SHARD_KEY = 'octopus.current_shard'.freeze
11
11
  CURRENT_GROUP_KEY = 'octopus.current_group'.freeze
12
12
  CURRENT_SLAVE_GROUP_KEY = 'octopus.current_slave_group'.freeze
13
- CURRENT_OPTIONS_KEY = 'octopus.current_options'.freeze
13
+ CURRENT_LOAD_BALANCE_OPTIONS_KEY = 'octopus.current_load_balance_options'.freeze
14
14
  BLOCK_KEY = 'octopus.block'.freeze
15
15
  LAST_CURRENT_SHARD_KEY = 'octopus.last_current_shard'.freeze
16
16
  FULLY_REPLICATED_KEY = 'octopus.fully_replicated'.freeze
@@ -118,6 +118,7 @@ module Octopus
118
118
  hash = shard_symbol
119
119
  shard_symbol = hash[:shard]
120
120
  slave_group_symbol = hash[:slave_group]
121
+ load_balance_options = hash[:load_balance_options]
121
122
 
122
123
  if shard_symbol.nil? && slave_group_symbol.nil?
123
124
  fail 'Neither shard or slave group must be specified'
@@ -134,6 +135,7 @@ module Octopus
134
135
  end
135
136
  end
136
137
  self.current_slave_group = slave_group_symbol
138
+ self.current_load_balance_options = load_balance_options
137
139
  else
138
140
  fail "Nonexistent Shard Name: #{shard_symbol}" if @shards[shard_symbol].nil?
139
141
  end
@@ -160,14 +162,15 @@ module Octopus
160
162
 
161
163
  def current_slave_group=(slave_group_symbol)
162
164
  Thread.current[CURRENT_SLAVE_GROUP_KEY] = slave_group_symbol
165
+ Thread.current[CURRENT_LOAD_BALANCE_OPTIONS_KEY] = nil if slave_group_symbol.nil?
163
166
  end
164
167
 
165
- def current_options
166
- Thread.current[CURRENT_OPTIONS_KEY]
168
+ def current_load_balance_options
169
+ Thread.current[CURRENT_LOAD_BALANCE_OPTIONS_KEY]
167
170
  end
168
171
 
169
- def current_options=(options)
170
- Thread.current[CURRENT_OPTIONS_KEY] = options
172
+ def current_load_balance_options=(options)
173
+ Thread.current[CURRENT_LOAD_BALANCE_OPTIONS_KEY] = options
171
174
  end
172
175
 
173
176
  def block
@@ -237,9 +240,9 @@ module Octopus
237
240
  @adapters.size > 1
238
241
  end
239
242
 
240
- def run_queries_on_shard(shard, options={}, &_block)
243
+ def run_queries_on_shard(shard, &_block)
241
244
  keeping_connection_proxy(shard) do
242
- using_shard(shard, options) do
245
+ using_shard(shard) do
243
246
  yield
244
247
  end
245
248
  end
@@ -438,7 +441,7 @@ module Octopus
438
441
 
439
442
  def send_queries_to_selected_slave(method, *args, &block)
440
443
  if current_model.replicated || fully_replicated?
441
- selected_slave = @slaves_load_balancer.next current_options
444
+ selected_slave = @slaves_load_balancer.next current_load_balance_options
442
445
  else
443
446
  selected_slave = Octopus.master_shard
444
447
  end
@@ -466,7 +469,7 @@ module Octopus
466
469
  # Temporarily switch `current_shard` to the next slave in a slave group and send queries to it
467
470
  # while preserving `current_shard`
468
471
  def send_queries_to_balancer(balancer, method, *args, &block)
469
- send_queries_to_slave(balancer.next(current_options), method, *args, &block)
472
+ send_queries_to_slave(balancer.next(current_load_balance_options), method, *args, &block)
470
473
  end
471
474
 
472
475
  # Temporarily switch `current_shard` to the specified slave and send queries to it
@@ -493,21 +496,21 @@ module Octopus
493
496
  end
494
497
 
495
498
  # Temporarily switch `current_shard` and run the block
496
- def using_shard(shard, options = {}, &_block)
499
+ def using_shard(shard, &_block)
497
500
  older_shard = current_shard
498
501
  older_slave_group = current_slave_group
499
- older_options = current_options
502
+ older_load_balance_options = current_load_balance_options
503
+
500
504
 
501
505
  begin
502
506
  unless current_model && !current_model.allowed_shard?(shard)
503
507
  self.current_shard = shard
504
- self.current_options = options
505
508
  end
506
509
  yield
507
510
  ensure
508
511
  self.current_shard = older_shard
509
512
  self.current_slave_group = older_slave_group
510
- self.current_options = older_options
513
+ self.current_load_balance_options = older_load_balance_options
511
514
  end
512
515
  end
513
516
 
@@ -6,8 +6,8 @@ module Octopus
6
6
  @load_balancer = Octopus.load_balancer.new(slaves_list)
7
7
  end
8
8
 
9
- def next
10
- @load_balancer.next
9
+ def next(options)
10
+ @load_balancer.next options
11
11
  end
12
12
  end
13
13
  end
@@ -1,3 +1,3 @@
1
1
  module Octopus
2
- VERSION = '0.8.5'
2
+ VERSION = '0.8.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: misha-ar-octopus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago Pradi