def __call__(self, function, *args, **kwargs):
        """execute a function within the context of a transaction"""
        for wait_in_seconds in self.backoff_generator():
            try:
                if self.do_quit_check:
                    self.quit_check()
                # self.db_conn_context_source is an instance of a
                # wrapper class on the actual connection driver
                with self.db_conn_context_source() as connection:
                    try:
                        result = function(connection, *args, **kwargs)
                        connection.commit()
                        return result
                    except:
                        connection.rollback()
                        raise

            except DBApiUtilNonFatalBaseException:
                raise

            except self.db_conn_context_source.conditional_exceptions, x:
                # these exceptions may or may not be retriable
                # the test is for is a last ditch effort to see if
                # we can retry
                if not self.db_conn_context_source.is_operational_exception(x):
                    self.config.logger.critical(
                        'Unrecoverable %s transaction error',
                        self.connection_source_type,
                        exc_info=True
                    )
                    raise
                self.config.logger.critical(
                    '%s transaction error eligible for retry',
                    self.connection_source_type,
                    exc_info=True)

            except self.db_conn_context_source.operational_exceptions, x:
                self.config.logger.critical(
                    '%s transaction error eligible for retry',
                    self.connection_source_type,
                    exc_info=True)

            self.db_conn_context_source.force_reconnect()
            self.config.logger.debug(
                'retry in %s seconds' % wait_in_seconds
            )
            self.responsive_sleep(
                wait_in_seconds,
                'waiting for retry after failure in %s transaction' %
                self.connection_source_type,
            )
        raise
def __call__ ( self , function , * args , ** kwargs ) : for wait_in_seconds in self . backoff_generator ( ) : try : if self . do_quit_check : self . quit_check ( ) with self . db_conn_context_source ( ) as connection : try : result = function ( connection , * args , ** kwargs ) connection . commit ( ) return result except : connection . rollback ( ) raise except DBApiUtilNonFatalBaseException : raise except self . db_conn_context_source . conditional_exceptions , x : if not self . db_conn_context_source . is_operational_exception ( x ) : self . config . logger . critical ( 'Unrecoverable %s transaction error' , self . connection_source_type , exc_info = True ) raise self . config . logger . critical ( '%s transaction error eligible for retry' , self . connection_source_type , exc_info = True ) except self . db_conn_context_source . operational_exceptions , x : self . config . logger . critical ( '%s transaction error eligible for retry' , self . connection_source_type , exc_info = True ) self . db_conn_context_source . force_reconnect ( ) self . config . logger . debug ( 'retry in %s seconds' % wait_in_seconds ) self . responsive_sleep ( wait_in_seconds , 'waiting for retry after failure in %s transaction' % self . connection_source_type , ) raise
execute a function within the context of a transaction