Last active
October 7, 2016 13:46
-
-
Save omkar0001/288fe19a4dcda9c3650669641673a8b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Will create a config file for project. Name of the file would be trueai_config.py. | |
file: trueai_config.py | |
This file will contain all the config settings, related to the project. One of the main config settings, we will be storing | |
is, the elasticsearch indexes we are using. The value of the variable, depends on the environmental variable | |
TRUEAI_ENVIRONMENT | |
if getenv('TRUEAI_ENVIRONMENT', 'devel') == 'test': | |
ELASTICSEARCH_TRUEAI_INDEX = 'test_trueai' | |
else: | |
ELASTICSEARCH_TRUEAI_INDEX = 'trueai' | |
While registering a document class, to es document, we can do this. | |
import trueai_config as config | |
es_database_wrapper.register(Experiment, index=config.ELASTICSEARCH_TRUEAI_INDEX, doc_type='experiment') | |
Advantages of the design: | |
============================= | |
One of the main advantages of this, design is its easy to create environments and can easily isolate them. For example. | |
when running tests, we can set the environmental variable as test. In that way test data will be created in other index, | |
oother than the index used in live or dev. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is much better than having a flag in the class function.