Class: Solr::MasterSlave::NodesGrayList::InMemory
- Inherits:
-
Object
- Object
- Solr::MasterSlave::NodesGrayList::InMemory
- Defined in:
- lib/solr/master_slave/nodes_gray_list/in_memory.rb
Constant Summary collapse
- DEFAULT_REMOVAL_PERIOD =
5 minutes in seconds
5 * 60
Instance Attribute Summary collapse
-
#gray_list ⇒ Object
readonly
Returns the value of attribute gray_list.
-
#removal_period ⇒ Object
readonly
Returns the value of attribute removal_period.
Instance Method Summary collapse
- #add(url) ⇒ Object
- #added?(url) ⇒ Boolean
-
#initialize(removal_period: DEFAULT_REMOVAL_PERIOD) ⇒ InMemory
constructor
A new instance of InMemory.
- #remove(url) ⇒ Object
- #select_active(urls, collection_name:) ⇒ Object
Constructor Details
#initialize(removal_period: DEFAULT_REMOVAL_PERIOD) ⇒ InMemory
Returns a new instance of InMemory.
9 10 11 12 |
# 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 |
Instance Attribute Details
#gray_list ⇒ Object (readonly)
Returns the value of attribute gray_list.
5 6 7 |
# File 'lib/solr/master_slave/nodes_gray_list/in_memory.rb', line 5 def gray_list @gray_list end |
#removal_period ⇒ Object (readonly)
Returns the value of attribute removal_period.
5 6 7 |
# File 'lib/solr/master_slave/nodes_gray_list/in_memory.rb', line 5 def removal_period @removal_period end |
Instance Method Details
#add(url) ⇒ Object
14 15 16 17 18 |
# 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) ⇒ Boolean
24 25 26 27 28 29 30 31 32 33 34 |
# 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) ⇒ Object
20 21 22 |
# 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:) ⇒ Object
36 37 38 39 40 41 42 43 |
# 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 |