1818
1919"""cylc ping [OPTIONS] ARGS
2020
21- Test communication with a running workflow .
21+ Test communication with running workflows .
2222
23- If workflow WORKFLOW is running or TASK in WORKFLOW is currently running,
24- exit with success status, else exit with error status.
23+ Print the HOST:PORT of running workflows.
24+ If any are not running, exit with error status.
2525"""
2626
2727from functools import partial
2828import sys
2929from typing import Any , Dict , TYPE_CHECKING
3030
31- import cylc .flow .flags
3231from cylc .flow .network .client_factory import get_client
3332from cylc .flow .network .multi import call_multi
3433from cylc .flow .option_parsers import (
35- FULL_ID_MULTI_ARG_DOC ,
34+ ID_MULTI_ARG_DOC ,
3635 CylcOptionParser as COP ,
3736)
38- from cylc .flow .task_state import TASK_STATUS_RUNNING
3937from cylc .flow .terminal import cli_function
4038
4139if TYPE_CHECKING :
4846 id
4947 name
5048 port
51- pubPort
52- }
53- }
54- '''
55-
56- TASK_QUERY = '''
57- query ($tProxy: ID!) {
58- taskProxy (id: $tProxy) {
59- state
60- id
6149 }
6250}
6351'''
@@ -67,9 +55,8 @@ def get_option_parser() -> COP:
6755 parser = COP (
6856 __doc__ ,
6957 comms = True ,
70- multitask = True ,
7158 multiworkflow = True ,
72- argdoc = [FULL_ID_MULTI_ARG_DOC ],
59+ argdoc = [ID_MULTI_ARG_DOC ],
7360 )
7461
7562 return parser
@@ -78,9 +65,10 @@ def get_option_parser() -> COP:
7865async def run (
7966 options : 'Values' ,
8067 workflow_id : str ,
81- * tokens_list ,
68+ client = None
8269) -> Dict :
83- pclient = get_client (workflow_id , timeout = options .comms_timeout )
70+
71+ pclient = client or get_client (workflow_id , timeout = options .comms_timeout )
8472
8573 ret : Dict [str , Any ] = {
8674 'stdout' : [],
@@ -91,38 +79,11 @@ async def run(
9179 'request_string' : FLOW_QUERY ,
9280 'variables' : {'wFlows' : [workflow_id ]}
9381 }
94- task_kwargs : Dict [str , Any ] = {
95- 'request_string' : TASK_QUERY ,
96- }
9782
98- # ping called on the workflow
9983 result = await pclient .async_request ('graphql' , flow_kwargs )
100- msg = ""
101- for flow in result ['workflows' ]:
102- w_name = flow ['name' ]
103- w_port = flow ['port' ]
104- w_pub_port = flow ['pubPort' ]
105- if cylc .flow .flags .verbosity > 0 :
106- ret ['stdout' ].append (
107- f'{ w_name } running on '
108- f'{ pclient .host } :{ w_port } { w_pub_port } \n '
109- )
110-
111- # ping called with task-like objects
112- for tokens in tokens_list :
113- task_kwargs ['variables' ] = {
114- 'tProxy' : tokens .relative_id
115- }
116- task_result = await pclient .async_request ('graphql' , task_kwargs )
117- string_id = tokens .relative_id
118- if not task_result .get ('taskProxy' ):
119- msg = f"task not found: { string_id } "
120- elif task_result ['taskProxy' ]['state' ] != TASK_STATUS_RUNNING :
121- msg = f"task not { TASK_STATUS_RUNNING } : { string_id } "
122- if msg :
123- ret ['stderr' ].append (msg )
124- ret ['exit' ] = 1
12584
85+ for flow in result ['workflows' ]:
86+ ret ['stdout' ].append (f"{ pclient .host } :{ flow ['port' ]} " )
12687 return ret
12788
12889
@@ -144,6 +105,6 @@ def main(
144105 partial (run , options ),
145106 * ids ,
146107 report = report ,
147- constraint = 'mixed ' ,
108+ constraint = 'workflows ' ,
148109 )
149110 sys .exit (all (rets .values ()) is False )
0 commit comments