def initialize_app(config): # logging configuration logging.config.fileConfig(config, disable_existing_loggers=False) logger.info("Read configuration from %r" % config) app._config_file = config app._config = Config(config) app.add_hook('before_request', before_request) app.add_hook('after_request', after_request) # sentry configuration if app._config['sentry']['enabled']: app._sentry = Sentry(app._config['sentry']['dsn']) else: app._sentry = None # backend configuration configfile = app._config['absearch']['config'] schemafile = app._config['absearch']['schema'] # directory datadir = app._config['directory']['path'] logger.info("Read config and schema from %r on disk" % datadir) def config_reader(): with open(os.path.join(datadir, configfile)) as f: data = f.read() return ( json.loads(data), hashlib.md5(data.encode("utf8")).hexdigest(), ) def schema_reader(): with open(os.path.join(datadir, schemafile)) as f: data = f.read() return ( json.loads(data), hashlib.md5(data.encode("utf8")).hexdigest(), ) # counter configuration counter = app._config['absearch']['counter'] counter_options = {} max_age = app._config['absearch']['max_age'] app.settings = SearchSettings(config_reader, schema_reader, counter, counter_options, max_age)
def __init__(self, config_reader, schema_reader=None, counter='memory', counter_options=None, max_age=None): self.max_age = max_age self.schema_md5 = self.config_md5 = None self._last_loaded = None logger.info("Use memory backend for counters") counters_backend = MemoryCohortCounters if counter_options is None: counter_options = {} self._counters = counters_backend(**counter_options) self.config_reader = config_reader self.schema_reader = schema_reader self.load()
def initialize_app(config): # logging configuration logging.config.fileConfig(config, disable_existing_loggers=False) logger.info("Read configuration from %r" % config) app._config_file = config app._config = Config(config) app.add_hook('before_request', before_request) app.add_hook('after_request', after_request) # statsd configuration app._statsd = _Statsd(app._config['statsd']) # sentry configuration if app._config['sentry']['enabled']: app._sentry = Sentry(app._config['sentry']['dsn']) else: app._sentry = None # backend configuration configfile = app._config['absearch']['config'] schemafile = app._config['absearch']['schema'] if app._config['absearch']['backend'] == 'aws': logger.info("Read config and schema from AWS") config_reader = partial(get_s3_file, configfile, app._config, app._statsd) schema_reader = partial(get_s3_file, schemafile, app._config, app._statsd) else: # directory datadir = app._config['directory']['path'] logger.info("Read config and schema from %r on disk" % datadir) def config_reader(): with open(os.path.join(datadir, configfile)) as f: data = f.read() return json.loads(data), hashlib.md5(data).hexdigest() def schema_reader(): with open(os.path.join(datadir, schemafile)) as f: data = f.read() return json.loads(data), hashlib.md5(data).hexdigest() # counter configuration counter = app._config['absearch']['counter'] if counter == 'redis': counter_options = dict(app._config['redis']) else: counter_options = {} counter_options['statsd'] = app._statsd max_age = app._config['absearch']['max_age'] app.settings = SearchSettings(config_reader, schema_reader, counter, counter_options, max_age)