def save_in_db(self): session = Session() if session.query(Run).filter_by(name=self.check_name).count(): run = session.query(Run).filter_by(name=self.check_name).one() run.last_exc_time = self.last_exc_time run.status = self.last_status run.nb_run = run.nb_run + 1 else: inst = Run(name=self.check_name, last_exc_time=self.last_exc_time, status=self.last_status, nb_run=1) session.add(inst) session.commit()
def __init__(self): if not self.__class__._shared_dict: session = Session() if session.query(Run).filter_by(name=self.check_name).count(): db_run = session.query(Run).filter_by(name=self.check_name).one() self.last_exc_time = db_run.last_exc_time self.last_status = db_run.status else: self.last_exc_time = None self.last_status = None self._notifiers = [notifier_class(self) for notifier_class in getattr(self, "notifiers", [NoActionNotifier])] self._frequency = getattr(self, "frequency", None) self.__class__._shared_dict = self.__dict__ else: self.__dict__ = self.__class__._shared_dict