Module: EnquiryConsul::Balancer

Defined in:
lib/enquiry-consul/balancer.rb

Overview

负载均衡模块

Class Method Summary collapse

Class Method Details

.pick_service(service_name, services) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/enquiry-consul/balancer.rb', line 5

def pick_service(service_name, services)
  pre_index = Rails.cache.read(service_name)
  next_index = pre_index && pre_index + 1 || 0
  next_index = 0 if next_index >= services.size
  Rails.cache.write(service_name, next_index)
  services[next_index]
end