Class: ProxyLoadBalancer
- Inherits:
-
Object
- Object
- ProxyLoadBalancer
- Defined in:
- app/services/proxy_load_balancer.rb
Instance Attribute Summary collapse
-
#offline ⇒ Object
readonly
Returns the value of attribute offline.
Instance Method Summary collapse
-
#initialize ⇒ ProxyLoadBalancer
constructor
A new instance of ProxyLoadBalancer.
-
#next(proxies) ⇒ Object
Get the least loaded proxy from the given list of proxies.
Constructor Details
#initialize ⇒ ProxyLoadBalancer
Returns a new instance of ProxyLoadBalancer.
5 6 7 8 |
# File 'app/services/proxy_load_balancer.rb', line 5 def initialize @tasks = {} @offline = [] end |
Instance Attribute Details
#offline ⇒ Object (readonly)
Returns the value of attribute offline.
3 4 5 |
# File 'app/services/proxy_load_balancer.rb', line 3 def offline @offline end |
Instance Method Details
#next(proxies) ⇒ Object
Get the least loaded proxy from the given list of proxies
11 12 13 14 15 16 17 |
# File 'app/services/proxy_load_balancer.rb', line 11 def next(proxies) exclude = @tasks.keys + @offline @tasks.merge!(get_counts(proxies - exclude)) next_proxy = @tasks.select { |proxy, _| proxies.include?(proxy) }.min_by { |_, job_count| job_count }.try(:first) @tasks[next_proxy] += 1 if next_proxy.present? next_proxy end |