def set_permit_timeout_from_features(enabled): """Control request timeouts being obtained from the 'hard_timeout' flag. Until we've fully setup a page to render - routed the request to the right object, setup a participation etc, feature flags cannot be completely used; and because doing feature flag lookups will trigger DB access, attempting to do a DB lookup will cause a nested DB lookup (the one being done, and the flags lookup). To resolve all of this, timeouts start as a config file only setting, and are then overridden once the request is ready to execute. :param enabled: If True permit looking up request timeouts in feature flags. """ get_interaction_extras().permit_timeout_from_features = enabled
def set_permit_timeout_from_features(enabled): """Control request timeouts being obtained from the 'hard_timeout' flag. Until we've fully setup a page to render - routed the request to the right object, setup a participation etc, feature flags cannot be completely used; and because doing feature flag lookups will trigger DB access, attempting to do a DB lookup will cause a nested DB lookup (the one being done, and the flags lookup). To resolve all of this, timeouts start as a config file only setting, and are then overridden once the request is ready to execute. :param enabled: If True permit looking up request timeouts in feature flags. """ get_interaction_extras().permit_timeout_from_features = enabled
def _get_request_timeout(timeout=None): """Get the timeout value in ms for the current request. :param timeout: A custom timeout in ms. :return None or a time in ms representing the budget to grant the request. """ if not getattr(_local, 'enable_timeout', True): return None if timeout is None: timeout = config.database.db_statement_timeout interaction_extras = get_interaction_extras() if (interaction_extras is not None and interaction_extras.permit_timeout_from_features): set_permit_timeout_from_features(False) try: timeout_str = features.getFeatureFlag('hard_timeout') finally: set_permit_timeout_from_features(True) if timeout_str: try: timeout = float(timeout_str) except ValueError: logging.error('invalid hard timeout flag %r', timeout_str) return timeout
def _get_request_timeout(timeout=None): """Get the timeout value in ms for the current request. :param timeout: A custom timeout in ms. :return None or a time in ms representing the budget to grant the request. """ if not getattr(_local, 'enable_timeout', True): return None if timeout is None: timeout = config.database.db_statement_timeout interaction_extras = get_interaction_extras() if (interaction_extras is not None and interaction_extras.permit_timeout_from_features): set_permit_timeout_from_features(False) try: timeout_str = features.getFeatureFlag('hard_timeout') finally: set_permit_timeout_from_features(True) if timeout_str: try: timeout = float(timeout_str) except ValueError: logging.error('invalid hard timeout flag %r', timeout_str) return timeout