Class: SplitIoClient::Cache::Fetchers::SegmentFetcher
- Inherits:
-
Object
- Object
- SplitIoClient::Cache::Fetchers::SegmentFetcher
- Defined in:
- lib/splitclient-rb/cache/fetchers/segment_fetcher.rb
Instance Attribute Summary collapse
-
#segments_repository ⇒ Object
readonly
Returns the value of attribute segments_repository.
Instance Method Summary collapse
- #call ⇒ Object
- #fetch_segment(name, fetch_options = { cache_control_headers: false, till: nil }) ⇒ Object
- #fetch_segments ⇒ Object
- #fetch_segments_if_not_exists(names, cache_control_headers = false) ⇒ Object
-
#initialize(segments_repository, api_key, config, telemetry_runtime_producer) ⇒ SegmentFetcher
constructor
A new instance of SegmentFetcher.
- #stop_segments_thread ⇒ Object
Constructor Details
#initialize(segments_repository, api_key, config, telemetry_runtime_producer) ⇒ SegmentFetcher
Returns a new instance of SegmentFetcher.
7 8 9 10 11 12 13 |
# File 'lib/splitclient-rb/cache/fetchers/segment_fetcher.rb', line 7 def initialize(segments_repository, api_key, config, telemetry_runtime_producer) @segments_repository = segments_repository @api_key = api_key @config = config @semaphore = Mutex.new @telemetry_runtime_producer = telemetry_runtime_producer end |
Instance Attribute Details
#segments_repository ⇒ Object (readonly)
Returns the value of attribute segments_repository.
5 6 7 |
# File 'lib/splitclient-rb/cache/fetchers/segment_fetcher.rb', line 5 def segments_repository @segments_repository end |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/splitclient-rb/cache/fetchers/segment_fetcher.rb', line 15 def call if ENV['SPLITCLIENT_ENV'] == 'test' fetch_segments return end segments_thread end |
#fetch_segment(name, fetch_options = { cache_control_headers: false, till: nil }) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/splitclient-rb/cache/fetchers/segment_fetcher.rb', line 37 def fetch_segment(name, = { cache_control_headers: false, till: nil }) @semaphore.synchronize do segments_api.fetch_segments_by_names([name], ) end rescue StandardError => e @config.log_found_exception(__method__.to_s, e) end |
#fetch_segments ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/splitclient-rb/cache/fetchers/segment_fetcher.rb', line 45 def fetch_segments @semaphore.synchronize do segments_api.fetch_segments_by_names(@segments_repository.used_segment_names) true end rescue StandardError => e @config.log_found_exception(__method__.to_s, e) false end |
#fetch_segments_if_not_exists(names, cache_control_headers = false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/splitclient-rb/cache/fetchers/segment_fetcher.rb', line 24 def fetch_segments_if_not_exists(names, cache_control_headers = false) names.each do |name| change_number = @segments_repository.get_change_number(name) if change_number == -1 = { cache_control_headers: cache_control_headers, till: nil } fetch_segment(name, ) if change_number == -1 end end rescue StandardError => e @config.log_found_exception(__method__.to_s, e) end |
#stop_segments_thread ⇒ Object
56 57 58 |
# File 'lib/splitclient-rb/cache/fetchers/segment_fetcher.rb', line 56 def stop_segments_thread SplitIoClient::Helpers::ThreadHelper.stop(:segment_fetcher, @config) end |