Use a defer.gatherResults to collect results from the perspective servers

This commit is contained in:
Mark Haines 2015-04-29 13:31:14 +01:00
parent a9549fdce3
commit 1319905d7a

View File

@ -124,18 +124,28 @@ class Keyring(object):
@defer.inlineCallbacks @defer.inlineCallbacks
def _get_server_verify_key_impl(self, server_name, key_ids): def _get_server_verify_key_impl(self, server_name, key_ids):
keys = None keys = None
perspective_results = []
for perspective_name, perspective_keys in self.perspective_servers.items(): for perspective_name, perspective_keys in self.perspective_servers.items():
@defer.inlineCallbacks
def get_key():
try: try:
keys = yield self.get_server_verify_key_v2_indirect( result = yield self.get_server_verify_key_v2_indirect(
server_name, key_ids, perspective_name, perspective_keys server_name, key_ids, perspective_name, perspective_keys
) )
break defer.returnValue(result)
except: except:
logging.info( logging.info(
"Unable to getting key %r for %r from %r", "Unable to getting key %r for %r from %r",
key_ids, server_name, perspective_name, key_ids, server_name, perspective_name,
) )
pass perspective_results.append(get_key())
perspective_results = yield defer.gatherResults(perspective_results)
for results in perspective_results:
if results is not None:
keys = results
limiter = yield get_retry_limiter( limiter = yield get_retry_limiter(
server_name, server_name,