server/hook.py
changeset 7398 26695dd703d8
parent 7387 d240cff2d8ba
child 7514 32081892850e
equal deleted inserted replaced
7397:6a9e66d788b3 7398:26695dd703d8
   728     takes a session object as first argument (accessible as `.session` from the
   728     takes a session object as first argument (accessible as `.session` from the
   729     operation instance), and optionally all keyword arguments needed by the
   729     operation instance), and optionally all keyword arguments needed by the
   730     operation. These keyword arguments will be accessible as attributes from the
   730     operation. These keyword arguments will be accessible as attributes from the
   731     operation instance.
   731     operation instance.
   732 
   732 
   733     An operation is triggered on connections pool events related to
   733     An operation is triggered on connections set events related to commit /
   734     commit / rollback transations. Possible events are:
   734     rollback transations. Possible events are:
   735 
   735 
   736     * `precommit`:
   736     * `precommit`:
   737 
   737 
   738       the transaction is being prepared for commit. You can freely do any heavy
   738       the transaction is being prepared for commit. You can freely do any heavy
   739       computation, raise an exception if the commit can't go. or even add some
   739       computation, raise an exception if the commit can't go. or even add some
   803                  % classid(self.__class__), DeprecationWarning)
   803                  % classid(self.__class__), DeprecationWarning)
   804             self.commit_event()
   804             self.commit_event()
   805         getattr(self, event)()
   805         getattr(self, event)()
   806 
   806 
   807     def precommit_event(self):
   807     def precommit_event(self):
   808         """the observed connections pool is preparing a commit"""
   808         """the observed connections set is preparing a commit"""
   809 
   809 
   810     def revertprecommit_event(self):
   810     def revertprecommit_event(self):
   811         """an error went when pre-commiting this operation or a later one
   811         """an error went when pre-commiting this operation or a later one
   812 
   812 
   813         should revert pre-commit's changes but take care, they may have not
   813         should revert pre-commit's changes but take care, they may have not
   814         been all considered if it's this operation which failed
   814         been all considered if it's this operation which failed
   815         """
   815         """
   816 
   816 
   817     def rollback_event(self):
   817     def rollback_event(self):
   818         """the observed connections pool has been rollbacked
   818         """the observed connections set has been rollbacked
   819 
   819 
   820         do nothing by default, the operation will just be removed from the pool
   820         do nothing by default
   821         operation list
       
   822         """
   821         """
   823 
   822 
   824     def postcommit_event(self):
   823     def postcommit_event(self):
   825         """the observed connections pool has committed"""
   824         """the observed connections set has committed"""
   826 
   825 
   827     @property
   826     @property
   828     @deprecated('[3.6] use self.session.user')
   827     @deprecated('[3.6] use self.session.user')
   829     def user(self):
   828     def user(self):
   830         return self.session.user
   829         return self.session.user
  1096     instead of giving them into the rql string.
  1095     instead of giving them into the rql string.
  1097     """
  1096     """
  1098     data_key = 'neweids'
  1097     data_key = 'neweids'
  1099 
  1098 
  1100     def rollback_event(self):
  1099     def rollback_event(self):
  1101         """the observed connections pool has been rollbacked,
  1100         """the observed connections set has been rollbacked,
  1102         remove inserted eid from repository type/source cache
  1101         remove inserted eid from repository type/source cache
  1103         """
  1102         """
  1104         try:
  1103         try:
  1105             self.session.repo.clear_caches(self.get_data())
  1104             self.session.repo.clear_caches(self.get_data())
  1106         except KeyError:
  1105         except KeyError:
  1110     """on commit of delete query, we have to remove from repository's
  1109     """on commit of delete query, we have to remove from repository's
  1111     type/source cache eids of entities deleted in that transaction.
  1110     type/source cache eids of entities deleted in that transaction.
  1112     """
  1111     """
  1113     data_key = 'pendingeids'
  1112     data_key = 'pendingeids'
  1114     def postcommit_event(self):
  1113     def postcommit_event(self):
  1115         """the observed connections pool has been rollbacked,
  1114         """the observed connections set has been rollbacked,
  1116         remove inserted eid from repository type/source cache
  1115         remove inserted eid from repository type/source cache
  1117         """
  1116         """
  1118         try:
  1117         try:
  1119             self.session.repo.clear_caches(self.get_data())
  1118             self.session.repo.clear_caches(self.get_data())
  1120         except KeyError:
  1119         except KeyError: