예제 #1
0
        def refresh_config_loop():
            while True:
                try:
                    self.update_from_config(filename, section=section)
                except (IOError, yaml.parser.ParserError):
                    stats.log_gauge("successful-config-update", 0)
                    stats.log_gauge("failed-config-update", 1)

                time.sleep(refresh_config_seconds)
예제 #2
0
        def refresh_config_loop():
            while True:
                try:
                    self.update_from_config(filename, section=section)
                except (IOError, yaml.parser.ParserError):
                    stats.log_gauge("successful-config-update", 0)
                    stats.log_gauge("failed-config-update", 1)

                time.sleep(refresh_config_seconds)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    def update_from_config(self, filename, section=None):
        self.logger.debug("Loading " + filename)
        with open(filename) as config:
            data = yaml.safe_load(config.read())

        settings = {}
        settings.update(data.get("common", {}))
        if section:
            settings.update(data.get(section, {}))

        for key, value in settings.iteritems():
            key = key.lower()

            # Limit the parts of the config file that can have an effect.
            if key not in self.settings:
                continue

            override = getattr(self, "override_%s" % key, None)
            if override is not None and callable(override):
                value = override(value)

            self[key] = value

        stats.log_gauge("successful-config-update", 1)
예제 #6
0
    def update_from_config(self, filename, section=None):
        self.logger.debug("Loading " + filename)
        with open(filename) as config:
            data = yaml.safe_load(config.read())

        settings = {}
        settings.update(data.get("common", {}))
        if section:
            settings.update(data.get(section, {}))

        for key, value in settings.iteritems():
            key = key.lower()

            # Limit the parts of the config file that can have an effect.
            if key not in self.settings:
                continue

            override = getattr(self, "override_%s" % key, None)
            if override is not None and callable(override):
                value = override(value)

            self[key] = value

        stats.log_gauge("successful-config-update", 1)
예제 #7
0
    def run(self):
        initial_url = get_database_url(self.settings)
        while True:
            self.logger.debug("Updating Graph from Database.")
            try:
                if get_database_url(self.settings) != initial_url:
                    self.crash()
                with closing(Session()) as session:
                    self.graph.update_from_db(session)

                stats.log_gauge("successful-db-update", 1)
                stats.log_gauge("failed-db-update", 0)
            except Exception:
                stats.log_gauge("successful-db-update", 0)
                stats.log_gauge("failed-db-update", 1)
                self.capture_exception()
                self.crash()

            sleep(self.refresh_interval)
예제 #8
0
파일: database.py 프로젝트: dropbox/grouper
    def run(self):
        # type () -> None
        initial_url = self.settings.database
        while True:
            self.logger.debug("Updating Graph from Database.")
            try:
                if self.settings.database != initial_url:
                    self.crash()
                with closing(Session()) as session:
                    self.graph.update_from_db(session)

                stats.log_gauge("successful-db-update", 1)
                stats.log_gauge("failed-db-update", 0)
            except Exception:
                stats.log_gauge("successful-db-update", 0)
                stats.log_gauge("failed-db-update", 1)
                self.capture_exception()
                self.crash()

            sleep(self.refresh_interval)
예제 #9
0
    def run(self):
        # type () -> None
        initial_url = self.settings.database
        while True:
            self.logger.debug("Updating Graph from Database.")
            try:
                if self.settings.database != initial_url:
                    self.crash()
                with closing(Session()) as session:
                    self.graph.update_from_db(session)

                stats.log_gauge("successful-db-update", 1)
                stats.log_gauge("failed-db-update", 0)
            except Exception:
                stats.log_gauge("successful-db-update", 0)
                stats.log_gauge("failed-db-update", 1)
                self.plugins.log_exception(*sys.exc_info())
                logging.exception("Failed to refresh graph")
                self.crash()

            sleep(self.refresh_interval)
예제 #10
0
    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)
예제 #11
0
    def run(self):
        while True:
            self.logger.debug("Updating Graph from Database.")
            try:
                with closing(Session()) as session:
                    self.graph.update_from_db(session)

                stats.log_gauge("successful-db-update", 1)
                stats.log_gauge("failed-db-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-db-update", 0)
                stats.log_gauge("failed-db-update", 1)
                self.capture_exception()
            except:
                stats.log_gauge("successful-db-update", 0)
                stats.log_gauge("failed-db-update", 1)
                self.capture_exception()
                raise

            sleep(self.refresh_interval)
예제 #12
0
    def run(self):
        while True:
            self.logger.debug("Updating Graph from Database.")
            try:
                with closing(Session()) as session:
                    self.graph.update_from_db(session)

                stats.log_gauge("successful-db-update", 1)
                stats.log_gauge("failed-db-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-db-update", 0)
                stats.log_gauge("failed-db-update", 1)
                self.capture_exception()
            except:
                stats.log_gauge("successful-db-update", 0)
                stats.log_gauge("failed-db-update", 1)
                self.capture_exception()
                raise

            sleep(self.refresh_interval)