Properly catch multiple exceptions.

This commit is contained in:
Jake Moshenko 2015-02-27 17:32:10 -05:00
parent ca5c34e00a
commit cf5bc6f0be

View file

@ -144,7 +144,7 @@ class EphemeralBuilderManager(BaseManager):
for realm in all_realms.children: for realm in all_realms.children:
if not realm.dir: if not realm.dir:
self._register_realm(json.loads(realm.value)) self._register_realm(json.loads(realm.value))
except KeyError, etcd.KeyError: except (KeyError, etcd.KeyError):
# no realms have been registered yet # no realms have been registered yet
pass pass
@ -207,7 +207,7 @@ class EphemeralBuilderManager(BaseManager):
try: try:
building = yield From(self._etcd_client.read(self._etcd_builder_prefix, recursive=True)) building = yield From(self._etcd_client.read(self._etcd_builder_prefix, recursive=True))
workers_alive = sum(1 for child in building.children if not child.dir) workers_alive = sum(1 for child in building.children if not child.dir)
except KeyError, etcd.KeyError: except (KeyError, etcd.KeyError):
workers_alive = 0 workers_alive = 0
except etcd.EtcdException: except etcd.EtcdException:
logger.exception('Exception when reading job count from etcd') logger.exception('Exception when reading job count from etcd')
@ -238,7 +238,7 @@ class EphemeralBuilderManager(BaseManager):
try: try:
yield From(self._etcd_client.write(job_key, json.dumps(payload), prevExist=False, ttl=ttl)) yield From(self._etcd_client.write(job_key, json.dumps(payload), prevExist=False, ttl=ttl))
except KeyError, etcd.KeyError: except (KeyError, etcd.KeyError):
# The job was already taken by someone else, we are probably a retry # The job was already taken by someone else, we are probably a retry
logger.error('Job already exists in etcd, are timeouts misconfigured or is the queue broken?') logger.error('Job already exists in etcd, are timeouts misconfigured or is the queue broken?')
raise Return(False) raise Return(False)
@ -273,7 +273,7 @@ class EphemeralBuilderManager(BaseManager):
try: try:
yield From(self._etcd_client.write(self._etcd_realm_key(realm), realm_spec, prevExist=False, yield From(self._etcd_client.write(self._etcd_realm_key(realm), realm_spec, prevExist=False,
ttl=ttl)) ttl=ttl))
except KeyError, etcd.KeyError: except (KeyError, etcd.KeyError):
logger.error('Realm already exists in etcd. UUID collision or something is very very wrong.') logger.error('Realm already exists in etcd. UUID collision or something is very very wrong.')
raise Return(False) raise Return(False)
except etcd.EtcdException: except etcd.EtcdException:
@ -293,7 +293,7 @@ class EphemeralBuilderManager(BaseManager):
logger.debug('Sending build %s to newly ready component on realm %s', logger.debug('Sending build %s to newly ready component on realm %s',
job.job_details['build_uuid'], build_component.builder_realm) job.job_details['build_uuid'], build_component.builder_realm)
yield From(build_component.start_build(job)) yield From(build_component.start_build(job))
except KeyError, etcd.KeyError: except (KeyError, etcd.KeyError):
logger.debug('Builder is asking for more work, but work already completed') logger.debug('Builder is asking for more work, but work already completed')
def build_component_disposed(self, build_component, timed_out): def build_component_disposed(self, build_component, timed_out):