diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2015-01-29 17:43:59 -0800 |
---|---|---|
committer | Julien Danjou <julien@danjou.info> | 2015-03-25 15:00:28 +0100 |
commit | 49220c6cfaa40b7db75d4e0a52d66e0fe377e122 (patch) | |
tree | ca00589a82260b040f4471fb956ecfaf0b78499e | |
parent | 20033a7660f692b9e8e58f144942ee25eb9f4a05 (diff) | |
download | tooz-49220c6cfaa40b7db75d4e0a52d66e0fe377e122.tar.gz |
Avoid re-using the same timeout for further watcher ops
Instead of re-using the same timeout that is passed into the
'run_watchers' function we should adjust that timeout after
each fetch so that the expected timeout the user gives to this
function is observed.
Change-Id: I5d171b1ac8b207213224f4e0f3909625de7275db
(cherry picked from commit e38a29f67180cb40a0b7915305bec62ed9527229)
-rw-r--r-- | tooz/drivers/redis.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/tooz/drivers/redis.py b/tooz/drivers/redis.py index 76b29f4..f52d36a 100644 --- a/tooz/drivers/redis.py +++ b/tooz/drivers/redis.py @@ -20,6 +20,11 @@ import contextlib from distutils import version import logging +try: + from time import monotonic as _now # noqa +except ImportError: + from time import time as _now # noqa + from concurrent import futures from oslo_utils import strutils import redis @@ -664,10 +669,17 @@ class RedisDriver(coordination.CoordinationDriver): raise tooz.NotImplemented def run_watchers(self, timeout=None): + if timeout is not None: + started_at = _now() result = [] for group_id in self.get_groups().get(timeout=timeout): + leftover_timeout = None + if timeout is not None: + elapsed = max(0.0, _now() - started_at) + leftover_timeout = timeout - elapsed try: - group_members = self.get_members(group_id).get(timeout=timeout) + group_members = self.get_members(group_id).get( + timeout=leftover_timeout) except coordination.GroupNotCreated: group_members = set() else: |