示例#1
0
    def signal_update(self):
        if not self._signal_update_fn:
            logger.info('No signal update function set.')
            return

        try:
            self._signal_update_fn()
        except Exception:
            logger.exception("Failed to signal update.")
            increment_counter(_METRIC_SIGNAL_UPDATE_EXCEPTION)
示例#2
0
  def signal_update(self):
    if not self._signal_update_fn:
      logger.info('No signal update function set.')
      return

    try:
      self._signal_update_fn()
    except Exception:
      logger.exception("Failed to signal update.")
      increment_counter(_METRIC_SIGNAL_UPDATE_EXCEPTION)
示例#3
0
    def _try_update(self, as_of=None):
        try:
            increment_counter(_METRIC_UPDATE_ATTEMPTED)
            if not as_of:
                as_of = datetime.now()

            do_update = self._should_update(as_of)
            if do_update:
                self._needs_update = False
                self._updating = True
                try:
                    self._update(restart_proxy=True)
                except Exception:
                    logger.exception('Failed to update configuration.')
                finally:
                    self._updating = False
        except Exception:
            increment_counter(_METRIC_UPDATE_ATTEMPT_FAILED)
            logger.exception('Error updating.')
示例#4
0
文件: proxy.py 项目: SEJeff/aurproxy
  def _try_update(self, as_of=None):
    try:
      increment_counter(_METRIC_UPDATE_ATTEMPTED)
      if not as_of:
        as_of = datetime.now()

      do_update = self._should_update(as_of)
      if do_update:
        self._needs_update = False
        self._updating= True
        try:
          self._update(restart_proxy=True)
        except Exception:
          logger.exception('Failed to update configuration.')
        finally:
          self._updating = False
    except Exception:
      increment_counter(_METRIC_UPDATE_ATTEMPT_FAILED)
      logger.exception('Error updating.')
示例#5
0
文件: backend.py 项目: 40a/aurproxy
  def _update(self, config, config_dest, restart_proxy):
    if not self._should_update_config(config, config_dest):
      logger.info('No update required.')
      return True

    self._backup(config_dest)
    revert = False
    try:
      logger.info('Writing new configuration.')
      logger.info(config)
      with open(config_dest, 'w') as updated_config:
        updated_config.write(config)

      increment_counter(_METRIC_UPDATE_SUCCEEDED)
      if restart_proxy:
        logger.info('Applying new configuration.')
        self.restart()
    except Exception:
      logger.exception('Writing new configuration failed.')
      revert = True
    finally:
      if revert:
        logger.error('Validation of new configuration failed!')
        logger.warning('Reverting to %s', self._build_backup_path(config_dest))
        try:
          self._revert(config_dest)
          increment_counter(_METRIC_REVERT_SUCCEEDED)
        except Exception:
          logger.exception('Attempt to revert to old configuration failed!')
          increment_counter(_METRIC_REVERT_FAILED)
    return not revert
示例#6
0
    def _update(self, config, config_dest, restart_proxy):
        if not self._should_update_config(config, config_dest):
            logger.info('No update required.')
            return True

        self._backup(config_dest)
        revert = False
        try:
            logger.info('Writing new configuration.')
            logger.info(config)
            with open(config_dest, 'w') as updated_config:
                updated_config.write(config)

            increment_counter(_METRIC_UPDATE_SUCCEEDED)
            if restart_proxy:
                logger.info('Applying new configuration.')
                self.restart()
        except Exception:
            logger.exception('Writing new configuration failed.')
            revert = True
        finally:
            if revert:
                logger.error('Validation of new configuration failed!')
                logger.warning('Reverting to %s',
                               self._build_backup_path(config_dest))
                try:
                    self._revert(config_dest)
                    increment_counter(_METRIC_REVERT_SUCCEEDED)
                except Exception:
                    logger.exception(
                        'Attempt to revert to old configuration failed!')
                    increment_counter(_METRIC_REVERT_FAILED)
        return not revert