Add RDSAwareHealthCheck
as alias for ProductionHealthCheck
This commit is contained in:
parent
685dd1a925
commit
45fe46d619
1 changed files with 13 additions and 10 deletions
|
@ -67,7 +67,7 @@ class HealthCheck(object):
|
|||
parameters = app.config['HEALTH_CHECKER'][1] or {}
|
||||
|
||||
for subc in cls.__subclasses__():
|
||||
if subc.check_name() == name:
|
||||
if name in subc.check_names():
|
||||
return subc(app, config_provider, **parameters)
|
||||
|
||||
raise Exception('Unknown health check with name %s' % name)
|
||||
|
@ -75,20 +75,22 @@ class HealthCheck(object):
|
|||
|
||||
class LocalHealthCheck(HealthCheck):
|
||||
@classmethod
|
||||
def check_name(cls):
|
||||
return 'LocalHealthCheck'
|
||||
def check_names(cls):
|
||||
return ['LocalHealthCheck']
|
||||
|
||||
|
||||
class ProductionHealthCheck(HealthCheck):
|
||||
def __init__(self, app, config_provider, access_key, secret_key, db_instance='quay'):
|
||||
super(ProductionHealthCheck, self).__init__(app, config_provider, ['redis'])
|
||||
class RDSAwareHealthCheck(HealthCheck):
|
||||
def __init__(self, app, config_provider, access_key, secret_key, db_instance='quay',
|
||||
region='us-east-1'):
|
||||
super(RDSAwareHealthCheck, self).__init__(app, config_provider, ['redis'])
|
||||
self.access_key = access_key
|
||||
self.secret_key = secret_key
|
||||
self.db_instance = db_instance
|
||||
self.region = region
|
||||
|
||||
@classmethod
|
||||
def check_name(cls):
|
||||
return 'ProductionHealthCheck'
|
||||
def check_names(cls):
|
||||
return ['RDSAwareHealthCheck', 'ProductionHealthCheck']
|
||||
|
||||
def get_instance_health(self, service_statuses):
|
||||
# Note: We skip the redis check because if redis is down, we don't want ELB taking the
|
||||
|
@ -115,8 +117,9 @@ class ProductionHealthCheck(HealthCheck):
|
|||
def _get_rds_status(self):
|
||||
""" Returns the status of the RDS instance as reported by AWS. """
|
||||
try:
|
||||
region = boto.rds2.connect_to_region('us-east-1',
|
||||
aws_access_key_id=self.access_key, aws_secret_access_key=self.secret_key)
|
||||
region = boto.rds2.connect_to_region(self.region, aws_access_key_id=self.access_key,
|
||||
aws_secret_access_key=self.secret_key)
|
||||
|
||||
response = region.describe_db_instances()['DescribeDBInstancesResponse']
|
||||
result = response['DescribeDBInstancesResult']
|
||||
instances = [i for i in result['DBInstances'] if i['DBInstanceIdentifier'] == self.db_instance]
|
||||
|
|
Reference in a new issue