Config Manager¶
Base Config Manager
¶
Static Config Manager
¶
-
class
optimizely.config_manager.
StaticConfigManager
(datafile=None, logger=None, error_handler=None, notification_center=None, skip_json_validation=False)¶ Config manager that returns ProjectConfig based on provided datafile.
-
get_config
()¶ Returns instance of ProjectConfig.
- Returns
ProjectConfig. None if not set.
-
Polling Config Manager
¶
-
class
optimizely.config_manager.
PollingConfigManager
(sdk_key=None, datafile=None, update_interval=None, blocking_timeout=None, url=None, url_template=None, logger=None, error_handler=None, notification_center=None, skip_json_validation=False)¶ Config manager that polls for the datafile and updated ProjectConfig based on an update interval.
-
fetch_datafile
()¶ Fetch datafile and set ProjectConfig.
-
get_config
()¶ Returns instance of ProjectConfig. Returns immediately if project config is ready otherwise blocks maximum for value of blocking_timeout in seconds.
- Returns
ProjectConfig. None if not set.
-
static
get_datafile_url
(sdk_key, url, url_template)¶ Helper method to determine URL from where to fetch the datafile.
- Parameters
sdk_key – Key uniquely identifying the datafile.
url – String representing URL from which to fetch the datafile.
url_template – String representing template which is filled in with SDK key to determine URL from which to fetch the datafile.
- Returns
String representing URL to fetch datafile from.
- Raises
optimizely.exceptions.InvalidInputException if –
- One of sdk_key or url is not provided. –
- url_template is invalid. –
-
property
is_running
¶ Check if polling thread is alive or not.
-
set_blocking_timeout
(blocking_timeout)¶ Helper method to set time in seconds to block the config call until config has been initialized.
- Parameters
blocking_timeout – Time in seconds to block the config call.
-
set_last_modified
(response_headers)¶ Looks up and sets last modified time based on Last-Modified header in the response.
- Parameters
response_headers – requests.Response.headers
-
set_update_interval
(update_interval)¶ Helper method to set frequency at which datafile has to be polled and ProjectConfig updated.
- Parameters
update_interval – Time in seconds after which to update datafile.
-
start
()¶ Start the config manager and the thread to periodically fetch datafile.
-