configcat 5.0.2 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/configcat/configcache.rb +19 -4
- data/lib/configcat/configcatclient.rb +263 -107
- data/lib/configcat/configcatlogger.rb +24 -0
- data/lib/configcat/configcatoptions.rb +153 -0
- data/lib/configcat/configentry.rb +40 -0
- data/lib/configcat/configfetcher.rb +98 -40
- data/lib/configcat/configservice.rb +212 -0
- data/lib/configcat/evaluationdetails.rb +23 -0
- data/lib/configcat/interfaces.rb +4 -59
- data/lib/configcat/localdictionarydatasource.rb +14 -4
- data/lib/configcat/localfiledatasource.rb +22 -11
- data/lib/configcat/overridedatasource.rb +8 -2
- data/lib/configcat/pollingmode.rb +62 -0
- data/lib/configcat/refreshresult.rb +3 -0
- data/lib/configcat/rolloutevaluator.rb +32 -37
- data/lib/configcat/user.rb +18 -39
- data/lib/configcat/utils.rb +10 -0
- data/lib/configcat/version.rb +1 -1
- data/lib/configcat.rb +128 -136
- metadata +24 -5
- data/lib/configcat/autopollingcachepolicy.rb +0 -99
- data/lib/configcat/lazyloadingcachepolicy.rb +0 -69
- data/lib/configcat/manualpollingcachepolicy.rb +0 -47
data/lib/configcat.rb
CHANGED
@@ -6,12 +6,25 @@ require 'configcat/user'
|
|
6
6
|
require 'logger'
|
7
7
|
|
8
8
|
module ConfigCat
|
9
|
-
|
10
9
|
@logger = Logger.new(STDOUT, level: Logger::WARN)
|
11
10
|
class << self
|
12
11
|
attr_accessor :logger
|
13
12
|
end
|
14
13
|
|
14
|
+
# Creates a new or gets an already existing `ConfigCatClient` for the given `sdk_key`.
|
15
|
+
#
|
16
|
+
# :param sdk_key [String] ConfigCat SDK Key to access your configuration.
|
17
|
+
# :param options [ConfigCatOptions] Configuration `ConfigCatOptions` for `ConfigCatClient`.
|
18
|
+
# :return [ConfigCatClient] the `ConfigCatClient` instance.
|
19
|
+
def ConfigCat.get(sdk_key, options = nil)
|
20
|
+
return ConfigCatClient.get(sdk_key, options)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Closes all ConfigCatClient instances.
|
24
|
+
def ConfigCat.close_all
|
25
|
+
ConfigCatClient.close_all
|
26
|
+
end
|
27
|
+
|
15
28
|
def ConfigCat.create_client(sdk_key, data_governance: DataGovernance::GLOBAL)
|
16
29
|
#
|
17
30
|
# Create an instance of ConfigCatClient and setup Auto Poll mode with default options
|
@@ -25,171 +38,150 @@ module ConfigCat
|
|
25
38
|
return create_client_with_auto_poll(sdk_key, data_governance: data_governance)
|
26
39
|
end
|
27
40
|
|
41
|
+
# Create an instance of ConfigCatClient and setup Auto Poll mode with custom options
|
42
|
+
#
|
43
|
+
# :param sdk_key: ConfigCat SDK Key to access your configuration.
|
44
|
+
# :param poll_interval_seconds: The client's poll interval in seconds. Default: 60 seconds.
|
45
|
+
# :param on_configuration_changed_callback: You can subscribe to configuration changes with this callback
|
46
|
+
# :param max_init_wait_time_seconds: maximum waiting time for first configuration fetch in polling mode.
|
47
|
+
# :param config_cache: If you want to use custom caching instead of the client's default,
|
48
|
+
# You can provide an implementation of ConfigCache.
|
49
|
+
# :param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
|
50
|
+
# :param proxy_address: Proxy address
|
51
|
+
# :param proxy_port: Proxy port
|
52
|
+
# :param proxy_user: username for proxy authentication
|
53
|
+
# :param proxy_pass: password for proxy authentication
|
54
|
+
# :param open_timeout_seconds: The number of seconds to wait for the server to make the initial connection. Default: 10 seconds.
|
55
|
+
# :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
|
56
|
+
# :param flag_overrides: A FlagOverrides implementation used to override feature flags & settings.
|
57
|
+
# :param data_governance:
|
58
|
+
# Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
|
59
|
+
# https://app.configcat.com/organization/data-governance
|
60
|
+
# (Only Organization Admins have access)
|
28
61
|
def ConfigCat.create_client_with_auto_poll(sdk_key,
|
29
62
|
poll_interval_seconds: 60,
|
30
63
|
max_init_wait_time_seconds: 5,
|
31
64
|
on_configuration_changed_callback: nil,
|
32
|
-
|
65
|
+
config_cache: nil,
|
33
66
|
base_url: nil,
|
34
67
|
proxy_address: nil,
|
35
68
|
proxy_port: nil,
|
36
69
|
proxy_user: nil,
|
37
70
|
proxy_pass: nil,
|
38
|
-
|
39
|
-
|
71
|
+
open_timeout_seconds: 10,
|
72
|
+
read_timeout_seconds: 30,
|
40
73
|
flag_overrides: nil,
|
41
74
|
data_governance: DataGovernance::GLOBAL)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
# :param data_governance:
|
60
|
-
# Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
|
61
|
-
# https://app.configcat.com/organization/data-governance
|
62
|
-
# (Only Organization Admins have access)
|
63
|
-
#
|
64
|
-
if sdk_key === nil
|
65
|
-
raise ConfigCatClientException, "SDK Key is required."
|
66
|
-
end
|
67
|
-
if poll_interval_seconds < 1
|
68
|
-
poll_interval_seconds = 1
|
69
|
-
end
|
70
|
-
if max_init_wait_time_seconds < 0
|
71
|
-
max_init_wait_time_seconds = 0
|
72
|
-
end
|
73
|
-
return ConfigCatClient.new(sdk_key,
|
74
|
-
poll_interval_seconds: poll_interval_seconds,
|
75
|
-
max_init_wait_time_seconds: max_init_wait_time_seconds,
|
76
|
-
on_configuration_changed_callback: on_configuration_changed_callback,
|
77
|
-
cache_time_to_live_seconds: 0,
|
78
|
-
config_cache_class: config_cache_class,
|
79
|
-
base_url: base_url,
|
80
|
-
proxy_address: proxy_address,
|
81
|
-
proxy_port: proxy_port,
|
82
|
-
proxy_user: proxy_user,
|
83
|
-
proxy_pass: proxy_pass,
|
84
|
-
open_timeout: open_timeout,
|
85
|
-
read_timeout: read_timeout,
|
86
|
-
flag_overrides: flag_overrides,
|
87
|
-
data_governance: data_governance)
|
75
|
+
options = ConfigCatOptions.new(
|
76
|
+
base_url: base_url,
|
77
|
+
polling_mode: PollingMode.auto_poll(poll_interval_seconds: poll_interval_seconds, max_init_wait_time_seconds: max_init_wait_time_seconds),
|
78
|
+
config_cache: config_cache,
|
79
|
+
proxy_address: proxy_address,
|
80
|
+
proxy_port: proxy_port,
|
81
|
+
proxy_user: proxy_user,
|
82
|
+
proxy_pass: proxy_pass,
|
83
|
+
open_timeout_seconds: open_timeout_seconds,
|
84
|
+
read_timeout_seconds: read_timeout_seconds,
|
85
|
+
flag_overrides: flag_overrides,
|
86
|
+
data_governance: data_governance
|
87
|
+
)
|
88
|
+
client = ConfigCatClient.get(sdk_key, options)
|
89
|
+
client.hooks.add_on_config_changed(on_configuration_changed_callback) if on_configuration_changed_callback
|
90
|
+
client.log.warn('create_client_with_auto_poll is deprecated. Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead')
|
91
|
+
return client
|
88
92
|
end
|
89
93
|
|
94
|
+
# Create an instance of ConfigCatClient and setup Lazy Load mode with custom options
|
95
|
+
#
|
96
|
+
# :param sdk_key: ConfigCat SDK Key to access your configuration.
|
97
|
+
# :param cache_time_to_live_seconds: The cache TTL.
|
98
|
+
# :param config_cache: If you want to use custom caching instead of the client's default,
|
99
|
+
# You can provide an implementation of ConfigCache.
|
100
|
+
# :param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
|
101
|
+
# :param proxy_address: Proxy address
|
102
|
+
# :param proxy_port: Proxy port
|
103
|
+
# :param proxy_user: username for proxy authentication
|
104
|
+
# :param proxy_pass: password for proxy authentication
|
105
|
+
# :param open_timeout_seconds: The number of seconds to wait for the server to make the initial connection. Default: 10 seconds.
|
106
|
+
# :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
|
107
|
+
# :param flag_overrides: A FlagOverrides implementation used to override feature flags & settings.
|
108
|
+
# :param data_governance:
|
109
|
+
# Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
|
110
|
+
# https://app.configcat.com/organization/data-governance
|
111
|
+
# (Only Organization Admins have access)
|
90
112
|
def ConfigCat.create_client_with_lazy_load(sdk_key,
|
91
113
|
cache_time_to_live_seconds: 60,
|
92
|
-
|
114
|
+
config_cache: nil,
|
93
115
|
base_url: nil,
|
94
116
|
proxy_address: nil,
|
95
117
|
proxy_port: nil,
|
96
118
|
proxy_user: nil,
|
97
119
|
proxy_pass: nil,
|
98
|
-
|
99
|
-
|
120
|
+
open_timeout_seconds: 10,
|
121
|
+
read_timeout_seconds: 30,
|
100
122
|
flag_overrides: nil,
|
101
123
|
data_governance: DataGovernance::GLOBAL)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
# Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
|
119
|
-
# https://app.configcat.com/organization/data-governance
|
120
|
-
# (Only Organization Admins have access)
|
121
|
-
#
|
122
|
-
if sdk_key === nil
|
123
|
-
raise ConfigCatClientException, "SDK Key is required."
|
124
|
-
end
|
125
|
-
if cache_time_to_live_seconds < 1
|
126
|
-
cache_time_to_live_seconds = 1
|
127
|
-
end
|
128
|
-
return ConfigCatClient.new(sdk_key,
|
129
|
-
poll_interval_seconds: 0,
|
130
|
-
max_init_wait_time_seconds: 0,
|
131
|
-
on_configuration_changed_callback: nil,
|
132
|
-
cache_time_to_live_seconds: cache_time_to_live_seconds,
|
133
|
-
config_cache_class: config_cache_class,
|
134
|
-
base_url: base_url,
|
135
|
-
proxy_address: proxy_address,
|
136
|
-
proxy_port: proxy_port,
|
137
|
-
proxy_user: proxy_user,
|
138
|
-
proxy_pass: proxy_pass,
|
139
|
-
open_timeout: open_timeout,
|
140
|
-
read_timeout: read_timeout,
|
141
|
-
flag_overrides: flag_overrides,
|
142
|
-
data_governance: data_governance)
|
124
|
+
options = ConfigCatOptions.new(
|
125
|
+
base_url: base_url,
|
126
|
+
polling_mode: PollingMode.lazy_load(cache_refresh_interval_seconds: cache_time_to_live_seconds),
|
127
|
+
config_cache: config_cache,
|
128
|
+
proxy_address: proxy_address,
|
129
|
+
proxy_port: proxy_port,
|
130
|
+
proxy_user: proxy_user,
|
131
|
+
proxy_pass: proxy_pass,
|
132
|
+
open_timeout_seconds: open_timeout_seconds,
|
133
|
+
read_timeout_seconds: read_timeout_seconds,
|
134
|
+
flag_overrides: flag_overrides,
|
135
|
+
data_governance: data_governance
|
136
|
+
)
|
137
|
+
client = ConfigCatClient.get(sdk_key, options)
|
138
|
+
client.log.warn('create_client_with_lazy_load is deprecated. Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead')
|
139
|
+
return client
|
143
140
|
end
|
144
141
|
|
142
|
+
# Create an instance of ConfigCatClient and setup Manual Poll mode with custom options
|
143
|
+
#
|
144
|
+
# :param sdk_key: ConfigCat SDK Key to access your configuration.
|
145
|
+
# :param config_cache: If you want to use custom caching instead of the client's default,
|
146
|
+
# You can provide an implementation of ConfigCache.
|
147
|
+
# :param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
|
148
|
+
# :param proxy_address: Proxy address
|
149
|
+
# :param proxy_port: Proxy port
|
150
|
+
# :param proxy_user: username for proxy authentication
|
151
|
+
# :param proxy_pass: password for proxy authentication
|
152
|
+
# :param open_timeout_seconds: The number of seconds to wait for the server to make the initial connection. Default: 10 seconds.
|
153
|
+
# :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
|
154
|
+
# :param flag_overrides: A FlagOverrides implementation used to override feature flags & settings.
|
155
|
+
# :param data_governance:
|
156
|
+
# Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
|
157
|
+
# https://app.configcat.com/organization/data-governance
|
158
|
+
# (Only Organization Admins have access)
|
145
159
|
def ConfigCat.create_client_with_manual_poll(sdk_key,
|
146
|
-
|
160
|
+
config_cache: nil,
|
147
161
|
base_url: nil,
|
148
162
|
proxy_address: nil,
|
149
163
|
proxy_port: nil,
|
150
164
|
proxy_user: nil,
|
151
165
|
proxy_pass: nil,
|
152
|
-
|
153
|
-
|
166
|
+
open_timeout_seconds: 10,
|
167
|
+
read_timeout_seconds: 30,
|
154
168
|
flag_overrides: nil,
|
155
169
|
data_governance: DataGovernance::GLOBAL)
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
# https://app.configcat.com/organization/data-governance
|
173
|
-
# (Only Organization Admins have access)
|
174
|
-
#
|
175
|
-
if sdk_key === nil
|
176
|
-
raise ConfigCatClientException, "SDK Key is required."
|
177
|
-
end
|
178
|
-
return ConfigCatClient.new(sdk_key,
|
179
|
-
poll_interval_seconds: 0,
|
180
|
-
max_init_wait_time_seconds: 0,
|
181
|
-
on_configuration_changed_callback: nil,
|
182
|
-
cache_time_to_live_seconds: 0,
|
183
|
-
config_cache_class: config_cache_class,
|
184
|
-
base_url: base_url,
|
185
|
-
proxy_address: proxy_address,
|
186
|
-
proxy_port: proxy_port,
|
187
|
-
proxy_user: proxy_user,
|
188
|
-
proxy_pass: proxy_pass,
|
189
|
-
open_timeout: open_timeout,
|
190
|
-
read_timeout: read_timeout,
|
191
|
-
flag_overrides: flag_overrides,
|
192
|
-
data_governance: data_governance)
|
170
|
+
options = ConfigCatOptions.new(
|
171
|
+
base_url: base_url,
|
172
|
+
polling_mode: PollingMode.manual_poll(),
|
173
|
+
config_cache: config_cache,
|
174
|
+
proxy_address: proxy_address,
|
175
|
+
proxy_port: proxy_port,
|
176
|
+
proxy_user: proxy_user,
|
177
|
+
proxy_pass: proxy_pass,
|
178
|
+
open_timeout_seconds: open_timeout_seconds,
|
179
|
+
read_timeout_seconds: read_timeout_seconds,
|
180
|
+
flag_overrides: flag_overrides,
|
181
|
+
data_governance: data_governance
|
182
|
+
)
|
183
|
+
client = ConfigCatClient.get(sdk_key, options)
|
184
|
+
client.log.warn('create_client_with_manual_poll is deprecated. Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead')
|
185
|
+
return client
|
193
186
|
end
|
194
|
-
|
195
|
-
end
|
187
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configcat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ConfigCat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Feature Flags created by developers for developers with ❤️. ConfigCat
|
98
112
|
lets you manage feature flags across frontend, backend, mobile, and desktop apps
|
99
113
|
without (re)deploying code. % rollouts, user targeting, segmentation. Feature toggle
|
@@ -106,20 +120,25 @@ extensions: []
|
|
106
120
|
extra_rdoc_files: []
|
107
121
|
files:
|
108
122
|
- lib/configcat.rb
|
109
|
-
- lib/configcat/autopollingcachepolicy.rb
|
110
123
|
- lib/configcat/configcache.rb
|
111
124
|
- lib/configcat/configcatclient.rb
|
125
|
+
- lib/configcat/configcatlogger.rb
|
126
|
+
- lib/configcat/configcatoptions.rb
|
127
|
+
- lib/configcat/configentry.rb
|
112
128
|
- lib/configcat/configfetcher.rb
|
129
|
+
- lib/configcat/configservice.rb
|
113
130
|
- lib/configcat/constants.rb
|
114
131
|
- lib/configcat/datagovernance.rb
|
132
|
+
- lib/configcat/evaluationdetails.rb
|
115
133
|
- lib/configcat/interfaces.rb
|
116
|
-
- lib/configcat/lazyloadingcachepolicy.rb
|
117
134
|
- lib/configcat/localdictionarydatasource.rb
|
118
135
|
- lib/configcat/localfiledatasource.rb
|
119
|
-
- lib/configcat/manualpollingcachepolicy.rb
|
120
136
|
- lib/configcat/overridedatasource.rb
|
137
|
+
- lib/configcat/pollingmode.rb
|
138
|
+
- lib/configcat/refreshresult.rb
|
121
139
|
- lib/configcat/rolloutevaluator.rb
|
122
140
|
- lib/configcat/user.rb
|
141
|
+
- lib/configcat/utils.rb
|
123
142
|
- lib/configcat/version.rb
|
124
143
|
homepage: https://configcat.com
|
125
144
|
licenses:
|
@@ -1,99 +0,0 @@
|
|
1
|
-
require 'configcat/interfaces'
|
2
|
-
require 'configcat/constants'
|
3
|
-
require 'concurrent'
|
4
|
-
|
5
|
-
module ConfigCat
|
6
|
-
class AutoPollingCachePolicy < CachePolicy
|
7
|
-
def initialize(config_fetcher, config_cache, cache_key, poll_interval_seconds=60, max_init_wait_time_seconds=5, on_configuration_changed_callback=nil)
|
8
|
-
if poll_interval_seconds < 1
|
9
|
-
poll_interval_seconds = 1
|
10
|
-
end
|
11
|
-
if max_init_wait_time_seconds < 0
|
12
|
-
max_init_wait_time_seconds = 0
|
13
|
-
end
|
14
|
-
@_config_fetcher = config_fetcher
|
15
|
-
@_config_cache = config_cache
|
16
|
-
@_cache_key = cache_key
|
17
|
-
@_poll_interval_seconds = poll_interval_seconds
|
18
|
-
@_max_init_wait_time_seconds = max_init_wait_time_seconds
|
19
|
-
@_on_configuration_changed_callback = on_configuration_changed_callback
|
20
|
-
@_initialized = false
|
21
|
-
@_is_running = false
|
22
|
-
@_start_time = Time.now.utc
|
23
|
-
@_lock = Concurrent::ReadWriteLock.new()
|
24
|
-
@_is_started = Concurrent::Event.new()
|
25
|
-
@thread = Thread.new{_run()}
|
26
|
-
@_is_started.wait()
|
27
|
-
end
|
28
|
-
|
29
|
-
def _run()
|
30
|
-
@_is_running = true
|
31
|
-
@_is_started.set()
|
32
|
-
loop do
|
33
|
-
force_refresh()
|
34
|
-
sleep(@_poll_interval_seconds)
|
35
|
-
break if !@_is_running
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def get()
|
40
|
-
while !@_initialized && (Time.now.utc < @_start_time + @_max_init_wait_time_seconds)
|
41
|
-
sleep(0.5)
|
42
|
-
end
|
43
|
-
begin
|
44
|
-
@_lock.acquire_read_lock()
|
45
|
-
return @_config_cache.get(@_cache_key)
|
46
|
-
ensure
|
47
|
-
@_lock.release_read_lock()
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def force_refresh()
|
52
|
-
begin
|
53
|
-
configuration_response = @_config_fetcher.get_configuration_json()
|
54
|
-
|
55
|
-
begin
|
56
|
-
@_lock.acquire_read_lock()
|
57
|
-
old_configuration = @_config_cache.get(@_cache_key)
|
58
|
-
ensure
|
59
|
-
@_lock.release_read_lock()
|
60
|
-
end
|
61
|
-
|
62
|
-
if configuration_response.is_fetched()
|
63
|
-
configuration = configuration_response.json()
|
64
|
-
if configuration != old_configuration
|
65
|
-
begin
|
66
|
-
@_lock.acquire_write_lock()
|
67
|
-
@_config_cache.set(@_cache_key, configuration)
|
68
|
-
@_initialized = true
|
69
|
-
ensure
|
70
|
-
@_lock.release_write_lock()
|
71
|
-
end
|
72
|
-
begin
|
73
|
-
if !@_on_configuration_changed_callback.equal?(nil)
|
74
|
-
@_on_configuration_changed_callback.()
|
75
|
-
end
|
76
|
-
rescue Exception => e
|
77
|
-
ConfigCat.logger.error("Exception in on_configuration_changed_callback: #{e.class}:'#{e}'")
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
if !@_initialized && !old_configuration.equal?(nil)
|
83
|
-
@_initialized = true
|
84
|
-
end
|
85
|
-
rescue Timeout::Error => e
|
86
|
-
ConfigCat.logger.error("Request timed out. Timeout values: [open: %ss, read: %ss]" %
|
87
|
-
[@_config_fetcher.get_open_timeout(), @_config_fetcher.get_read_timeout()])
|
88
|
-
rescue Exception => e
|
89
|
-
ConfigCat.logger.error("Double-check your SDK Key at https://app.configcat.com/sdkkey.")
|
90
|
-
ConfigCat.logger.error "threw exception #{e.class}:'#{e}'"
|
91
|
-
ConfigCat.logger.error "stacktrace: #{e.backtrace}"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def stop()
|
96
|
-
@_is_running = false
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'configcat/interfaces'
|
2
|
-
require 'configcat/constants'
|
3
|
-
require 'concurrent'
|
4
|
-
|
5
|
-
|
6
|
-
module ConfigCat
|
7
|
-
class LazyLoadingCachePolicy < CachePolicy
|
8
|
-
|
9
|
-
def initialize(config_fetcher, config_cache, cache_key, cache_time_to_live_seconds=60)
|
10
|
-
if cache_time_to_live_seconds < 1
|
11
|
-
cache_time_to_live_seconds = 1
|
12
|
-
end
|
13
|
-
@_config_fetcher = config_fetcher
|
14
|
-
@_config_cache = config_cache
|
15
|
-
@_cache_key = cache_key
|
16
|
-
@_cache_time_to_live = cache_time_to_live_seconds
|
17
|
-
@_lock = Concurrent::ReadWriteLock.new()
|
18
|
-
@_last_updated = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def get()
|
22
|
-
begin
|
23
|
-
@_lock.acquire_read_lock()
|
24
|
-
utc_now = Time.now.utc
|
25
|
-
if !@_last_updated.equal?(nil) && (@_last_updated + @_cache_time_to_live > utc_now)
|
26
|
-
config = @_config_cache.get(@_cache_key)
|
27
|
-
if !config.equal?(nil)
|
28
|
-
return config
|
29
|
-
end
|
30
|
-
end
|
31
|
-
ensure
|
32
|
-
@_lock.release_read_lock()
|
33
|
-
end
|
34
|
-
force_refresh()
|
35
|
-
begin
|
36
|
-
@_lock.acquire_read_lock()
|
37
|
-
config = @_config_cache.get(@_cache_key)
|
38
|
-
return config
|
39
|
-
ensure
|
40
|
-
@_lock.release_read_lock()
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def force_refresh()
|
45
|
-
begin
|
46
|
-
configuration_response = @_config_fetcher.get_configuration_json()
|
47
|
-
if configuration_response.is_fetched()
|
48
|
-
configuration = configuration_response.json()
|
49
|
-
begin
|
50
|
-
@_lock.acquire_write_lock()
|
51
|
-
@_config_cache.set(@_cache_key, configuration)
|
52
|
-
@_last_updated = Time.now.utc
|
53
|
-
ensure
|
54
|
-
@_lock.release_write_lock()
|
55
|
-
end
|
56
|
-
end
|
57
|
-
rescue StandardError => e
|
58
|
-
ConfigCat.logger.error("Double-check your SDK Key at https://app.configcat.com/sdkkey.")
|
59
|
-
ConfigCat.logger.error "threw exception #{e.class}:'#{e}'"
|
60
|
-
ConfigCat.logger.error "stacktrace: #{e.backtrace}"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def stop()
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'configcat/interfaces'
|
2
|
-
require 'configcat/constants'
|
3
|
-
require 'concurrent'
|
4
|
-
|
5
|
-
module ConfigCat
|
6
|
-
class ManualPollingCachePolicy < CachePolicy
|
7
|
-
def initialize(config_fetcher, config_cache, cache_key)
|
8
|
-
@_config_fetcher = config_fetcher
|
9
|
-
@_config_cache = config_cache
|
10
|
-
@_cache_key = cache_key
|
11
|
-
@_lock = Concurrent::ReadWriteLock.new()
|
12
|
-
end
|
13
|
-
|
14
|
-
def get()
|
15
|
-
begin
|
16
|
-
@_lock.acquire_read_lock()
|
17
|
-
config = @_config_cache.get(@_cache_key)
|
18
|
-
return config
|
19
|
-
ensure
|
20
|
-
@_lock.release_read_lock()
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def force_refresh()
|
25
|
-
begin
|
26
|
-
configuration_response = @_config_fetcher.get_configuration_json()
|
27
|
-
if configuration_response.is_fetched()
|
28
|
-
configuration = configuration_response.json()
|
29
|
-
begin
|
30
|
-
@_lock.acquire_write_lock()
|
31
|
-
@_config_cache.set(@_cache_key, configuration)
|
32
|
-
ensure
|
33
|
-
@_lock.release_write_lock()
|
34
|
-
end
|
35
|
-
end
|
36
|
-
rescue StandardError => e
|
37
|
-
ConfigCat.logger.error("Double-check your SDK Key at https://app.configcat.com/sdkkey.")
|
38
|
-
ConfigCat.logger.error "threw exception #{e.class}:'#{e}'"
|
39
|
-
ConfigCat.logger.error "stacktrace: #{e.backtrace}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def stop()
|
44
|
-
# pass
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|