mirror of
https://github.com/internetarchive/warcprox.git
synced 2025-01-18 13:22:09 +01:00
standardize the concept of 'now' to ensure that the same view of the service is returned from the read and update queries.
This commit is contained in:
parent
501ec1ff23
commit
78c26186b0
@ -222,6 +222,8 @@ class ServiceRegistry(object):
|
|||||||
'''
|
'''
|
||||||
if candidate is not None:
|
if candidate is not None:
|
||||||
candidate['id'] = role
|
candidate['id'] = role
|
||||||
|
# use the same concept of 'now' for both queries
|
||||||
|
now = rr.now().run()
|
||||||
|
|
||||||
if not 'heartbeat_interval' in candidate:
|
if not 'heartbeat_interval' in candidate:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
@ -231,8 +233,8 @@ class ServiceRegistry(object):
|
|||||||
if not (isinstance(val, float) or isinstance(val, int)) or val <= 0:
|
if not (isinstance(val, float) or isinstance(val, int)) or val <= 0:
|
||||||
raise Exception('heartbeat_interval must be a number > 0')
|
raise Exception('heartbeat_interval must be a number > 0')
|
||||||
|
|
||||||
candidate['first_heartbeat'] = r.now()
|
candidate['first_heartbeat'] = now
|
||||||
candidate['last_heartbeat'] = r.now()
|
candidate['last_heartbeat'] = now
|
||||||
if not 'host' in candidate:
|
if not 'host' in candidate:
|
||||||
candidate['host'] = socket.gethostname()
|
candidate['host'] = socket.gethostname()
|
||||||
if not 'pid' in candidate:
|
if not 'pid' in candidate:
|
||||||
@ -243,7 +245,7 @@ class ServiceRegistry(object):
|
|||||||
lambda row: r.branch(
|
lambda row: r.branch(
|
||||||
r.branch(
|
r.branch(
|
||||||
row,
|
row,
|
||||||
row['last_heartbeat'] > r.now() - row['heartbeat_interval'] * 3,
|
row['last_heartbeat'] > now - row['heartbeat_interval'] * 3,
|
||||||
False),
|
False),
|
||||||
row, candidate),
|
row, candidate),
|
||||||
return_changes='always').run()
|
return_changes='always').run()
|
||||||
@ -256,7 +258,7 @@ class ServiceRegistry(object):
|
|||||||
|
|
||||||
results = list(self.rr.table(
|
results = list(self.rr.table(
|
||||||
'services', read_mode='majority').get_all(role).filter(
|
'services', read_mode='majority').get_all(role).filter(
|
||||||
lambda row: row['last_heartbeat'] > r.now() - row['heartbeat_interval'] * 3).run())
|
lambda row: row['last_heartbeat'] > now - row['heartbeat_interval'] * 3).run())
|
||||||
if results:
|
if results:
|
||||||
return results[0]
|
return results[0]
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user