Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernise 'cylc dump -t' print format. #6440

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions changes.d/6440.feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The "cylc dump" command now prints task IDs. Use "--legacy" if you need the old format.
26 changes: 25 additions & 1 deletion cylc/flow/scripts/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ def get_option_parser():
parser.add_option(
"-t", "--tasks", help="Task states only.",
action="store_const", const="tasks", dest="disp_form")
parser.add_option(
"-l", "--legacy", help="Tasks states only; use legacy format.",
action="store_true", default=False, dest="legacy_format")
parser.add_option(
"-f", "--flows", help="Print flow numbers with tasks.",
action="store_true", default=False, dest="show_flows")
Expand Down Expand Up @@ -274,7 +277,7 @@ async def dump(workflow_id, options, write=print):
for key, value in sorted(summary.items()):
write(
f'{to_snake_case(key).replace("_", " ")}={value}')
else:
elif options.legacy_format:
for item in summary['taskProxies']:
if options.sort_by_cycle:
values = [
Expand All @@ -294,6 +297,27 @@ async def dump(workflow_id, options, write=print):
if options.show_flows:
values.append(item['flowNums'])
write(', '.join(values))
else:
for item in summary['taskProxies']:
result = (
f"{item['cyclePoint']}/{item['name']}"
f":{item['state']}"
)
attrs = []
if item['isHeld']:
attrs.append("held")
if item['isQueued']:
attrs.append("queued")
if item['isRunahead']:
attrs.append("runahead")
if attrs:
result += " (" + ",".join(attrs) + ")"
if options.show_flows:
result += (
f" flows={item['flowNums'].replace(' ','')}"
)
write(result)

except Exception as exc:
raise CylcError(
json.dumps(workflows, indent=4) + '\n' + str(exc) + '\n'
Expand Down
2 changes: 1 addition & 1 deletion tests/flakyfunctional/hold-release/14-hold-kill/flow.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'1/sleeper:waiting\(held\).* job killed'

sleep 10 # sleep, should still be held after 10 seconds
cylc dump -s -t "${CYLC_WORKFLOW_ID}" >'cylc-dump.out'
cylc dump -l -s -t "${CYLC_WORKFLOW_ID}" >'cylc-dump.out'
diff -u 'cylc-dump.out' - <<'__OUT__'
1, killer, running, not-held, not-queued, not-runahead
1, sleeper, waiting, held, not-queued, not-runahead
Expand Down
2 changes: 1 addition & 1 deletion tests/flakyfunctional/restart/21-task-elapsed.t
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ cylc workflow-state "${WORKFLOW_NAME}" \
--status=running \
--interval=1 \
--max-polls=10 1>'/dev/null' 2>&1
cylc dump -r "${WORKFLOW_NAME}" >'cylc-dump.out'
cylc dump -l -r "${WORKFLOW_NAME}" >'cylc-dump.out'

test_dump 'cylc-dump.out'

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/queues/qsize/flow.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
N_SUCCEEDED=0
while ((N_SUCCEEDED < 12)); do
sleep 1
N_RUNNING=$(cylc dump -t $CYLC_WORKFLOW_ID | grep running | wc -l)
N_RUNNING=$(cylc dump -l -t $CYLC_WORKFLOW_ID | grep running | wc -l)
((N_RUNNING <= {{q_size}})) # check
N_SUCCEEDED=$(cylc workflow-state "${CYLC_WORKFLOW_ID}//*/*:succeeded" | wc -l)
done
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/reload/03-queues/flow.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cylc__job__poll_grep_workflow_log 'Reload completed'
script = """
cylc__job__wait_cylc_message_started
while true; do
RUNNING=$(cylc dump -t "${CYLC_WORKFLOW_ID}" | grep running | wc -l)
RUNNING=$(cylc dump -l -t "${CYLC_WORKFLOW_ID}" | grep running | wc -l)
# Should be max of: monitor plus 3 members of q1
echo "RUNNING $RUNNING"
if ((RUNNING > 4)); then
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/runahead/06-release-update.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ poll_grep_workflow_log -E "${NEXT1}/bar.* added to active task pool"
sleep 10

# (gratuitous use of --flows for test coverage)
cylc dump --flows -t "${WORKFLOW_NAME}" | awk '{print $1 $2 $3 $7}' >'log'
cylc dump -l --flows -t "${WORKFLOW_NAME}" | awk '{print $1 $2 $3 $7}' >'log'

# The scheduler task pool should contain:
# NEXT1/foo - waiting on clock trigger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if ((CYLC_TASK_CYCLE_POINT == 1)); then
expected="foo, 1, running, not-held, not-queued, not-runahead
foo, 2, waiting, not-held, not-queued, runahead"
diff <(cylc dump -t "${CYLC_WORKFLOW_ID}") <(echo "$expected")
diff <(cylc dump -l -t "${CYLC_WORKFLOW_ID}") <(echo "$expected")
# Force trigger next instance while it is runahead limited.
cylc trigger $CYLC_WORKFLOW_ID//2/foo
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
if ((CYLC_TASK_CYCLE_POINT == 1)); then
# Force trigger 3/foo while 2/foo is runahead limited.
expected="foo, 2, waiting, not-held, not-queued, runahead"
diff <(cylc dump -t "${CYLC_WORKFLOW_ID}" | grep 'foo, 2') \
diff <(cylc dump -l -t "${CYLC_WORKFLOW_ID}" | grep 'foo, 2') \
<(echo "$expected")
cylc trigger --flow=none $CYLC_WORKFLOW_ID//3/foo
elif ((CYLC_TASK_CYCLE_POINT == 3)); then
Expand Down
50 changes: 48 additions & 2 deletions tests/integration/scripts/test_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
get_option_parser,
)


DumpOptions = Options(get_option_parser())


Expand All @@ -48,5 +47,52 @@ async def test_dump_tasks(flow, scheduler, start):
# schd.release_queued_tasks()
await schd.update_data_structure()
ret = []
await dump(id_, DumpOptions(disp_form='tasks'), write=ret.append)
await dump(
id_,
DumpOptions(disp_form='tasks', legacy_format=True),
write=ret.append
)
assert ret == ['a, 1, waiting, not-held, queued, not-runahead']


async def test_dump_format(flow, scheduler, start):
"""Check the new "cylc dump" output format, i.e. task IDs.

See: https://github.com/cylc/cylc-flow/pull/6440
"""
id_ = flow({
'scheduler': {
'allow implicit tasks': 'true',
},
'scheduling': {
'graph': {
'R1': 'a',
},
},
})
schd = scheduler(id_)
async with start(schd):
[itask] = schd.pool.get_tasks()

itask.state_reset(is_held=True)
schd.pool.data_store_mgr.delta_task_held(itask)

itask.state_reset(is_runahead=True)
schd.pool.data_store_mgr.delta_task_runahead(itask)

itask.state_reset(is_queued=True)
schd.pool.data_store_mgr.delta_task_queued(itask)

itask.flow_nums = set([1,2])
schd.pool.data_store_mgr.delta_task_flow_nums(itask)

await schd.update_data_structure()
ret = []
await dump(
id_,
DumpOptions(disp_form='tasks', show_flows=True),
write=ret.append
)
assert ret == [
'1/a:waiting (held,queued,runahead) flows=[1,2]',
]
Loading