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

Merge branch 'fix/webservice_mdc_client_init' into 'master'

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

See merge request detectors/pycalibration!431
parents 51adb1de a79a9bea
No related branches found
No related tags found
1 merge request!431Create the webservice's MyMDC client in a non-blocking thread
......@@ -49,25 +49,31 @@ async def init_job_db(config):
return conn
async def init_md_client(config):
""" Initialize an MDC client connection
async def init_md_client(config: Dict[str, Dict[str, str]]) -> MetadataClient:
"""Initialize an MDC client connection.
:param config: the configuration parsed from the webservice YAML config
: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
mdconf = config['metadata-client']
client_conn = MetadataClient(client_id=mdconf['user-id'],
client_secret=mdconf['user-secret'],
user_email=mdconf['user-email'],
token_url=mdconf['token-url'],
refresh_url=mdconf['refresh-url'],
auth_url=mdconf['auth-url'],
scope=mdconf['scope'],
base_api_url=mdconf['base-api-url'])
return client_conn
# During MetadataClient initialisation, this object requests authentication from MyMDC
# As such, it is needed to run the initialisation in a thread.
def _init_client():
mdconf = config['metadata-client']
client_conn = MetadataClient(client_id=mdconf['user-id'],
client_secret=mdconf['user-secret'],
user_email=mdconf['user-email'],
token_url=mdconf['token-url'],
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):
......
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