Class: SplitIoClient::Engine::Impressions::UniqueKeysTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-rb/engine/impressions/unique_keys_tracker.rb

Constant Summary collapse

INTERVAL_TO_CLEAR_LONG_TERM_CACHE =

24 hours

86_400

Instance Method Summary collapse

Constructor Details

#initialize(config, filter_adapter, sender_adapter, cache) ⇒ UniqueKeysTracker

Returns a new instance of UniqueKeysTracker.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/splitclient-rb/engine/impressions/unique_keys_tracker.rb', line 9

def initialize(config,
               filter_adapter,
               sender_adapter,
               cache)
  @config = config
  @filter_adapter = filter_adapter
  @sender_adapter = sender_adapter
  @cache = cache
  @cache_max_size = config.unique_keys_cache_max_size
  @max_bulk_size = config.unique_keys_bulk_size
  @semaphore = Mutex.new
end

Instance Method Details

#callObject



22
23
24
25
# File 'lib/splitclient-rb/engine/impressions/unique_keys_tracker.rb', line 22

def call
  @config.threads[:unique_keys_sender] = Thread.new { send_bulk_data_thread }
  @config.threads[:clear_filter] = Thread.new { clear_filter_thread }
end

#track(feature_name, key) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/splitclient-rb/engine/impressions/unique_keys_tracker.rb', line 27

def track(feature_name, key)
  return false if @filter_adapter.contains?(feature_name, key)

  @filter_adapter.add(feature_name, key)

  add_or_update(feature_name, key)

  send_bulk_data if @cache.size >= @cache_max_size

  true
rescue StandardError => e
  @config.log_found_exception(__method__.to_s, e)
  false
end