Module: LoadBalancer::ClassMethods

Defined in:
lib/multi_dbs_load_balancer/load_balancer.rb

Instance Method Summary collapse

Instance Method Details

#connected_through_load_balancer(name, **options, &blk) ⇒ Object Also known as: connected_through, connected_by

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
# File 'lib/multi_dbs_load_balancer/load_balancer.rb', line 42

def connected_through_load_balancer(name, **options, &blk)
    raise ArgumentError, "not found #{name} load balancer" unless LoadBalancer.lb.has_key?(name)
    
    configs = LoadBalancer.lb[name]
    lb = configs[:clazz].new(configs[:db_configs], redis: configs[:redis], key: configs[:key])
    lb.connected_to_next_db(**options, &blk)
end

#load_balancing(name, db_configs, algorithm: :round_robin, redis: nil) ⇒ Object



38
39
40
# File 'lib/multi_dbs_load_balancer/load_balancer.rb', line 38

def load_balancing(name, db_configs, algorithm: :round_robin, redis: nil)
    LoadBalancer.init(name, db_configs, algorithm: algorithm, redis: redis)
end