Ejemplo n.º 1
0
 def exec_eager(self, *args, **kwargs):
     """Run transaction aware task in eager mode."""
     # We are run in a post-commit hook, so there is no transaction manager available
     tm = TransactionManager()
     # Do not attempt any transaction retries in eager mode
     tm.retry_attempt_count = 1
     self.request.update(request=self.make_faux_request(tm=tm))
     return self.run(*args, **kwargs)
Ejemplo n.º 2
0
def _create_session(transaction_manager: TransactionManager, engine: Engine) -> Session:
    """Create a new database session with Zope transaction manager attached.

    The attached transaction manager takes care of committing the transaction at the end of the request.
    """
    dbsession = Session(bind=engine)
    transaction_manager.retry_attempt_count = 3  # TODO: Hardcoded for now
    zope.sqlalchemy.register(dbsession, transaction_manager=transaction_manager)
    dbsession.transaction_manager = transaction_manager
    return dbsession
Ejemplo n.º 3
0
    def exec_eager(self, *args, **kwargs):
        """Run transaction aware task in eager mode."""

        # We are run in a post-commit hook, so there is no transaction manager available
        tm = TransactionManager()

        # Do not attempt any transaction retries in eager mode
        tm.retry_attempt_count = 1

        self.request.update(request=self.make_faux_request(
            transaction_manager=tm))

        with tm:
            # This doesn't do transaction retry attempts, but should be good enough for eager
            return self.run(*args, **kwargs)