Skip to content

Commit

Permalink
Add req-meta
Browse files Browse the repository at this point in the history
  • Loading branch information
datamel committed Dec 15, 2021
1 parent d989bbf commit 436dd86
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions cylc/uiserver/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ def __init__(self, data, log, **kwargs):
# Mutations
async def mutator(self, info, *m_args):
"""Mutate workflow."""
req_meta = {}
_, w_args, _, _ = m_args
auth_user = info.context.get('current_user', 'unknown user')
req_meta['auth_user'] = info.context.get(
'current_user', 'unknown user')
w_ids = [
flow[WORKFLOW].id
for flow in await self.get_workflows_data(w_args)]
Expand All @@ -210,7 +212,7 @@ async def mutator(self, info, *m_args):
'variables': variables,
}
return await self.workflows_mgr.multi_request(
'graphql', w_ids, graphql_args, auth_user=auth_user
'graphql', w_ids, graphql_args, req_meta=req_meta
)

async def service(self, info, *m_args):
Expand Down
11 changes: 7 additions & 4 deletions cylc/uiserver/workflows_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def workflow_request(
req_context=None,
*,
log=None,
auth_user=None
req_meta=None
):
"""Workflow request command.
Expand All @@ -63,6 +63,7 @@ async def workflow_request(
args (dict): Endpoint arguments.
timeout (float): Client request timeout (secs).
req_context (str): A string to identifier.
req_meta (dict): Meta data related to request, e.g. auth_user
Returns:
tuple: (req_context, result)
Expand All @@ -72,7 +73,7 @@ async def workflow_request(
req_context = command
try:
result = await client.async_request(
command, args, timeout, auth_user=auth_user)
command, args, timeout, req_meta=req_meta)
return (req_context, result)
except ClientTimeout as exc:
if log:
Expand Down Expand Up @@ -274,13 +275,15 @@ async def multi_request(
args=None,
multi_args=None,
timeout=None,
auth_user=None
req_meta=None
):
"""Send requests to multiple workflows."""
if args is None:
args = {}
if multi_args is None:
multi_args = {}
if req_meta is None:
req_meta = {}
req_args = {
w_id: (
self.active[w_id]['req_client'],
Expand All @@ -295,7 +298,7 @@ async def multi_request(
req_context=info,
*request_args,
log=self.log,
auth_user=auth_user
req_meta=req_meta
)
for info, request_args in req_args.items()
]
Expand Down

0 comments on commit 436dd86

Please sign in to comment.