lib/ldclient-rb/impl/big_segments.rb in launchdarkly-server-sdk-6.4.0 vs lib/ldclient-rb/impl/big_segments.rb in launchdarkly-server-sdk-7.0.0

- old
+ new

@@ -20,39 +20,39 @@ @stale_after_millis = big_segments_config.stale_after * 1000 @status_provider = BigSegmentStoreStatusProviderImpl.new(-> { get_status }) @logger = logger @last_status = nil - if !@store.nil? + unless @store.nil? @cache = ExpiringCache.new(big_segments_config.user_cache_size, big_segments_config.user_cache_time) @poll_worker = RepeatingTask.new(big_segments_config.status_poll_interval, 0, -> { poll_store_and_update_status }, logger) @poll_worker.start end end attr_reader :status_provider def stop - @poll_worker.stop if !@poll_worker.nil? - @store.stop if !@store.nil? + @poll_worker.stop unless @poll_worker.nil? + @store.stop unless @store.nil? end - def get_user_membership(user_key) - return nil if !@store - membership = @cache[user_key] - if !membership + def get_context_membership(context_key) + return nil unless @store + membership = @cache[context_key] + unless membership begin - membership = @store.get_membership(BigSegmentStoreManager.hash_for_user_key(user_key)) + membership = @store.get_membership(BigSegmentStoreManager.hash_for_context_key(context_key)) membership = EMPTY_MEMBERSHIP if membership.nil? - @cache[user_key] = membership + @cache[context_key] = membership rescue => e LaunchDarkly::Util.log_exception(@logger, "Big Segment store membership query returned error", e) return BigSegmentMembershipResult.new(nil, BigSegmentsStatus::STORE_ERROR) end end - poll_store_and_update_status if !@last_status - if !@last_status.available + poll_store_and_update_status unless @last_status + unless @last_status.available return BigSegmentMembershipResult.new(membership, BigSegmentsStatus::STORE_ERROR) end BigSegmentMembershipResult.new(membership, @last_status.stale ? BigSegmentsStatus::STALE : BigSegmentsStatus::HEALTHY) end @@ -60,29 +60,29 @@ @last_status || poll_store_and_update_status end def poll_store_and_update_status new_status = Interfaces::BigSegmentStoreStatus.new(false, false) # default to "unavailable" if we don't get a new status below - if !@store.nil? + unless @store.nil? begin metadata = @store.get_metadata - new_status = Interfaces::BigSegmentStoreStatus.new(true, !metadata || is_stale(metadata.last_up_to_date)) + new_status = Interfaces::BigSegmentStoreStatus.new(true, !metadata || stale?(metadata.last_up_to_date)) rescue => e LaunchDarkly::Util.log_exception(@logger, "Big Segment store status query returned error", e) end end @last_status = new_status @status_provider.update_status(new_status) - + new_status end - def is_stale(timestamp) + def stale?(timestamp) !timestamp || ((Impl::Util.current_time_millis - timestamp) >= @stale_after_millis) end - def self.hash_for_user_key(user_key) - Digest::SHA256.base64digest(user_key) + def self.hash_for_context_key(context_key) + Digest::SHA256.base64digest(context_key) end end # # Default implementation of the BigSegmentStoreStatusProvider interface.