lib/cache/repositories/splits_repository.rb in splitclient-rb-3.1.2 vs lib/cache/repositories/splits_repository.rb in splitclient-rb-3.1.3.pre.rc1

- old
+ new

@@ -4,14 +4,17 @@ module Cache module Repositories class SplitsRepository < Repository SPLITS_SLICE = 10 - def initialize(adapter) + attr_reader :adapter + + def initialize(adapter, config) @adapter = adapter + @config = config - @adapter.set_string(namespace_key('split.till'), '-1') + @adapter.set_string(namespace_key('splits.till'), '-1') @adapter.initialize_map(namespace_key('segments.registered')) end def add_split(split) @adapter.set_string(namespace_key("split.#{split[:name]}"), split.to_json) @@ -52,23 +55,22 @@ end splits_hash end - # Return an array of Split Names excluding control keys like split.till + # Return an array of Split Names excluding control keys like splits.till def split_names - @adapter.find_strings_by_prefix(namespace_key('split')) - .reject { |split| split == namespace_key('split.till') } + @adapter.find_strings_by_prefix(namespace_key('split.')) .map { |split| split.gsub(namespace_key('split.'), '') } end def set_change_number(since) - @adapter.set_string(namespace_key('split.till'), since) + @adapter.set_string(namespace_key('splits.till'), since) end def get_change_number - @adapter.string(namespace_key('split.till')) + @adapter.string(namespace_key('splits.till')) end def set_segment_names(names) return if names.nil? || names.empty? @@ -77,9 +79,21 @@ end end def exists?(name) @adapter.exists?(namespace_key("split.#{name}")) + end + + def ready? + @adapter.string(namespace_key('cache.ready.splits')).to_i != -1 + end + + def not_ready! + @adapter.set_string(namespace_key('cache.ready.splits'), -1) + end + + def ready! + @adapter.set_string(namespace_key('cache.ready.splits'), Time.now.utc.to_i) end end end end end