Skip to content
Snippets Groups Projects
Commit a79a9bea authored by Cyril Danilevski's avatar Cyril Danilevski :scooter:
Browse files

Create the webservice's MyMDC client in a non-blocking thread executor

parent 51adb1de
No related branches found
No related tags found
No related merge requests found
...@@ -49,25 +49,31 @@ async def init_job_db(config): ...@@ -49,25 +49,31 @@ async def init_job_db(config):
return conn return conn
async def init_md_client(config): async def init_md_client(config: Dict[str, Dict[str, str]]) -> MetadataClient:
""" Initialize an MDC client connection """Initialize an MDC client connection.
:param config: the configuration parsed from the webservice YAML config :param config: the configuration parsed from the webservice YAML config
:return: an MDC client connection :return: an MDC client connection
""" """
# FIXME: this blocks the even loop, should use asyncio.Task
# FIXME: calls to this coro should be shielded
# TODO: could the client be a global? This would recuce passing it around # TODO: could the client be a global? This would recuce passing it around
mdconf = config['metadata-client']
client_conn = MetadataClient(client_id=mdconf['user-id'], # During MetadataClient initialisation, this object requests authentication from MyMDC
client_secret=mdconf['user-secret'], # As such, it is needed to run the initialisation in a thread.
user_email=mdconf['user-email'], def _init_client():
token_url=mdconf['token-url'], mdconf = config['metadata-client']
refresh_url=mdconf['refresh-url'], client_conn = MetadataClient(client_id=mdconf['user-id'],
auth_url=mdconf['auth-url'], client_secret=mdconf['user-secret'],
scope=mdconf['scope'], user_email=mdconf['user-email'],
base_api_url=mdconf['base-api-url']) token_url=mdconf['token-url'],
return client_conn refresh_url=mdconf['refresh-url'],
auth_url=mdconf['auth-url'],
scope=mdconf['scope'],
base_api_url=mdconf['base-api-url'])
return client_conn
loop = get_event_loop()
client = await shield(loop.run_in_executor(None, _init_client))
return client
def init_config_repo(config): def init_config_repo(config):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment