Skip to content

Commit abb7899

Browse files
authored
fix: fix local evaluation poller interval issue (#26)
1 parent 04995c6 commit abb7899

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

lib/experiment/local/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(api_key, config = nil)
2020
Logger::INFO
2121
end
2222
@fetcher = LocalEvaluationFetcher.new(api_key, @config.debug, @config.server_url)
23-
@poller = FlagConfigPoller.new(@fetcher, @cache, @config.debug)
23+
@poller = FlagConfigPoller.new(@fetcher, @cache, @config.debug, @config.flag_config_polling_interval_millis)
2424

2525
raise ArgumentError, 'Experiment API key is empty' if @api_key.nil? || @api_key.empty?
2626
end

lib/experiment/local/config.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class LocalEvaluationConfig
2424
# @param [String] server_url The server endpoint from which to request variants.
2525
# @param [Hash] bootstrap The value of bootstrap.
2626
# @param [long] flag_config_polling_interval_millis The value of flag config polling interval in million seconds.
27-
def initialize(server_url = DEFAULT_SERVER_URL, bootstrap = {},
28-
flag_config_polling_interval_millis = 30_000, debug: false)
27+
def initialize(server_url: DEFAULT_SERVER_URL, bootstrap: {},
28+
flag_config_polling_interval_millis: 30_000, debug: false)
2929
@debug = debug || false
3030
@server_url = server_url
3131
@bootstrap = bootstrap

lib/experiment/local/poller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module AmplitudeExperiment
44
class FlagConfigPoller
55
FLAG_CONFIG_POLLING_INTERVAL_MILLIS = 30_000
66

7-
def initialize(fetcher, cache, debug, poll_interval_millis: FLAG_CONFIG_POLLING_INTERVAL_MILLIS)
7+
def initialize(fetcher, cache, debug, poll_interval_millis = FLAG_CONFIG_POLLING_INTERVAL_MILLIS)
88
@fetcher = fetcher
99
@cache = cache
1010
@poll_interval_millis = poll_interval_millis
@@ -40,7 +40,7 @@ def run
4040
@cache.clear
4141
@cache.put_all(flag_configs)
4242
@poller_thread = Thread.new do
43-
sleep @poll_interval_millis
43+
sleep(@poll_interval_millis / 1000.to_f)
4444
run
4545
end
4646
end

spec/experiment/local/client_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module AmplitudeExperiment
1818

1919
describe '#evaluation' do
2020
it 'evaluation should return variant empty object with invalid user input' do
21-
local_evaluation_client = LocalEvaluationClient.new(SERVER_API_KEY)
21+
local_evaluation_client = LocalEvaluationClient.new(SERVER_API_KEY, LocalEvaluationConfig.new(flag_config_polling_interval_millis: 15_000))
2222
result = local_evaluation_client.evaluate({}, [])
2323
expect(result).to eq({})
2424
end

0 commit comments

Comments
 (0)