Commit 25ca23f2 authored by Luc Yriarte's avatar Luc Yriarte
Browse files

Rename extensions as modules in the code

parent acba77ae
Pipeline #51492 passed with stages
in 11 minutes and 48 seconds
......@@ -183,10 +183,10 @@ class ConfigurationContainer:
default='300',
factory=lambda x: int(x))
extension_modules: EnvVar = EnvVar(
key='EXTENSION_MODULES',
description="""Comma separated list of extension module names to load.""",
default=None)
modules: EnvVar = EnvVar(
key='MODULES',
description="""Comma separated list of module names to load.""",
default="") # Add modules to the list once they are refactored, so that they are included
_environment_dict: Dict = os.environ
......
# Load extension modules [alpha version]
# Load modules [alpha version]
import importlib
import sys
......@@ -19,19 +19,19 @@ def get_routers():
def load_modules():
discovered_modules = []
extension_modules = Config.extension_modules.value
if extension_modules:
discovered_modules = extension_modules.split(',')
modules = Config.modules.value
if modules:
discovered_modules = modules.split(',')
logger.get_logger().info(f'Discovered modules: {discovered_modules}')
for name in discovered_modules:
load_extension(name)
load_module(name)
def load_extension(name):
def load_module(name):
log = logger.get_logger()
try:
log.info(f'Loading `{name}` extension')
log.info(f'Loading `{name}` module')
module = importlib.import_module(name)
can_run, message = module.can_run()
......@@ -49,12 +49,12 @@ def load_extension(name):
log.info(f'Done. `{name}` loaded')
except AttributeError as error:
log.warning(f'Failed to load `{name}` extension. Module not configured properly. {error}')
log.warning(f'Failed to load `{name}` module. Module not configured properly. {error}')
except ModuleNotFoundError as error:
log.warning(f'Failed to load `{name}` extension. Module not found. {error}')
log.warning(f'Failed to load `{name}` module. Module not found. {error}')
except ValueError as error:
log.warning(f'Failed to load `{name}` extension. {error}')
log.warning(f'Failed to load `{name}` module. {error}')
except NameError as error:
log.warning(f'Failed to load `{name}` extension. Missing module configuration. {error}')
log.warning(f'Failed to load `{name}` module. Missing module configuration. {error}')
except:
log.warning(f'Failed to load `{name}` extension. {sys.exc_info()[0]}')
log.warning(f'Failed to load `{name}` module. {sys.exc_info()[0]}')
......@@ -126,7 +126,7 @@ async def startup_event():
if Config.alpha_feature_enabled.value:
enable_alpha_feature()
add_extension_routers()
add_modules_routers()
@base_app.on_event('shutdown')
......@@ -263,12 +263,12 @@ add_exception_handlers(wdms_app)
# Load and add router modules [alpha version]
def add_extension_routers():
def add_modules_routers():
for router in discoverer.get_routers():
add_extension_router(router)
add_modules_router(router)
def add_extension_router(router):
def add_modules_router(router):
log = logger.get_logger()
name = router.prefix
try:
......
......@@ -23,8 +23,8 @@ data:
USE_PARTITION_SERVICE: {{ .Values.configMap.data.usePartitionService }}
AZ_LOGGER_LEVEL: {{ .Values.configMap.data.loggerLevel }}
ENVIRONMENT_NAME: {{ .Values.configMap.data.environmentName }}
{{ if .Values.configMap.data.extensionModules }}
EXTENSION_MODULES: {{ .Values.configMap.data.extensionModules }}
{{ if .Values.configMap.data.modules }}
MODULES: {{ .Values.configMap.data.modules }}
{{ end }}
kind: ConfigMap
metadata:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment