-
Notifications
You must be signed in to change notification settings - Fork 28
fix(blocking-api): fixed issue related to default blocking-timeout and blocking API methods. #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -39,5 +38,9 @@ def initialize(datafile, logger, error_handler, skip_json_validation) | |||
skip_json_validation | |||
) | |||
end | |||
|
|||
def get_config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, this should be defined in the projectconfigmanager as an abstract method. right now i can see config is defined in the projectconfig manager.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please respond to get_config
, rest of the stuff will review after that.
# Get Project Config. | ||
|
||
# If the background datafile polling thread is running. and config has been initalized, | ||
# we simply return config. | ||
# If it is not, we wait and block maximum for @blocking_timeout. | ||
# If thread is not running, we fetch the datafile and update config. | ||
return nil if @closed == true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have to return nil
in this case? Is there a problem with just returning the current @config
? Also, why @closed == true
instead of @closed
?
@@ -243,7 +245,7 @@ def blocking_timeout(blocking_timeout) | |||
Logger::DEBUG, | |||
"Blocking timeout is not provided. Defaulting to #{Helpers::Constants::CONFIG_MANAGER['DEFAULT_BLOCKING_TIMEOUT']} seconds." | |||
) | |||
@polling_interval = Helpers::Constants::CONFIG_MANAGER['DEFAULT_BLOCKING_TIMEOUT'] | |||
@blocking_timeout = Helpers::Constants::CONFIG_MANAGER['DEFAULT_BLOCKING_TIMEOUT'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ensure that there is test coverage that would have revealed these places where it should have been @blocking_timeout
, but was actually @polling_interval
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -105,13 +105,15 @@ def stop! | |||
@closed = true | |||
end | |||
|
|||
def get_config | |||
def config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why you are defining config not get_config, unable to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following ruby's convention.
Please view rubocop's rule https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Naming/AccessorMethodName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stumpled upon this, too. Not even your own StaticProjectConfigManager is using get_config
which makes it unusable here:
Lines 85 to 88 in 31e93c7
@config_manager = if config_manager.respond_to?(:get_config) | |
config_manager | |
elsif sdk_key | |
HTTPProjectConfigManager.new( |
@msohailhussain Could you please review and approve if this looks good to you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. please address minor nits.
# Get Project Config. | ||
|
||
# If the background datafile polling thread is running. and config has been initalized, | ||
# we simply return config. | ||
# If it is not, we wait and block maximum for @blocking_timeout. | ||
# If thread is not running, we fetch the datafile and update config. | ||
return @config if @closed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msohailhussain I agree that stopped
is a better attribute name.
README.md
Outdated
@@ -44,7 +44,7 @@ You can initialize the Optimizely instance in two ways: directly with a datafile | |||
|
|||
When the `datafile` is given then it will be used initially before any update. | |||
|
|||
2. Initialize Optimizely by providing a Config Manager that implements a 'get_config' method. You can customize our `HTTPConfigManager` as needed. | |||
2. Initialize Optimizely by providing a Config Manager that implements a 'config' method. You can customize our `HTTPConfigManager` as needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use config
lib/optimizely/helpers/constants.rb
Outdated
@@ -362,7 +362,7 @@ module Constants | |||
|
|||
CONFIG_MANAGER = { | |||
'DATAFILE_URL_TEMPLATE' => 'https://cdn.optimizely.com/datafiles/%s.json', | |||
# Default time in seconds to block the get_config call until config has been initialized. | |||
# Default time in seconds to block the config method call until config has been initialized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config
or 'config'
lib/optimizely/optimizely_factory.rb
Outdated
@@ -29,7 +29,7 @@ def self.default_instance(sdk_key, datafile = nil) | |||
|
|||
# Returns a new optimizely instance. | |||
# | |||
# @param config_manager - Required ConfigManagerInterface Responds to get_config. | |||
# @param config_manager - Required ConfigManagerInterface Responds to config method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please single quote. am saying config should be more focused as method name.
Summary
blocking_timeout
is set to default.blocking_timeout
period or datafile is not loaded successfulsy.