Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cylc/flow/scripts/cat_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
'd': 'print-dir',
'c': 'cat',
't': 'tail',
'a': 'auto',
}


Expand Down Expand Up @@ -367,7 +368,7 @@ def get_task_job_attrs(workflow_id, point, task, submit_num):
"""Retrieve job info from the database.

* live_job_id is the job ID if job is running, else None.
* submit_failed is True if the the submission failed.
* submit_failed is True if the submission failed.

Returns:
tuple - (platform, job_runner_name, live_job_id, submit_failed)
Expand Down Expand Up @@ -466,6 +467,10 @@ def _main(
file_name: str = options.filename or 's'
log_file_path: Path

# auto mode only applies to task logs. Default to cat mode.
if mode == 'auto':
mode = 'cat'

if mode == 'list-dir':
# list workflow logs
print('\n'.join(sorted(
Expand Down Expand Up @@ -540,6 +545,10 @@ def _main(
# KeyError: Is already long form (standard log, or custom).
platform_name, _, live_job_id, submit_failed = get_task_job_attrs(
workflow_id, point, task, submit_num)
if mode == 'auto' and live_job_id is None:
mode = 'cat'
elif mode == 'auto' and live_job_id:
mode = 'tail'
platform = get_platform(platform_name)
batchview_cmd = None
if live_job_id is not None:
Expand Down
55 changes: 55 additions & 0 deletions tests/functional/cylc-cat-log/14-auto-mode.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/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/>.
#-------------------------------------------------------------------------------
# Test "cylc cat-log" using auto mode with a custom tail /command
. "$(dirname "$0")/test_header"
#-------------------------------------------------------------------------------
set_test_number 7
install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}"
create_test_global_config "" "
[platforms]
[[localhost]]
tail command template = $PWD/bin/my-tailer.sh %(filename)s
"
#-------------------------------------------------------------------------------
TEST_NAME="${TEST_NAME_BASE}-validate"
run_ok "${TEST_NAME}" cylc validate "${WORKFLOW_NAME}"
workflow_run_ok "${TEST_NAME_BASE}-run" cylc play "${WORKFLOW_NAME}"
cylc workflow-state "${WORKFLOW_NAME}//1/foo:started" --interval=1
sleep 3
# Test that the custom tail command is used when the task is live
TEST_NAME=${TEST_NAME_BASE}-cat-log-auto-tail
cylc cat-log "${WORKFLOW_NAME}//1/foo" -f o -m a > "${TEST_NAME}.out"
grep_ok "HELLO from foo 1" "${TEST_NAME}.out"
#-------------------------------------------------------------------------------
cylc stop --kill --max-polls=20 --interval=1 "${WORKFLOW_NAME}"
#-------------------------------------------------------------------------------
# Test that the custom tail command is not used when the task is not live
# (i.e., auto mode should not use the custom tail command)
TEST_NAME=${TEST_NAME_BASE}-cat-log-auto-cat
cylc cat-log "${WORKFLOW_NAME}//1/foo" -f o -m a > "${TEST_NAME}.out"
grep_fail "HELLO from foo 1" "${TEST_NAME}.out"
grep_ok "from foo 1" "${TEST_NAME}.out"
#-------------------------------------------------------------------------------
# Test that the custom tail command is not used when workflow logs are requested
# (i.e., auto mode should not use the custom tail command)
TEST_NAME=${TEST_NAME_BASE}-cat-log-auto-workflow
# Use the workflow name without the task ID to get the workflow logs
cylc cat-log "${WORKFLOW_NAME}" -m a > "${TEST_NAME}.out"
grep_fail "HELLO" "${TEST_NAME}.out"
grep_ok "$("Workflow: */functional/cylc-cat-log/14-auto-mode")" "${TEST_NAME}.out"
purge
5 changes: 5 additions & 0 deletions tests/functional/cylc-cat-log/14-auto-mode/bin/my-tailer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# Modify 'tail' output to prove that cylc used the custom tailer.
# Exit immediately, for the test (i.e. don't 'tail -F')
FILE="$1"
tail -n +1 "${FILE}" | awk '{print "HELLO", $0; fflush() }'
15 changes: 15 additions & 0 deletions tests/functional/cylc-cat-log/14-auto-mode/flow.cylc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[scheduler]
[[events]]
abort on stall timeout = True
stall timeout = PT2M
[scheduling]
[[graph]]
R1 = foo
[runtime]
[[foo]]
script = """
for I in $(seq 1 100); do
echo "from $CYLC_TASK_NAME $I"
sleep 1
done
"""
Loading