Class: SplitIoClient::Api::Segments
- Defined in:
- lib/splitclient-rb/engine/api/segments.rb
Overview
Retrieves segment changes from the Split Backend
Constant Summary collapse
- METRICS_PREFIX =
'segmentChangeFetcher'
Constants inherited from Client
Instance Method Summary collapse
- #fetch_segments_by_names(names) ⇒ Object
-
#initialize(api_key, metrics, segments_repository, config) ⇒ Segments
constructor
A new instance of Segments.
Methods inherited from Client
Constructor Details
#initialize(api_key, metrics, segments_repository, config) ⇒ Segments
Returns a new instance of Segments.
9 10 11 12 13 14 |
# File 'lib/splitclient-rb/engine/api/segments.rb', line 9 def initialize(api_key, metrics, segments_repository, config) super(config) @metrics = metrics @api_key = api_key @segments_repository = segments_repository end |
Instance Method Details
#fetch_segments_by_names(names) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/splitclient-rb/engine/api/segments.rb', line 16 def fetch_segments_by_names(names) start = Time.now return if names.nil? || names.empty? names.each do |name| since = @segments_repository.get_change_number(name) loop do segment = fetch_segment_changes(name, since) @segments_repository.add_to_segment(segment) @config.split_logger.log_if_debug("Segment #{name} fetched before: #{since}, \ till: #{@segments_repository.get_change_number(name)}") break if since.to_i >= @segments_repository.get_change_number(name).to_i since = @segments_repository.get_change_number(name) end end latency = (Time.now - start) * 1000.0 @metrics.time(METRICS_PREFIX + '.time', latency) end |