Skip to content
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

feat: Add blocking timeout in polling manager #211

Merged
merged 6 commits into from
Oct 9, 2019

Conversation

rashidsp
Copy link
Contributor

@rashidsp rashidsp commented Sep 23, 2019

Summary

This introduces blocking timeout in Python Config Manager. Config Manager will block the main thread until the config is available or the timeout occurs.

https://github.com/optimizely/python-testapp/pull/63 should be merged to pass FSC tests for this PR.

Copy link
Contributor

@oakbani oakbani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice pick threading.condition. Please address comments and add unit tests.

@@ -145,6 +146,9 @@ def get_config(self):
Returns:
ProjectConfig. None if not set.
"""
self._condition.acquire()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only be doing this for the first time. See Ruby.

self.last_modified = None
self._polling_thread = threading.Thread(target=self._run)
self._polling_thread.setDaemon(True)
self._polling_thread.start()
self._condition = threading.Condition()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will have to put this inside static config manager since you use it in it's method.

Args:
blocking_timeout: Time in seconds to block the config call.
"""
if not blocking_timeout:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. Check if it's None. Otherwise, this will be true when blocking_timeout is 0

"""
if not blocking_timeout:
blocking_timeout = enums.ConfigManager.DEFAULT_BLOCKING_TIMEOUT
self.logger.debug('Set config blocking timeout to default value {}.'.format(blocking_timeout))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. See log in Ruby

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. Setting

blocking_timeout = enums.ConfigManager.DEFAULT_BLOCKING_TIMEOUT
self.logger.debug('Set config blocking timeout to default value {}.'.format(blocking_timeout))

if not isinstance(blocking_timeout, (int, float)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use numbers.Integral instead of int. This will cover long for Python 2 as well

)

# If blocking timeout is less than or equal to 0 then set it to default blocking timeout.
if blocking_timeout <= 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why haven't you enforced MIN and MAX limit as in Ruby SDK?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel 0 should be allowed as a value if people are not interested in blocking.

@oakbani
Copy link
Contributor

oakbani commented Sep 24, 2019

@coveralls
Copy link

coveralls commented Sep 26, 2019

Coverage Status

Coverage decreased (-0.09%) to 97.765% when pulling 5cbf39d on rashid/dfm-blocking-timeout into 3731be4 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 98.282% when pulling 4bb2cfb on rashid/dfm-blocking-timeout into 6794260 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 98.282% when pulling 4bb2cfb on rashid/dfm-blocking-timeout into 6794260 on master.

@oakbani oakbani changed the title Added blocking timeout in polling manager feat: Add blocking timeout in polling manager Sep 26, 2019
@oakbani oakbani marked this pull request as ready for review September 26, 2019 12:36
@oakbani oakbani requested a review from a team as a code owner September 26, 2019 12:36
@@ -95,6 +96,7 @@ def __init__(self,
notification_center=notification_center)
self._config = None
self.validate_schema = not skip_json_validation
self._configReadyEvent = threading.Event()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this camelCased when (almost) the entirety of this SDK is snake cased?

"""
if not blocking_timeout:
blocking_timeout = enums.ConfigManager.DEFAULT_BLOCKING_TIMEOUT
self.logger.debug('Set config blocking timeout to default value {}.'.format(blocking_timeout))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. Setting

)

# If blocking timeout is less than or equal to 0 then set it to default blocking timeout.
if blocking_timeout <= 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel 0 should be allowed as a value if people are not interested in blocking.

@@ -133,6 +135,7 @@ def _set_config(self, datafile):
return

self._config = config
self._configReadyEvent.set()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the effect of calling set() twice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No effect. It will make the already 'true' internal flag to 'true' again. Once an event has been set, all the threads which wait for the events do not block until .clear() has been called on the event, which makes the internal flag false.

@@ -38,6 +38,8 @@ class AudienceEvaluationLogs(object):

class ConfigManager(object):
DATAFILE_URL_TEMPLATE = 'https://cdn.optimizely.com/datafiles/{sdk_key}.json'
# Default time in seconds to block the 'get_config' method call until 'config' instance has been initialized.
DEFAULT_BLOCKING_TIMEOUT = 15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this 10 seconds.

@oakbani oakbani dismissed their stale review September 27, 2019 05:06

I am doing it now

Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aliabbasrizvi aliabbasrizvi merged commit 22437a7 into master Oct 9, 2019
@aliabbasrizvi aliabbasrizvi deleted the rashid/dfm-blocking-timeout branch October 9, 2019 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants