Commit 47cea1bd authored by Yannick's avatar Yannick
Browse files

remove module discovery

parent c5b46c4f
Pipeline #116111 failed with stages
in 41 minutes and 7 seconds
# Wellbore Domain Services Modules
> :warning: **Work In Progress**
> Refactoring of Wellbore DDMS as independent modules
\ No newline at end of file
# Load modules [alpha version]
import importlib
import sys
from app.conf import Config, MODULES_PATH_PREFIX
from app.helper import logger
discovered_routers = []
def reset_routers():
global discovered_routers
discovered_routers = []
def get_routers():
if len(discovered_routers) == 0:
return discovered_routers
def load_modules():
discovered_modules = []
modules = Config.modules.value
if modules:
discovered_modules = modules.split(',')
logger.get_logger().info(f'Discovered modules: {discovered_modules}')
for name in discovered_modules:
def load_module(name):
log = logger.get_logger()
try:'Loading `{name}` module')
module = importlib.import_module(f'{MODULES_PATH_PREFIX}.{name}')
router = module.router
if not router.prefix:
raise AttributeError('Router prefix cannot be empty')
if not router.tags:
raise AttributeError('Router tags cannot be empty')
discovered_routers.append(router)'Done. `{name}` loaded')
except AttributeError as 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}` module. Module not found. {error}')
except ValueError as error:
log.warning(f'Failed to load `{name}` module. {error}')
except NameError as error:
log.warning(f'Failed to load `{name}` module. Missing module configuration. {error}')
log.warning(f'Failed to load `{name}` module. {sys.exc_info()[0]}')
Supports Markdown
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