def onFailure(self, transaction, th_q, args, kw): th_q.join() results = transaction.results if errors.hasFailed(results): transaction.state = 2 eventname = self.name failed_apps = dict () #rollback_candidates = [s for s in self.subscribers_s + self.subscribers if not s.ignore_old_failures and s.name in results] rollback_candidates = [s for s in self.subscribers_s + self.subscribers if s.name in results] logger.debug("Begin rollback") for subscriber in rollback_candidates: f = getattr(subscriber, eventname, getattr(subscriber, "onAnyEvent", None)) rollback = getattr(f, "rollback", None) if rollback: logger.debug("ateempting rollback for %s" % subscriber.name) try: rollback(subscriber, *args, **kw) except Exception, err: msg = "Rollback failed for %s:%s (%s)" % (subscriber.name, eventname, err) logger.exception(msg) if errors.isError(results[subscriber.name]): failed_apps[subscriber.name] = results[subscriber.name] if subscriber.adminemail: recipient = subscriber.adminemail appname = subscriber.name err = utils.sendAlert(locals()) if err: logger.warn(err)
def hasFailedBefore(subscriber_name): for tr in Transaction.query.filter_by(state=2): ret = tr.results.get(subscriber_name, None) if ret and errors.isError(tr.results[subscriber_name]): return True return False