splitclient-rb 6.4.1.pre.rc3-java → 7.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.txt +15 -1
- data/Detailed-README.md +9 -21
- data/NEWS +3 -0
- data/lib/splitclient-rb.rb +2 -1
- data/lib/splitclient-rb/cache/adapters/cache_adapter.rb +3 -3
- data/lib/splitclient-rb/cache/repositories/events/memory_repository.rb +5 -4
- data/lib/splitclient-rb/cache/repositories/events/redis_repository.rb +4 -3
- data/lib/splitclient-rb/cache/repositories/events_repository.rb +10 -9
- data/lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb +7 -6
- data/lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb +5 -4
- data/lib/splitclient-rb/cache/repositories/impressions_repository.rb +9 -8
- data/lib/splitclient-rb/cache/repositories/metrics/memory_repository.rb +3 -2
- data/lib/splitclient-rb/cache/repositories/metrics/redis_repository.rb +5 -4
- data/lib/splitclient-rb/cache/repositories/metrics_repository.rb +6 -4
- data/lib/splitclient-rb/cache/repositories/repository.rb +7 -2
- data/lib/splitclient-rb/cache/repositories/segments_repository.rb +6 -5
- data/lib/splitclient-rb/cache/repositories/splits_repository.rb +56 -14
- data/lib/splitclient-rb/cache/routers/impression_router.rb +5 -4
- data/lib/splitclient-rb/cache/senders/events_sender.rb +7 -6
- data/lib/splitclient-rb/cache/senders/impressions_sender.rb +10 -9
- data/lib/splitclient-rb/cache/senders/metrics_sender.rb +9 -8
- data/lib/splitclient-rb/cache/stores/sdk_blocker.rb +19 -10
- data/lib/splitclient-rb/cache/stores/segment_store.rb +15 -28
- data/lib/splitclient-rb/cache/stores/split_store.rb +13 -15
- data/lib/splitclient-rb/clients/localhost_split_client.rb +8 -7
- data/lib/splitclient-rb/clients/split_client.rb +65 -35
- data/lib/splitclient-rb/engine/api/client.rb +17 -13
- data/lib/splitclient-rb/engine/api/events.rb +7 -6
- data/lib/splitclient-rb/engine/api/impressions.rb +6 -5
- data/lib/splitclient-rb/engine/api/metrics.rb +8 -7
- data/lib/splitclient-rb/engine/api/segments.rb +11 -10
- data/lib/splitclient-rb/engine/api/splits.rb +6 -5
- data/lib/splitclient-rb/engine/matchers/all_keys_matcher.rb +1 -1
- data/lib/splitclient-rb/engine/matchers/between_matcher.rb +7 -5
- data/lib/splitclient-rb/engine/matchers/combining_matcher.rb +5 -4
- data/lib/splitclient-rb/engine/matchers/contains_all_matcher.rb +4 -4
- data/lib/splitclient-rb/engine/matchers/contains_any_matcher.rb +3 -3
- data/lib/splitclient-rb/engine/matchers/contains_matcher.rb +7 -5
- data/lib/splitclient-rb/engine/matchers/dependency_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/ends_with_matcher.rb +5 -4
- data/lib/splitclient-rb/engine/matchers/equal_to_boolean_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/equal_to_matcher.rb +6 -4
- data/lib/splitclient-rb/engine/matchers/equal_to_set_matcher.rb +3 -3
- data/lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_matcher.rb +6 -4
- data/lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb +6 -4
- data/lib/splitclient-rb/engine/matchers/matcher.rb +4 -0
- data/lib/splitclient-rb/engine/matchers/matches_string_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/negation_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/part_of_set_matcher.rb +4 -4
- data/lib/splitclient-rb/engine/matchers/set_matcher.rb +2 -1
- data/lib/splitclient-rb/engine/matchers/starts_with_matcher.rb +4 -3
- data/lib/splitclient-rb/engine/matchers/user_defined_segment_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/whitelist_matcher.rb +7 -5
- data/lib/splitclient-rb/engine/models/label.rb +2 -0
- data/lib/splitclient-rb/engine/parser/condition.rb +31 -20
- data/lib/splitclient-rb/engine/parser/evaluator.rb +3 -2
- data/lib/splitclient-rb/engine/parser/split_adapter.rb +9 -7
- data/lib/splitclient-rb/localhost_split_factory.rb +3 -2
- data/lib/splitclient-rb/managers/split_manager.rb +39 -5
- data/lib/splitclient-rb/redis_metrics_fixer.rb +5 -4
- data/lib/splitclient-rb/split_config.rb +35 -14
- data/lib/splitclient-rb/split_factory.rb +44 -32
- data/lib/splitclient-rb/split_factory_builder.rb +4 -5
- data/lib/splitclient-rb/split_factory_registry.rb +51 -0
- data/lib/splitclient-rb/split_logger.rb +5 -14
- data/lib/splitclient-rb/validators.rb +19 -16
- data/lib/splitclient-rb/version.rb +1 -1
- metadata +5 -4
@@ -6,14 +6,15 @@ module SplitIoClient
|
|
6
6
|
|
7
7
|
attr_reader :adapter
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
9
|
+
def initialize(config)
|
10
|
+
super(config)
|
11
|
+
@adapter = case @config.cache_adapter.class.to_s
|
11
12
|
when 'SplitIoClient::Cache::Adapters::RedisAdapter'
|
12
|
-
SplitIoClient::Cache::Adapters::CacheAdapter.new(
|
13
|
+
SplitIoClient::Cache::Adapters::CacheAdapter.new(@config)
|
13
14
|
else
|
14
|
-
|
15
|
+
@config.cache_adapter
|
15
16
|
end
|
16
|
-
@adapter.set_bool(namespace_key('.ready'), false) unless
|
17
|
+
@adapter.set_bool(namespace_key('.ready'), false) unless @config.mode.equal?(:consumer)
|
17
18
|
end
|
18
19
|
|
19
20
|
# Receives segment data, adds and removes segements from the store
|
@@ -6,14 +6,16 @@ module SplitIoClient
|
|
6
6
|
class SplitsRepository < Repository
|
7
7
|
attr_reader :adapter
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
9
|
+
def initialize(config)
|
10
|
+
super(config)
|
11
|
+
@tt_cache = {}
|
12
|
+
@adapter = case @config.cache_adapter.class.to_s
|
11
13
|
when 'SplitIoClient::Cache::Adapters::RedisAdapter'
|
12
|
-
SplitIoClient::Cache::Adapters::CacheAdapter.new(
|
14
|
+
SplitIoClient::Cache::Adapters::CacheAdapter.new(@config)
|
13
15
|
else
|
14
|
-
|
16
|
+
@config.cache_adapter
|
15
17
|
end
|
16
|
-
unless
|
18
|
+
unless @config.mode.equal?(:consumer)
|
17
19
|
@adapter.set_string(namespace_key('.splits.till'), '-1')
|
18
20
|
@adapter.initialize_map(namespace_key('.segments.registered'))
|
19
21
|
end
|
@@ -21,15 +23,27 @@ module SplitIoClient
|
|
21
23
|
|
22
24
|
def add_split(split)
|
23
25
|
return unless split[:name]
|
26
|
+
existing_split = get_split(split[:name])
|
27
|
+
|
28
|
+
if(!existing_split)
|
29
|
+
increase_tt_name_count(split[:trafficTypeName])
|
30
|
+
elsif(existing_split[:trafficTypeName] != split[:trafficTypeName])
|
31
|
+
increase_tt_name_count(split[:trafficTypeName])
|
32
|
+
decrease_tt_name_count(existing_split[:trafficTypeName])
|
33
|
+
end
|
24
34
|
|
25
35
|
@adapter.set_string(namespace_key(".split.#{split[:name]}"), split.to_json)
|
26
36
|
end
|
27
37
|
|
28
|
-
def remove_split(
|
29
|
-
|
38
|
+
def remove_split(split)
|
39
|
+
tt_name = split[:trafficTypeName]
|
40
|
+
|
41
|
+
decrease_tt_name_count(split[:trafficTypeName])
|
42
|
+
|
43
|
+
@adapter.delete(namespace_key(".split.#{split[:name]}"))
|
30
44
|
end
|
31
45
|
|
32
|
-
def get_splits(names)
|
46
|
+
def get_splits(names, symbolize_names = true)
|
33
47
|
splits = {}
|
34
48
|
split_names = names.map { |name| namespace_key(".split.#{name}") }
|
35
49
|
splits.merge!(
|
@@ -40,7 +54,8 @@ module SplitIoClient
|
|
40
54
|
|
41
55
|
splits.map do |name, data|
|
42
56
|
parsed_data = data ? JSON.parse(data, symbolize_names: true) : nil
|
43
|
-
|
57
|
+
split_name = symbolize_names ? name.to_sym : name
|
58
|
+
[split_name, parsed_data]
|
44
59
|
end.to_h
|
45
60
|
end
|
46
61
|
|
@@ -51,13 +66,22 @@ module SplitIoClient
|
|
51
66
|
end
|
52
67
|
|
53
68
|
def splits
|
54
|
-
|
69
|
+
get_splits(split_names, false)
|
70
|
+
end
|
55
71
|
|
56
|
-
|
57
|
-
|
72
|
+
def traffic_type_exists(tt_name)
|
73
|
+
case @adapter
|
74
|
+
when SplitIoClient::Cache::Adapters::CacheAdapter
|
75
|
+
tt_count = @adapter.string(namespace_key(".trafficType.#{tt_name}"))
|
76
|
+
begin
|
77
|
+
!tt_count.nil? && Integer(tt_count, 10) > 0
|
78
|
+
rescue StandardError => e
|
79
|
+
@config.logger.error("Error while parsing Traffic Type count: #{e.message}")
|
80
|
+
false
|
81
|
+
end
|
82
|
+
else
|
83
|
+
@tt_cache.key?(tt_name) && @tt_cache[tt_name] > 0
|
58
84
|
end
|
59
|
-
|
60
|
-
splits_hash
|
61
85
|
end
|
62
86
|
|
63
87
|
# Return an array of Split Names excluding control keys like splits.till
|
@@ -99,8 +123,26 @@ module SplitIoClient
|
|
99
123
|
end
|
100
124
|
|
101
125
|
def clear
|
126
|
+
@tt_cache.clear
|
127
|
+
|
102
128
|
@adapter.clear(namespace_key)
|
103
129
|
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def increase_tt_name_count(tt_name)
|
134
|
+
return unless tt_name
|
135
|
+
|
136
|
+
@tt_cache[tt_name] = 0 unless @tt_cache[tt_name]
|
137
|
+
@tt_cache[tt_name] += 1
|
138
|
+
end
|
139
|
+
|
140
|
+
def decrease_tt_name_count(tt_name)
|
141
|
+
return unless tt_name
|
142
|
+
|
143
|
+
@tt_cache[tt_name] -= 1 if @tt_cache[tt_name]
|
144
|
+
@tt_cache.delete(tt_name) if @tt_cache[tt_name] == 0
|
145
|
+
end
|
104
146
|
end
|
105
147
|
end
|
106
148
|
end
|
@@ -2,8 +2,9 @@ module SplitIoClient
|
|
2
2
|
class ImpressionRouter
|
3
3
|
attr_reader :router_thread
|
4
4
|
|
5
|
-
def initialize
|
6
|
-
@
|
5
|
+
def initialize(config)
|
6
|
+
@config = config
|
7
|
+
@listener = @config.impression_listener
|
7
8
|
|
8
9
|
return unless @listener
|
9
10
|
|
@@ -44,12 +45,12 @@ module SplitIoClient
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def router_thread
|
47
|
-
|
48
|
+
@config.threads[:impression_router] = Thread.new do
|
48
49
|
loop do
|
49
50
|
begin
|
50
51
|
@listener.log(@queue.pop)
|
51
52
|
rescue StandardError => error
|
52
|
-
|
53
|
+
@config.log_found_exception(__method__.to_s, error)
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
@@ -4,8 +4,9 @@ module SplitIoClient
|
|
4
4
|
module Cache
|
5
5
|
module Senders
|
6
6
|
class EventsSender
|
7
|
-
def initialize(events_repository)
|
7
|
+
def initialize(events_repository, config)
|
8
8
|
@events_repository = events_repository
|
9
|
+
@config = config
|
9
10
|
end
|
10
11
|
|
11
12
|
def call
|
@@ -25,19 +26,19 @@ module SplitIoClient
|
|
25
26
|
private
|
26
27
|
|
27
28
|
def events_thread
|
28
|
-
|
29
|
+
@config.threads[:events_sender] = Thread.new do
|
29
30
|
begin
|
30
|
-
|
31
|
-
|
31
|
+
@config.logger.info('Starting events service')
|
32
|
+
|
32
33
|
loop do
|
33
34
|
post_events
|
34
35
|
|
35
|
-
sleep(SplitIoClient::Utilities.randomize_interval(
|
36
|
+
sleep(SplitIoClient::Utilities.randomize_interval(@config.events_push_rate))
|
36
37
|
end
|
37
38
|
rescue SplitIoClient::SDKShutdownException
|
38
39
|
post_events
|
39
40
|
|
40
|
-
|
41
|
+
@config.logger.info('Posting events due to shutdown')
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
@@ -4,14 +4,15 @@ module SplitIoClient
|
|
4
4
|
module Cache
|
5
5
|
module Senders
|
6
6
|
class ImpressionsSender
|
7
|
-
def initialize(impressions_repository, api_key)
|
7
|
+
def initialize(impressions_repository, api_key, config)
|
8
8
|
@impressions_repository = impressions_repository
|
9
9
|
@api_key = api_key
|
10
|
+
@config = config
|
10
11
|
end
|
11
12
|
|
12
13
|
def call
|
13
|
-
if
|
14
|
-
|
14
|
+
if @config.disable_impressions
|
15
|
+
@config.logger.info('Disabling impressions service by config')
|
15
16
|
return
|
16
17
|
end
|
17
18
|
|
@@ -31,19 +32,19 @@ module SplitIoClient
|
|
31
32
|
private
|
32
33
|
|
33
34
|
def impressions_thread
|
34
|
-
|
35
|
+
@config.threads[:impressions_sender] = Thread.new do
|
35
36
|
begin
|
36
|
-
|
37
|
+
@config.logger.info('Starting impressions service')
|
37
38
|
|
38
39
|
loop do
|
39
40
|
post_impressions(false)
|
40
41
|
|
41
|
-
sleep(SplitIoClient::Utilities.randomize_interval(
|
42
|
+
sleep(SplitIoClient::Utilities.randomize_interval(@config.impressions_refresh_rate))
|
42
43
|
end
|
43
44
|
rescue SplitIoClient::SDKShutdownException
|
44
45
|
post_impressions
|
45
46
|
|
46
|
-
|
47
|
+
@config.logger.info('Posting impressions due to shutdown')
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
@@ -54,11 +55,11 @@ module SplitIoClient
|
|
54
55
|
|
55
56
|
impressions_api.post(formatted_impressions)
|
56
57
|
rescue StandardError => error
|
57
|
-
|
58
|
+
@config.log_found_exception(__method__.to_s, error)
|
58
59
|
end
|
59
60
|
|
60
61
|
def impressions_api
|
61
|
-
@impressions_api ||= SplitIoClient::Api::Impressions.new(@api_key)
|
62
|
+
@impressions_api ||= SplitIoClient::Api::Impressions.new(@api_key, @config)
|
62
63
|
end
|
63
64
|
end
|
64
65
|
end
|
@@ -4,9 +4,10 @@ module SplitIoClient
|
|
4
4
|
module Cache
|
5
5
|
module Senders
|
6
6
|
class MetricsSender
|
7
|
-
def initialize(metrics_repository, api_key)
|
7
|
+
def initialize(metrics_repository, api_key, config)
|
8
8
|
@metrics_repository = metrics_repository
|
9
9
|
@api_key = api_key
|
10
|
+
@config = config
|
10
11
|
end
|
11
12
|
|
12
13
|
def call
|
@@ -24,19 +25,19 @@ module SplitIoClient
|
|
24
25
|
private
|
25
26
|
|
26
27
|
def metrics_thread
|
27
|
-
|
28
|
+
@config.threads[:metrics_sender] = Thread.new do
|
28
29
|
begin
|
29
|
-
|
30
|
-
|
30
|
+
@config.logger.info('Starting metrics service')
|
31
|
+
|
31
32
|
loop do
|
32
33
|
post_metrics
|
33
34
|
|
34
|
-
sleep(SplitIoClient::Utilities.randomize_interval(
|
35
|
+
sleep(SplitIoClient::Utilities.randomize_interval(@config.metrics_refresh_rate))
|
35
36
|
end
|
36
37
|
rescue SplitIoClient::SDKShutdownException
|
37
38
|
post_metrics
|
38
39
|
|
39
|
-
|
40
|
+
@config.logger.info('Posting metrics due to shutdown')
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
@@ -44,11 +45,11 @@ module SplitIoClient
|
|
44
45
|
def post_metrics
|
45
46
|
metrics_api.post
|
46
47
|
rescue StandardError => error
|
47
|
-
|
48
|
+
@config.log_found_exception(__method__.to_s, error)
|
48
49
|
end
|
49
50
|
|
50
51
|
def metrics_api
|
51
|
-
@metrics_api ||= SplitIoClient::Api::Metrics.new(@api_key, @metrics_repository)
|
52
|
+
@metrics_api ||= SplitIoClient::Api::Metrics.new(@api_key, @metrics_repository, @config)
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
@@ -7,37 +7,46 @@ module SplitIoClient
|
|
7
7
|
class SDKBlocker
|
8
8
|
attr_reader :splits_repository
|
9
9
|
|
10
|
-
def initialize(splits_repository, segments_repository)
|
10
|
+
def initialize(splits_repository, segments_repository, config)
|
11
11
|
@splits_repository = splits_repository
|
12
12
|
@segments_repository = segments_repository
|
13
|
+
@config = config
|
13
14
|
|
14
|
-
@
|
15
|
-
|
15
|
+
if @config.standalone?
|
16
|
+
@splits_repository.not_ready!
|
17
|
+
@segments_repository.not_ready!
|
18
|
+
end
|
16
19
|
end
|
17
20
|
|
18
21
|
def splits_ready!
|
19
|
-
|
22
|
+
if !ready?
|
23
|
+
@splits_repository.ready!
|
24
|
+
@config.logger.info('splits are ready')
|
25
|
+
end
|
20
26
|
end
|
21
27
|
|
22
28
|
def segments_ready!
|
23
|
-
|
29
|
+
if !ready?
|
30
|
+
@segments_repository.ready!
|
31
|
+
@config.logger.info('segments are ready')
|
32
|
+
end
|
24
33
|
end
|
25
34
|
|
26
|
-
def block
|
35
|
+
def block(time = nil)
|
27
36
|
begin
|
28
|
-
|
37
|
+
timeout = time || @config.block_until_ready
|
38
|
+
Timeout::timeout(timeout) do
|
29
39
|
sleep 0.1 until ready?
|
30
40
|
end
|
31
41
|
rescue Timeout::Error
|
32
42
|
fail SDKBlockerTimeoutExpiredException, 'SDK start up timeout expired'
|
33
43
|
end
|
34
44
|
|
35
|
-
|
36
|
-
SplitIoClient.configuration.threads[:split_store].run
|
37
|
-
SplitIoClient.configuration.threads[:segment_store].run
|
45
|
+
@config.logger.info('SplitIO SDK is ready')
|
38
46
|
end
|
39
47
|
|
40
48
|
def ready?
|
49
|
+
return true if @config.consumer?
|
41
50
|
@splits_repository.ready? && @segments_repository.ready?
|
42
51
|
end
|
43
52
|
end
|
@@ -4,10 +4,11 @@ module SplitIoClient
|
|
4
4
|
class SegmentStore
|
5
5
|
attr_reader :segments_repository
|
6
6
|
|
7
|
-
def initialize(segments_repository, api_key, metrics, sdk_blocker = nil)
|
7
|
+
def initialize(segments_repository, api_key, metrics, config, sdk_blocker = nil)
|
8
8
|
@segments_repository = segments_repository
|
9
9
|
@api_key = api_key
|
10
10
|
@metrics = metrics
|
11
|
+
@config = config
|
11
12
|
@sdk_blocker = sdk_blocker
|
12
13
|
end
|
13
14
|
|
@@ -28,42 +29,28 @@ module SplitIoClient
|
|
28
29
|
private
|
29
30
|
|
30
31
|
def segments_thread
|
31
|
-
|
32
|
-
|
33
|
-
SplitIoClient.configuration.block_until_ready > 0 ? blocked_store : unblocked_store
|
34
|
-
end
|
35
|
-
end
|
32
|
+
@config.threads[:segment_store] = Thread.new do
|
33
|
+
@config.logger.info('Starting segments fetcher service')
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
next unless @sdk_blocker.splits_repository.ready?
|
35
|
+
loop do
|
36
|
+
next unless @sdk_blocker.splits_repository.ready?
|
40
37
|
|
41
|
-
|
42
|
-
|
38
|
+
store_segments
|
39
|
+
@config.logger.debug("Segment names: #{@segments_repository.used_segment_names.to_a}") if @config.debug_enabled
|
43
40
|
|
44
|
-
|
45
|
-
@
|
46
|
-
|
41
|
+
sleep_for = random_interval(@config.segments_refresh_rate)
|
42
|
+
@config.logger.debug("Segments store is sleeping for: #{sleep_for} seconds") if @config.debug_enabled
|
43
|
+
sleep(sleep_for)
|
47
44
|
end
|
48
|
-
|
49
|
-
sleep_for = random_interval(SplitIoClient.configuration.segments_refresh_rate)
|
50
|
-
SplitIoClient.configuration.logger.debug("Segments store is sleeping for: #{sleep_for} seconds") if SplitIoClient.configuration.debug_enabled
|
51
|
-
sleep(sleep_for)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def unblocked_store
|
56
|
-
loop do
|
57
|
-
store_segments
|
58
|
-
|
59
|
-
sleep(random_interval(SplitIoClient.configuration.segments_refresh_rate))
|
60
45
|
end
|
61
46
|
end
|
62
47
|
|
63
48
|
def store_segments
|
64
49
|
segments_api.store_segments_by_names(@segments_repository.used_segment_names)
|
50
|
+
|
51
|
+
@sdk_blocker.segments_ready!
|
65
52
|
rescue StandardError => error
|
66
|
-
|
53
|
+
@config.log_found_exception(__method__.to_s, error)
|
67
54
|
end
|
68
55
|
|
69
56
|
def random_interval(interval)
|
@@ -73,7 +60,7 @@ module SplitIoClient
|
|
73
60
|
end
|
74
61
|
|
75
62
|
def segments_api
|
76
|
-
@segments_api ||= SplitIoClient::Api::Segments.new(@api_key, @metrics, @segments_repository)
|
63
|
+
@segments_api ||= SplitIoClient::Api::Segments.new(@api_key, @metrics, @segments_repository, @config)
|
77
64
|
end
|
78
65
|
end
|
79
66
|
end
|
@@ -4,10 +4,11 @@ module SplitIoClient
|
|
4
4
|
class SplitStore
|
5
5
|
attr_reader :splits_repository
|
6
6
|
|
7
|
-
def initialize(splits_repository, api_key, metrics, sdk_blocker = nil)
|
7
|
+
def initialize(splits_repository, api_key, metrics, config, sdk_blocker = nil)
|
8
8
|
@splits_repository = splits_repository
|
9
9
|
@api_key = api_key
|
10
10
|
@metrics = metrics
|
11
|
+
@config = config
|
11
12
|
@sdk_blocker = sdk_blocker
|
12
13
|
end
|
13
14
|
|
@@ -28,12 +29,12 @@ module SplitIoClient
|
|
28
29
|
private
|
29
30
|
|
30
31
|
def splits_thread
|
31
|
-
|
32
|
-
|
32
|
+
@config.threads[:split_store] = Thread.new do
|
33
|
+
@config.logger.info('Starting splits fetcher service')
|
33
34
|
loop do
|
34
35
|
store_splits
|
35
36
|
|
36
|
-
sleep(random_interval(
|
37
|
+
sleep(random_interval(@config.features_refresh_rate))
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
@@ -48,15 +49,12 @@ module SplitIoClient
|
|
48
49
|
@splits_repository.set_segment_names(data[:segment_names])
|
49
50
|
@splits_repository.set_change_number(data[:till])
|
50
51
|
|
51
|
-
|
52
|
+
@config.logger.debug("segments seen(#{data[:segment_names].length}): #{data[:segment_names].to_a}") if @config.debug_enabled
|
52
53
|
|
53
|
-
|
54
|
-
@sdk_blocker.splits_ready!
|
55
|
-
SplitIoClient.configuration.logger.info('splits are ready')
|
56
|
-
end
|
54
|
+
@sdk_blocker.splits_ready!
|
57
55
|
|
58
56
|
rescue StandardError => error
|
59
|
-
|
57
|
+
@config.log_found_exception(__method__.to_s, error)
|
60
58
|
end
|
61
59
|
|
62
60
|
def random_interval(interval)
|
@@ -71,7 +69,7 @@ module SplitIoClient
|
|
71
69
|
|
72
70
|
def add_split_unless_archived(split)
|
73
71
|
if Engine::Models::Split.archived?(split)
|
74
|
-
|
72
|
+
@config.logger.debug("Seeing archived split #{split[:name]}") if @config.debug_enabled
|
75
73
|
|
76
74
|
remove_archived_split(split)
|
77
75
|
else
|
@@ -80,13 +78,13 @@ module SplitIoClient
|
|
80
78
|
end
|
81
79
|
|
82
80
|
def remove_archived_split(split)
|
83
|
-
|
81
|
+
@config.logger.debug("removing split from store(#{split})") if @config.debug_enabled
|
84
82
|
|
85
|
-
@splits_repository.remove_split(split
|
83
|
+
@splits_repository.remove_split(split)
|
86
84
|
end
|
87
85
|
|
88
86
|
def store_split(split)
|
89
|
-
|
87
|
+
@config.logger.debug("storing split (#{split[:name]})") if @config.debug_enabled
|
90
88
|
|
91
89
|
@splits_repository.add_split(split)
|
92
90
|
end
|
@@ -94,7 +92,7 @@ module SplitIoClient
|
|
94
92
|
private
|
95
93
|
|
96
94
|
def splits_api
|
97
|
-
@splits_api ||= SplitIoClient::Api::Splits.new(@api_key, @metrics)
|
95
|
+
@splits_api ||= SplitIoClient::Api::Splits.new(@api_key, @metrics, @config)
|
98
96
|
end
|
99
97
|
end
|
100
98
|
end
|