Add environment variables support
First read wiki try to run an (example)[https://gitlab.clarin-pl.eu/nlpworkers/tester] (play around with example/worker.py).
All the configuration is taken from the config.ini file -- the nlp_ws library should also support env variables.
- The enviromental variables should always override values in config.ini (if they are defined)
- Enviromental variables should always be written with capital letters (THIS_IS_AN_EXAMPLE).
- This is not a requirement for keywords in config.ini, so you should convert envs to small letters programically
- Before implementing your own solution please google for some standard approach (I think that the config loading function should be overrided or extended) -> nlp_ws/_service.py:128
- Please mind variables from lines 90-110 (like
CFG_S_SERV
). They contain possible keywords from config.ini files. - It is bizzare that variables given below (ad. 5) are not named accordingly. Consider changing that (eq "CFG_S_SERV_O_RHOST" -> "CFG_S_SERV_O_RABBIT_HOST"). If its done, we have a ready convenction for naming enviroment variables!
CFG_S_SERV = 'service'
CFG_S_SERV_O_ROOT = 'root'
CFG_S_SERV_O_TOOL = 'tool'
CFG_S_SERV_O_QPREFIX = 'queue_prefix'
CFG_S_SERV_O_RHOST = 'rabbit_host'
CFG_S_SERV_O_RUSER = 'rabbit_user'
CFG_S_SERV_O_RPSWD = 'rabbit_password'
CFG_S_SERV_O_PROD = 'is_production'
CFG_S_TOOL = 'tool'
CFG_S_TOOL_O_NUMW = 'workers_number'
CFG_S_LOG = 'logging'
CFG_S_LOG_O_PORT = 'port'
CFG_S_LOG_O_FILENAME = 'logfile_name'
CFG_S_LOG_O_FILESIZE = 'logfile_maxsize'
CFG_S_LOG_O_FILECOUNT = 'logfile_maxbackups'
CFG_S_LOG_O_FORMAT = 'log_format'
CFG_S_LOG_O_LEVEL = 'local_log_level'
CFG_S_LOGLEVELS = 'logging_levels'
- If point 6. is met a programmer (that creates some nlp_worker) could either define some extra parameters using config.ini:
[tool]
my_awsome_variable = "value"
or by passing env like that
CFG_S_TOOL_O_MY_AWSOME_VARIABLE=value
This of course would require you to read all envs that starts with CFG_S_TOOL, CFG_S_SERV and CFG_S_LOG and add them to config
(this require some string operation, as the variable should be visible as my_awsome_variable
).
- Do not break compability! Under no circumstances ;)
- If something is not clear, or you have your own thoughts on the problem, please talk to me.