Class: SplitIoClient::Cache::Fetchers::SplitFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-rb/cache/fetchers/split_fetcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(splits_repository, rule_based_segments_repository, api_key, config, telemetry_runtime_producer) ⇒ SplitFetcher



7
8
9
10
11
12
13
14
# File 'lib/splitclient-rb/cache/fetchers/split_fetcher.rb', line 7

def initialize(splits_repository, rule_based_segments_repository, api_key, config, telemetry_runtime_producer)
  @splits_repository = splits_repository
  @rule_based_segments_repository = rule_based_segments_repository
  @api_key = api_key
  @config = config
  @semaphore = Mutex.new
  @telemetry_runtime_producer = telemetry_runtime_producer
end

Instance Attribute Details

#rule_based_segments_repositoryObject (readonly)

Returns the value of attribute rule_based_segments_repository.



5
6
7
# File 'lib/splitclient-rb/cache/fetchers/split_fetcher.rb', line 5

def rule_based_segments_repository
  @rule_based_segments_repository
end

#splits_repositoryObject (readonly)

Returns the value of attribute splits_repository.



5
6
7
# File 'lib/splitclient-rb/cache/fetchers/split_fetcher.rb', line 5

def splits_repository
  @splits_repository
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
# File 'lib/splitclient-rb/cache/fetchers/split_fetcher.rb', line 16

def call
  if ENV['SPLITCLIENT_ENV'] == 'test'
    fetch_splits
    return
  end

  splits_thread
end

#fetch_splits(fetch_options = { cache_control_headers: false, till: nil }) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/splitclient-rb/cache/fetchers/split_fetcher.rb', line 25

def fetch_splits(fetch_options = { cache_control_headers: false, till: nil })
  @semaphore.synchronize do
    data = splits_since(@splits_repository.get_change_number, @rule_based_segments_repository.get_change_number, fetch_options)
    SplitIoClient::Helpers::RepositoryHelper.update_feature_flag_repository(@splits_repository, data[:ff][:d], data[:ff][:t], @config, @splits_api.clear_storage)
    SplitIoClient::Helpers::RepositoryHelper.update_rule_based_segment_repository(@rule_based_segments_repository, data[:rbs][:d], data[:rbs][:t], @config)
    @splits_repository.set_segment_names(data[:segment_names])
    @rule_based_segments_repository.set_segment_names(data[:segment_names])
    @config.logger.debug("segments seen(#{data[:segment_names].length}): #{data[:segment_names].to_a}") if @config.debug_enabled

    { segment_names: data[:segment_names], success: true }
  end
rescue StandardError => e
  @config.log_found_exception(__method__.to_s, e)
  { segment_names: [], success: false }
end

#stop_splits_threadObject



41
42
43
# File 'lib/splitclient-rb/cache/fetchers/split_fetcher.rb', line 41

def stop_splits_thread
  SplitIoClient::Helpers::ThreadHelper.stop(:split_fetcher, @config)
end