Esempio n. 1
0
    def connect(self, readonly=False, force_commit=False):
        """
        Pulls a connection from the pool when context is entered and
        returns it when context is exited.

        A COMMIT is performed on the current transaction if everything went
        well. Otherwise transaction is ROLLBACK, and everything cleaned up.
        """
        with_transaction = not readonly and self.commit_manually
        session = None
        try:
            # Pull connection from pool.
            session = self.session_factory()
            # Start context
            yield session
            if not readonly and not self.commit_manually:
                # Mark session as dirty.
                self.invalidate(session)
            # Success
            if with_transaction:
                session.commit()
            elif force_commit:
                # Commit like would do a succesful request.
                zope_transaction.commit()

        except sqlalchemy.exc.SQLAlchemyError as e:
            logger.error(e)
            if session and with_transaction:
                session.rollback()
            raise exceptions.BackendError(original=e)

        finally:
            if session and self.commit_manually:
                # Give back to pool if commit done manually.
                session.close()
Esempio n. 2
0
    def connect(self, readonly=False, force_commit=False):
        """
        Pulls a connection from the pool when context is entered and
        returns it when context is exited.

        A COMMIT is performed on the current transaction if everything went
        well. Otherwise transaction is ROLLBACK, and everything cleaned up.
        """
        with_transaction = not readonly and self.commit_manually
        session = None
        try:
            # Pull connection from pool.
            session = self.session_factory()
            # Start context
            yield session
            if not readonly and not self.commit_manually:
                # Mark session as dirty.
                self.invalidate(session)
            # Success
            if with_transaction:
                session.commit()
            elif force_commit:
                # Commit like would do a succesful request.
                zope_transaction.commit()

        except sqlalchemy.exc.SQLAlchemyError as e:
            logger.error(e)
            if session and with_transaction:
                session.rollback()
            raise exceptions.BackendError(original=e) from e
        finally:
            if session and self.commit_manually:
                # Give back to pool if commit done manually.
                session.close()
Esempio n. 3
0
 def __call__(self, event):
     try:
         payload = json.dumps(event.payload)
     except TypeError:
         logger.error("Unable to dump the payload", exc_info=True)
         return
     try:
         self._client.lpush(self.listname, payload)
     except Exception:
         logger.error("Unable to send the payload to Redis", exc_info=True)
Esempio n. 4
0
 def __call__(self, event):
     try:
         logger.info(json.dumps(event.payload))
     except TypeError:
         logger.error("Unable to dump the payload", exc_info=True)
         return