Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1645)

Unified Diff: appengine/machine_provider/config.py

Issue 2225263004: Adds config component to Machine Provider (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/machine_provider/app.yaml ('k') | appengine/machine_provider/cron.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/machine_provider/config.py
diff --git a/appengine/machine_provider/config.py b/appengine/machine_provider/config.py
new file mode 100644
index 0000000000000000000000000000000000000000..adc4bb8157ec94787c1e6e72ab9840733330ae77
--- /dev/null
+++ b/appengine/machine_provider/config.py
@@ -0,0 +1,46 @@
+# Copyright 2016 The LUCI Authors. All rights reserved.
+# Use of this source code is governed under the Apache License, Version 2.0
+# that can be found in the LICENSE file.
+
+"""Instance specific settings."""
+
+import logging
+
+from components import config
+from components import net
+from components import utils
+from components.config import validation
+
+from proto import config_pb2
+
+SETTINGS_CFG_FILENAME = 'settings.cfg'
+
+
+ConfigApi = config.ConfigApi
+
+
+@validation.self_rule(SETTINGS_CFG_FILENAME, config_pb2.SettingsCfg)
+def validate_settings(cfg, ctx):
+ """Validates settings.cfg file against proto message schema."""
+ pass
+
+
+def _get_settings():
+ """Returns (rev, cfg) where cfg is a parsed SettingsCfg message.
+
+ If config does not exists, returns (None, <cfg with defaults>).
+
+ The config is cached in the datastore.
+ """
+ # store_last_good=True tells config component to update the config file
+ # in a cron job. Here we just read from the datastore.
+ rev, cfg = config.get_self_config(
+ SETTINGS_CFG_FILENAME, config_pb2.SettingsCfg, store_last_good=True)
+ cfg = cfg or config_pb2.SettingsCfg()
+ return rev, cfg
+
+
+@utils.cache_with_expiration(60)
+def settings():
+ """Loads settings from an NDB-based cache or a default one if not present."""
+ return _get_settings()[1]
« no previous file with comments | « appengine/machine_provider/app.yaml ('k') | appengine/machine_provider/cron.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698