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, api_key, metrics, config, sdk_blocker = nil) ⇒ SplitFetcher

Returns a new instance of SplitFetcher.



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

def initialize(splits_repository, api_key, metrics, config, sdk_blocker = nil)
  @splits_repository = splits_repository
  @api_key = api_key
  @metrics = metrics
  @config = config
  @sdk_blocker = sdk_blocker
  @semaphore = Mutex.new
end

Instance Attribute Details

#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
24
25
26
27
28
# File 'lib/splitclient-rb/cache/fetchers/split_fetcher.rb', line 16

def call
  if ENV['SPLITCLIENT_ENV'] == 'test'
    fetch_splits
  else
    splits_thread

    if defined?(PhusionPassenger)
      PhusionPassenger.on_event(:starting_worker_process) do |forked|
        splits_thread if forked
      end
    end
  end
end

#fetch_splitsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/splitclient-rb/cache/fetchers/split_fetcher.rb', line 30

def fetch_splits
  @semaphore.synchronize do
    data = splits_since(@splits_repository.get_change_number)

    data[:splits] && data[:splits].each do |split|
      add_split_unless_archived(split)
    end

    @splits_repository.set_segment_names(data[:segment_names])
    @splits_repository.set_change_number(data[:till])

    @config.logger.debug("segments seen(#{data[:segment_names].length}): #{data[:segment_names].to_a}") if @config.debug_enabled

    @sdk_blocker.splits_ready!

    data[:segment_names]
  end
rescue StandardError => error
  @config.log_found_exception(__method__.to_s, error)
end

#stop_splits_threadObject



51
52
53
# File 'lib/splitclient-rb/cache/fetchers/split_fetcher.rb', line 51

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