Skip to content

feat: Add blocking timeout in polling manager - #211

Merged
Ali Abbas Rizvi (aliabbasrizvi) merged 6 commits into
masterfrom
rashid/dfm-blocking-timeout
Oct 9, 2019
Merged

Ali Abbas Rizvi (aliabbasrizvi) merged 6 commits into
masterfrom
rashid/dfm-blocking-timeout

Conversation

@rashidsp

@rashidsp Rashid Siddique (rashidsp) commented Sep 23, 2019 •

Copy link
Copy Markdown
Contributor

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.

@oakbani Owais Akbani (oakbani) left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread optimizely/config_manager.py Outdated
Returns:
ProjectConfig. None if not set.
"""
self._condition.acquire()

Copy link
Copy Markdown
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.

Comment thread optimizely/config_manager.py Outdated
self._polling_thread = threading.Thread(target=self._run)
self._polling_thread.setDaemon(True)
self._polling_thread.start()
self._condition = threading.Condition()

Copy link
Copy Markdown
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.

Comment thread optimizely/config_manager.py Outdated
Args:
blocking_timeout: Time in seconds to block the config call.
"""
if not blocking_timeout:

Copy link
Copy Markdown
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

Comment thread optimizely/config_manager.py Outdated
"""
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit. Setting

Comment thread optimizely/config_manager.py Outdated
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
Copy Markdown
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

Comment thread optimizely/config_manager.py Outdated
)

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

@coveralls

Coveralls (coveralls) commented Sep 26, 2019 •

Copy link
Copy Markdown

Coverage Status

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

@coveralls

Copy link
Copy Markdown

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
Copy Markdown

Coverage Status

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

@oakbani Owais Akbani (oakbani) changed the title Added blocking timeout in polling manager feat: Add blocking timeout in polling manager Sep 26, 2019
@oakbani
Owais Akbani (oakbani) marked this pull request as ready for review September 26, 2019 12:36
@oakbani
Owais Akbani (oakbani) requested a review from a team as a code owner September 26, 2019 12:36
Comment thread optimizely/config_manager.py Outdated
notification_center=notification_center)
self._config = None
self.validate_schema = not skip_json_validation
self._configReadyEvent = threading.Event()

Copy link
Copy Markdown
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?

Comment thread optimizely/config_manager.py Outdated
"""
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit. Setting

Comment thread optimizely/config_manager.py Outdated
)

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

Copy link
Copy Markdown
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.

Comment thread optimizely/config_manager.py Outdated
return

self._config = config
self._configReadyEvent.set()

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread optimizely/helpers/enums.py Outdated
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
Copy Markdown
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@aliabbasrizvi
Ali Abbas Rizvi (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.

5 participants