use new index "role" in service registry

This commit is contained in:
Noah Levitt 2017-09-06 17:25:35 -07:00
parent 43cbcdf644
commit 03e641549e
2 changed files with 7 additions and 7 deletions

View File

@ -110,7 +110,7 @@ class ServiceRegistry(object):
self.rr.table_create(
'services', shards=1,
replicas=min(3, len(self.rr.servers))).run()
# self.rr.table('services').index_create...?
self.rr.table('services').index_create('role').run()
def heartbeat(self, status_info):
'''
@ -218,7 +218,7 @@ class ServiceRegistry(object):
the unique service, if there is one and it is healthy, otherwise
None
'''
# use the same concept of 'now' for all queries
# use the same concept of 'now' for all queries
now = doublethink.utcnow()
if candidate is not None:
candidate['id'] = role
@ -275,9 +275,9 @@ class ServiceRegistry(object):
value of 'load'
'''
try:
result = self.rr.table('services').filter({"role":role}).filter(
lambda svc: r.now().sub(svc["last_heartbeat"]) < svc["ttl"]
).order_by("load")[0].run()
result = self.rr.table('services').get_all(role, index='role').filter(
lambda svc: r.now().sub(svc["last_heartbeat"]) < svc["ttl"]
).order_by("load")[0].run()
return result
except r.ReqlNonExistenceError:
return None
@ -300,7 +300,7 @@ class ServiceRegistry(object):
try:
query = self.rr.table('services')
if role:
query = query.filter({"role":role})
query = query.get_all(role, index='role')
query = query.filter(
lambda svc: r.now().sub(svc["last_heartbeat"]) < svc["ttl"] #.default(20.0)
).order_by("load")

View File

@ -3,7 +3,7 @@ import codecs
setuptools.setup(
name='doublethink',
version='0.2.0.dev83',
version='0.2.0.dev84',
packages=['doublethink'],
classifiers=[
'Programming Language :: Python :: 2.7',