Skip to content

Commit e65e8ed

Browse files
tui: improve --comms-timeout documentation (#6182)
* tui: improve --comms-timeout documentation * Correct default in CLI docs. * Mention the "--comms-timeout" option when timeouts occur. * spelling correction --------- Co-authored-by: Mark Dawson <[email protected]>
1 parent 4ec556a commit e65e8ed

File tree

2 files changed

+53
-19
lines changed

2 files changed

+53
-19
lines changed

cylc/flow/scripts/tui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
to the GUI.
2626
2727
Press "h" whilst running Tui to bring up the help screen, use the arrow
28-
keys to navigage.
28+
keys to navigate.
2929
3030
"""
3131

@@ -66,7 +66,7 @@ def get_option_parser() -> COP:
6666
metavar='SEC',
6767
help=(
6868
"Set a timeout for network connections"
69-
" to the running workflow. The default is no timeout."
69+
" to the running workflow. The default is 3 seconds."
7070
" For task messaging connections see"
7171
" site/user config file documentation."
7272
),

cylc/flow/tui/updater.py

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,36 @@ def get_default_filters():
8282
}
8383

8484

85+
def set_message(data, workflow_id, message, prefix='Error - '):
86+
"""Set a message to display instead of the workflow contents.
87+
88+
This is for critical errors that mean we are unable to load a workflow.
89+
90+
Args:
91+
data:
92+
The updater data.
93+
workflow_id:
94+
The ID of the workflow to set the error for.
95+
message:
96+
A message string or an Exception instance to use for the error
97+
text. If a string is provided, it may not contain newlines.
98+
prefix:
99+
A string that will be prepended to the message.
100+
101+
"""
102+
if isinstance(message, Exception):
103+
# use the first line of the error message.
104+
message = str(message).splitlines()[0]
105+
for workflow in data['workflows']:
106+
# find the workflow in the data
107+
if workflow['id'] == workflow_id:
108+
# use the _tui_data field to hold the message
109+
workflow['_tui_data'] = (
110+
f'{prefix}{message}'
111+
)
112+
break
113+
114+
85115
class Updater():
86116
"""The bit of Tui which provides the data.
87117
@@ -266,17 +296,19 @@ async def _update_workflow(self, w_id, client, data):
266296
'id': w_id,
267297
'status': 'stopped',
268298
})
299+
except ClientTimeout:
300+
self._clients[w_id] = None
301+
set_message(
302+
data,
303+
w_id,
304+
'Timeout communicating with workflow.'
305+
' Use "--comms-timeout" to increase the timeout',
306+
)
269307
except (CylcError, ZMQError) as exc:
270308
# something went wrong :(
271309
# remove the client on any error, we'll reconnect next time
272310
self._clients[w_id] = None
273-
for workflow in data['workflows']:
274-
if workflow['id'] == w_id:
275-
workflow['_tui_data'] = (
276-
f'Error - {str(exc).splitlines()[0]}'
277-
)
278-
break
279-
311+
set_message(data, w_id, exc)
280312
else:
281313
# the data arrived, add it to the update
282314
workflow_data = workflow_update['workflows'][0]
@@ -295,16 +327,18 @@ def _connect(self, data):
295327
timeout=self.client_timeout,
296328
)
297329
except WorkflowStopped:
298-
for workflow in data['workflows']:
299-
if workflow['id'] == w_id:
300-
workflow['_tui_data'] = 'Workflow is not running'
301-
except (ZMQError, ClientError, ClientTimeout) as exc:
302-
for workflow in data['workflows']:
303-
if workflow['id'] == w_id:
304-
workflow['_tui_data'] = (
305-
f'Error - {str(exc).splitlines()[0]}'
306-
)
307-
break
330+
set_message(
331+
data, w_id, 'Workflow is not running', prefix=''
332+
)
333+
except ClientTimeout:
334+
set_message(
335+
data,
336+
w_id,
337+
'Timeout connecting to workflow.'
338+
' Use "--comms-timeout" to increase the timeout',
339+
)
340+
except (ZMQError, ClientError) as exc:
341+
set_message(data, w_id, exc)
308342

309343
async def _scan(self):
310344
"""Scan for workflows on the filesystem."""

0 commit comments

Comments
 (0)