def run(self): while True: try: with closing(Session()) as session: self.logger.debug("Expiring edges....") self.expire_edges(session) self.logger.debug( "Expiring nonauditor approvers in audited groups...") self.expire_nonauditors(session) self.logger.debug("Sending emails...") process_async_emails(self.settings, session, datetime.utcnow()) self.logger.debug("Pruning old traces....") prune_old_traces(session) session.commit() stats.set_gauge("successful-background-update", 1) stats.set_gauge("failed-background-update", 0) except OperationalError: Session.configure( bind=get_db_engine(get_database_url(self.settings))) self.logger.critical("Failed to connect to database.") stats.set_gauge("successful-background-update", 0) stats.set_gauge("failed-background-update", 1) self.capture_exception() except: stats.set_gauge("successful-background-update", 0) stats.set_gauge("failed-background-update", 1) self.capture_exception() raise sleep(60)
def run(self): # type: () -> None initial_url = self.settings.database while True: try: if self.settings.database != initial_url: self.crash() with closing(Session()) as session: self.logger.info("Expiring edges....") self.expire_edges(session) self.logger.info("Promoting nonauditor approvers in audited groups...") self.promote_nonauditors(session) self.logger.info("Sending emails...") process_async_emails(self.settings, session, datetime.utcnow()) self.logger.info("Pruning old traces....") prune_old_traces(session) session.commit() stats.log_gauge("successful-background-update", 1) stats.log_gauge("failed-background-update", 0) except Exception: stats.log_gauge("successful-background-update", 0) stats.log_gauge("failed-background-update", 1) self.plugins.log_exception(None, None, *sys.exc_info()) self.logger.exception("Unexpected exception occurred in background thread") self.crash() self.logger.debug("Sleeping for {} seconds...".format(self.settings.sleep_interval)) sleep(self.settings.sleep_interval)
def run(self): # type: () -> None initial_url = self.settings.database while True: try: if self.settings.database != initial_url: self.crash() with closing(Session()) as session: self.logger.info("Expiring edges....") self.expire_edges(session) self.logger.info("Promoting nonauditor approvers in audited groups...") self.promote_nonauditors(session) self.logger.info("Sending emails...") process_async_emails(self.settings, session, datetime.utcnow()) self.logger.info("Pruning old traces....") prune_old_traces(session) session.commit() stats.log_gauge("successful-background-update", 1) stats.log_gauge("failed-background-update", 0) except Exception: stats.log_gauge("successful-background-update", 0) stats.log_gauge("failed-background-update", 1) self._capture_exception() self.logger.exception("Unexpected exception occurred in background thread.") self.crash() self.logger.debug("Sleeping for {} seconds...".format(self.settings.sleep_interval)) sleep(self.settings.sleep_interval)
def run(self): while True: try: with closing(Session()) as session: self.logger.debug("Expiring edges....") self.expire_edges(session) self.logger.debug("Expiring nonauditor approvers in audited groups...") self.expire_nonauditors(session) self.logger.debug("Sending emails...") process_async_emails(self.settings, session, datetime.utcnow()) self.logger.debug("Pruning old traces....") prune_old_traces(session) session.commit() stats.set_gauge("successful-background-update", 1) stats.set_gauge("failed-background-update", 0) except OperationalError: Session.configure(bind=get_db_engine(get_database_url(self.settings))) self.logger.critical("Failed to connect to database.") stats.set_gauge("successful-background-update", 0) stats.set_gauge("failed-background-update", 1) self.capture_exception() except: stats.set_gauge("successful-background-update", 0) stats.set_gauge("failed-background-update", 1) self.capture_exception() raise sleep(60)
def run(self): while True: try: session = Session() logging.debug("Expiring edges....") self.expire_edges(session) logging.debug("Sending emails...") process_async_emails(self.settings, session, datetime.utcnow()) logging.debug("Pruning old traces....") prune_old_traces(session) session.commit() session.close() stats.set_gauge("successful-background-run", 1) except OperationalError: Session.configure(bind=get_db_engine(get_database_url(self.settings))) logging.critical("Failed to connect to database.") stats.set_gauge("successful-background-run", 0) self.capture_exception() except: stats.set_gauge("successful-background-run", 0) self.capture_exception() raise sleep(60)
def run(self): # type: () -> None while True: try: with closing(Session()) as session: self.logger.info("Expiring edges....") self.expire_edges(session) self.logger.info("Expiring nonauditor approvers in audited groups...") self.expire_nonauditors(session) self.logger.info("Sending emails...") process_async_emails(self.settings, session, datetime.utcnow()) self.logger.info("Pruning old traces....") prune_old_traces(session) session.commit() stats.log_gauge("successful-background-update", 1) stats.log_gauge("failed-background-update", 0) except OperationalError: Session.configure(bind=get_db_engine(get_database_url(self.settings))) self.logger.critical("Failed to connect to database.") stats.log_gauge("successful-background-update", 0) stats.log_gauge("failed-background-update", 1) self._capture_exception() except: stats.log_gauge("successful-background-update", 0) stats.log_gauge("failed-background-update", 1) self._capture_exception() self.logger.exception("Unexpected exception occurred in background thread.") raise self.logger.debug("Sleeping for {} seconds...".format(self.settings.sleep_interval)) sleep(self.settings.sleep_interval)