Skip to content

Commit

Permalink
fix an error handling bug in Cylc Scan
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Oct 17, 2022
1 parent 481c0dc commit ddb9f78
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Maintenance release.

### Fixes

[#5196](https://github.com/cylc/cylc-flow/pull/5196) - Replace traceback
with warning for scan error messages where Workflow is stopped.

[#5192](https://github.com/cylc/cylc-flow/pull/5192) - Recompute runahead limit
after use of `cylc remove`.

Expand Down
2 changes: 1 addition & 1 deletion cylc/flow/network/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def _timeout_handler(workflow: str, host: str, port: Union[int, str]):
host (str): host name
port (Union[int, str]): port number
Raises:
ClientError: if the workflow has already stopped.
WorkflowStopped: if the workflow has already stopped.
"""
if workflow is None:
return
Expand Down
4 changes: 4 additions & 0 deletions cylc/flow/network/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ async def graphql_query(flow, fields, filters=None):
"""
query = f'query {{ workflows(ids: ["{flow["name"]}"]) {{ {fields} }} }}'
try:

client = WorkflowRuntimeClient(
flow['name'],
# use contact_info data if present for efficiency
Expand All @@ -468,6 +469,9 @@ async def graphql_query(flow, fields, filters=None):
'variables': {}
}
)
except WorkflowStopped:
LOG.warning(f'Workflow not running: {flow["name"]}')
return False
except ClientTimeout:
LOG.exception(
f'Timeout: name: {flow["name"]}, '
Expand Down
40 changes: 40 additions & 0 deletions tests/functional/shutdown/23-scan-killed.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# https://github.com/cylc/cylc-flow/pull/5196
# Traceback not seen if contact file is found with stopped workflow.

. "$(dirname "$0")/test_header"

set_test_number 1

init_workflow "${TEST_NAME_BASE}" <<'__FLOW_CONFIG__'
[scheduling]
[[graph]]
R1 = foo
[runtime]
[[foo]]
script = sleep 100
__FLOW_CONFIG__

cylc play "${WORKFLOW_NAME}" > temp
PID=$(grep -Po PID=.* temp | awk -F '=' '{print $2}')
cp "${WORKFLOW_RUN_DIR}/.service/contact" contact.bk
kill "$PID"
cp contact.bk "${WORKFLOW_RUN_DIR}/.service/contact"
cylc scan -t rich > log.txt 2>&1
grep_fail "cylc.flow.exceptions.WorkflowStopped" "log.txt"

0 comments on commit ddb9f78

Please sign in to comment.