(self, use_cached=None)
return connection
Get and memoize connections to instances
Get and memoize connections to instances
Get and memoize connections to instances
def _get_connection(self, use_cached=None):
        """Get and memoize connections to instances"""
        use_cached = use_cached if use_cached is not None else self.use_cached
        if self.connection and use_cached:
            return self.connection
        try:
            connect_kwargs = self._get_connect_kwargs()
            connection = pg.connect(**connect_kwargs)
            connection.set_isolation_level(pg.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
        except Exception:
            redacted_url = self._get_redacted_dsn()
            message = u'Cannot establish connection to {}'.format(redacted_url)

            self.service_check(
                self.SERVICE_CHECK_NAME, AgentCheck.CRITICAL, tags=self._get_service_checks_tags(), message=message
            )
            raise

        self.connection = connection
        return connection
def _get_connection ( self , use_cached = None ) : use_cached = use_cached if use_cached is not None else self . use_cached if self . connection and use_cached : return self . connection try : connect_kwargs = self . _get_connect_kwargs ( ) connection = pg . connect ( * * connect_kwargs ) connection . set_isolation_level ( pg . extensions . ISOLATION_LEVEL_AUTOCOMMIT ) except Exception : redacted_url = self . _get_redacted_dsn ( ) message = u'Cannot establish connection to {}' . format ( redacted_url ) self . service_check ( self . SERVICE_CHECK_NAME , AgentCheck . CRITICAL , tags = self . _get_service_checks_tags ( ) , message = message ) raise self . connection = connection return connection