class Solr::MasterSlave::NodesGrayList::InMemory

Constants

DEFAULT_REMOVAL_PERIOD

Attributes

gray_list[R]
removal_period[R]

Public Class Methods

new(removal_period: DEFAULT_REMOVAL_PERIOD) click to toggle source
# File lib/solr/master_slave/nodes_gray_list/in_memory.rb, line 9
def initialize(removal_period: DEFAULT_REMOVAL_PERIOD)
  @gray_list = {}
  @removal_period = removal_period
end

Public Instance Methods

add(url) click to toggle source
# File lib/solr/master_slave/nodes_gray_list/in_memory.rb, line 14
def add(url)
  return if gray_list.has_key?(url)
  ::Solr.configuration.logger.info("#{url} added to a gray list")
  gray_list[url] = Time.now.utc
end
added?(url) click to toggle source
# File lib/solr/master_slave/nodes_gray_list/in_memory.rb, line 24
def added?(url)
  added_at = gray_list[url]
  return false unless added_at

  if added_at + removal_period > Time.now.utc
    true
  else
    remove(url)
    false
  end
end
remove(url) click to toggle source
# File lib/solr/master_slave/nodes_gray_list/in_memory.rb, line 20
def remove(url)
  gray_list.delete(url)
end
select_active(urls, collection_name:) click to toggle source
# File lib/solr/master_slave/nodes_gray_list/in_memory.rb, line 36
def select_active(urls, collection_name:)
  urls = Array(urls)
  active_urls = urls.reject do |url|
    collection_url = File.join(url, collection_name.to_s)
    added?(collection_url)
  end
  active_urls.any? ? active_urls : urls
end