@@ -82,6 +82,36 @@ def get_default_filters():
82
82
}
83
83
84
84
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
+
85
115
class Updater ():
86
116
"""The bit of Tui which provides the data.
87
117
@@ -266,17 +296,19 @@ async def _update_workflow(self, w_id, client, data):
266
296
'id' : w_id ,
267
297
'status' : 'stopped' ,
268
298
})
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
+ )
269
307
except (CylcError , ZMQError ) as exc :
270
308
# something went wrong :(
271
309
# remove the client on any error, we'll reconnect next time
272
310
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 )
280
312
else :
281
313
# the data arrived, add it to the update
282
314
workflow_data = workflow_update ['workflows' ][0 ]
@@ -295,16 +327,18 @@ def _connect(self, data):
295
327
timeout = self .client_timeout ,
296
328
)
297
329
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 )
308
342
309
343
async def _scan (self ):
310
344
"""Scan for workflows on the filesystem."""
0 commit comments