Skip to content

Commit

Permalink
fixed issue #541, also fixed same issue in clonesrv6.py
Browse files Browse the repository at this point in the history
  • Loading branch information
lulupac committed Sep 16, 2015
1 parent 918efb2 commit 4e4634b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions examples/Python/clonesrv5.py
Expand Up @@ -109,8 +109,8 @@ def handle_collect(self, msg):
self.sequence += 1
kvmsg.sequence = self.sequence
kvmsg.send(self.publisher)
ttl = kvmsg.get('ttl')
if ttl is not None:
ttl = float(kvmsg.get('ttl', 0))
if ttl:
kvmsg['ttl'] = time.time() + ttl
kvmsg.store(self.kvmap)
logging.info("I: publishing update=%d", self.sequence)
Expand All @@ -123,7 +123,8 @@ def flush_ttl(self):
def flush_single(self, kvmsg):
"""If key-value pair has expired, delete it and publish the fact
to listening clients."""
if kvmsg.get('ttl', 0) <= time.time():
ttl = float(kvmsg.get('ttl', 0))
if ttl and ttl <= time.time():
kvmsg.body = ""
self.sequence += 1
kvmsg.sequence = self.sequence
Expand Down
10 changes: 5 additions & 5 deletions examples/Python/clonesrv6.py
Expand Up @@ -142,7 +142,7 @@ def handle_collect(self, msg):
self.sequence += 1
kvmsg.sequence = self.sequence
kvmsg.send(self.publisher)
ttl = int(kvmsg.get('ttl'))
ttl = float(kvmsg.get('ttl', 0))
if ttl:
kvmsg['ttl'] = time.time() + ttl
kvmsg.store(self.kvmap)
Expand Down Expand Up @@ -175,7 +175,7 @@ def flush_ttl(self):
def flush_single(self, kvmsg):
"""If key-value pair has expired, delete it and publish the fact
to listening clients."""
ttl = int(kvmsg.get('ttl'))
ttl = float(kvmsg.get('ttl', 0))
if ttl and ttl <= time.time():
kvmsg.body = ""
self.sequence += 1
Expand Down Expand Up @@ -256,9 +256,9 @@ def handle_subscriber(self, msg):

# Find and remove update off pending list
kvmsg = KVMsg.from_msg(msg)
# update integer ttl -> timestamp
ttl = int(kvmsg.get('ttl'))
if ttl is not None:
# update float ttl -> timestamp
ttl = float(kvmsg.get('ttl', 0))
if ttl:
kvmsg['ttl'] = time.time() + ttl

if kvmsg.key != "HUGZ":
Expand Down

0 comments on commit 4e4634b

Please sign in to comment.