<s> import logging <EOL> import uuid <EOL> import psycopg2 <EOL> from django . db import connections , DatabaseError <EOL> from celery import current_app <EOL> from kombu import Connection <EOL> from . import CheckItem <EOL> logger = logging . getLogger ( __name__ ) <EOL> class PGConnection ( CheckItem ) : <EOL> """<STR_LIT>""" <EOL> working_status = ( <EOL> psycopg2 . extensions . STATUS_READY , <EOL> psycopg2 . extensions . STATUS_BEGIN , <EOL> psycopg2 . extensions . STATUS_IN_TRANSACTION , <EOL> psycopg2 . extensions . STATUS_PREPARED , <EOL> ) <EOL> def __init__ ( self ) : <EOL> self . must_fail = False <EOL> for conn in connections . all ( ) : <EOL> try : <EOL> conn . cursor ( ) . execute ( '<STR_LIT>' ) <EOL> except DatabaseError : <EOL> pass <EOL> except psycopg2 . OperationalError as e : <EOL> self . must_fail = True <EOL> def __call__ ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . must_fail : <EOL> return False <EOL> for conn in connections . all ( ) : <EOL> try : <EOL> if conn . connection . status not in self . working_status : <EOL> return False <EOL> except AttributeError as e : <EOL> return None <EOL> else : <EOL> return True <EOL> class CeleryConnection ( CheckItem ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . broker_url = current_app . conf . BROKER_URL <EOL> def __call__ ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . broker_url == '<STR_LIT>' : <EOL> return None <EOL> else : <EOL> try : <EOL> ping_response = current_app . control . ping ( timeout = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> ping_key = ping_response . keys ( ) [ <NUM_LIT:0> ] <EOL> status = ping_response [ ping_key ] [ '<STR_LIT>' ] == u'<STR_LIT>' <EOL> except Exception as exc : <EOL> logger . exception ( exc ) <EOL> status = False <EOL> return status <EOL> class RabbitConnection ( CheckItem ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . broker_url = current_app . conf . BROKER_URL <EOL> def __call__ ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . broker_url . startswith ( "<STR_LIT>" ) : <EOL> try : <EOL> connection = Connection ( self . broker_url , connection_timeout = <NUM_LIT:1> ) <EOL> try : <EOL> connection . connect ( ) <EOL> status = connection . connected <EOL> finally : <EOL> connection . release ( ) <EOL> except Exception as exc : <EOL> logger . exception ( exc ) <EOL> status = False <EOL> return status <EOL> else : <EOL> return None </s>
