Skip to content

Commit 3320c05

Browse files
dump: restrict window to n=0 (#5600)
This restores the old `cylc dump` behaviour of displaying only the pool contents.
1 parent 9f738da commit 3320c05

File tree

4 files changed

+81
-15
lines changed

4 files changed

+81
-15
lines changed

changes.d/5600.break.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The `cylc dump` command now only shows active tasks (e.g. running & queued
2+
tasks). This restores its behaviour of only showing the tasks which currently
3+
exist in the pool as it did in Cylc 7 and earlier versions of Cylc 8.

cylc/flow/scripts/dump.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
2121
Print information about a running workflow.
2222
23+
This command can provide information about active tasks, e.g. running or queued
24+
tasks. For more detailed view of the workflow see `cylc tui` or `cylc gui`.
25+
2326
For command line monitoring:
2427
* `cylc tui`
2528
* `watch cylc dump WORKFLOW_ID` works for small simple workflows
@@ -28,20 +31,21 @@
2831
its prerequisites and outputs, see 'cylc show'.
2932
3033
Examples:
31-
# Display the state of all running tasks, sorted by cycle point:
34+
# Display the state of all active tasks, sorted by cycle point:
3235
$ cylc dump --tasks --sort WORKFLOW_ID | grep running
3336
34-
# Display the state of all tasks in a particular cycle point:
37+
# Display the state of all active in a particular cycle point:
3538
$ cylc dump -t WORKFLOW_ID | grep 2010082406
3639
"""
3740

38-
from graphene.utils.str_converters import to_snake_case
41+
import asyncio
3942
import json
40-
import sys
4143
from typing import TYPE_CHECKING
4244

45+
from graphene.utils.str_converters import to_snake_case
46+
4347
from cylc.flow.exceptions import CylcError
44-
from cylc.flow.id_cli import parse_id
48+
from cylc.flow.id_cli import parse_id_async
4549
from cylc.flow.option_parsers import (
4650
WORKFLOW_ID_ARG_DOC,
4751
CylcOptionParser as COP,
@@ -59,6 +63,7 @@
5963
name
6064
cyclePoint
6165
state
66+
graphDepth
6267
isHeld
6368
isQueued
6469
isRunahead
@@ -179,7 +184,11 @@ def get_option_parser():
179184

180185
@cli_function(get_option_parser)
181186
def main(_, options: 'Values', workflow_id: str) -> None:
182-
workflow_id, *_ = parse_id(
187+
asyncio.run(dump(workflow_id, options))
188+
189+
190+
async def dump(workflow_id, options, write=print):
191+
workflow_id, *_ = await parse_id_async(
183192
workflow_id,
184193
constraint='workflows',
185194
)
@@ -195,6 +204,9 @@ def main(_, options: 'Values', workflow_id: str) -> None:
195204
else:
196205
sort_args = {'keys': ['name', 'cyclePoint']}
197206

207+
# retrict to the n=0 window
208+
graph_depth = 0
209+
198210
if options.disp_form == "raw":
199211
query = f'''
200212
{TASK_SUMMARY_FRAGMENT}
@@ -203,10 +215,10 @@ def main(_, options: 'Values', workflow_id: str) -> None:
203215
query ($wFlows: [ID]!, $sortBy: SortArgs) {{
204216
workflows (ids: $wFlows, stripNull: false) {{
205217
...wFlow
206-
taskProxies (sort: $sortBy) {{
218+
taskProxies (sort: $sortBy, graphDepth: {graph_depth}) {{
207219
...tProxy
208220
}}
209-
familyProxies (sort: $sortBy) {{
221+
familyProxies (sort: $sortBy, graphDepth: {graph_depth}) {{
210222
...fProxy
211223
}}
212224
}}
@@ -224,7 +236,7 @@ def main(_, options: 'Values', workflow_id: str) -> None:
224236
{TASK_SUMMARY_FRAGMENT}
225237
query ($wFlows: [ID]!, $sortBy: SortArgs) {{
226238
workflows (ids: $wFlows, stripNull: false) {{
227-
taskProxies (sort: $sortBy) {{
239+
taskProxies (sort: $sortBy, graphDepth: {graph_depth}) {{
228240
...tProxy
229241
}}
230242
}}
@@ -235,15 +247,15 @@ def main(_, options: 'Values', workflow_id: str) -> None:
235247
'variables': {'wFlows': [workflow_id], 'sortBy': sort_args}
236248
}
237249

238-
workflows = pclient('graphql', query_kwargs)
250+
workflows = await pclient.async_request('graphql', query_kwargs)
239251

240252
try:
241253
for summary in workflows['workflows']:
242254
if options.disp_form == "raw":
243255
if options.pretty:
244-
sys.stdout.write(json.dumps(summary, indent=4) + '\n')
256+
write(json.dumps(summary, indent=4))
245257
else:
246-
print(summary)
258+
write(summary)
247259
else:
248260
if options.disp_form != "tasks":
249261
node_urls = {
@@ -261,7 +273,7 @@ def main(_, options: 'Values', workflow_id: str) -> None:
261273
del summary['families']
262274
del summary['meta']
263275
for key, value in sorted(summary.items()):
264-
print(
276+
write(
265277
f'{to_snake_case(key).replace("_", " ")}={value}')
266278
else:
267279
for item in summary['taskProxies']:
@@ -282,7 +294,7 @@ def main(_, options: 'Values', workflow_id: str) -> None:
282294
else 'not-runahead')
283295
if options.show_flows:
284296
values.append(item['flowNums'])
285-
print(', '.join(values))
297+
write(', '.join(values))
286298
except Exception as exc:
287299
raise CylcError(
288300
json.dumps(workflows, indent=4) + '\n' + str(exc) + '\n')

tests/functional/runahead/06-release-update.t

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ sleep 10
3535
# (gratuitous use of --flows for test coverage)
3636
cylc dump --flows -t "${WORKFLOW_NAME}" | awk '{print $1 $2 $3 $7}' >'log'
3737
cmp_ok 'log' - <<__END__
38-
bar,$NEXT1,waiting,[1]
3938
foo,$NEXT1,waiting,[1]
4039
__END__
4140

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
2+
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
"""Test the "cylc dump" command."""
18+
19+
from cylc.flow.option_parsers import (
20+
Options,
21+
)
22+
from cylc.flow.scripts.dump import (
23+
dump,
24+
get_option_parser,
25+
)
26+
27+
28+
DumpOptions = Options(get_option_parser())
29+
30+
31+
async def test_dump_tasks(flow, scheduler, start):
32+
"""It should show n=0 tasks.
33+
34+
See: https://github.com/cylc/cylc-flow/pull/5600
35+
"""
36+
id_ = flow({
37+
'scheduler': {
38+
'allow implicit tasks': 'true',
39+
},
40+
'scheduling': {
41+
'graph': {
42+
'R1': 'a => b => c',
43+
},
44+
},
45+
})
46+
schd = scheduler(id_)
47+
async with start(schd):
48+
# schd.release_queued_tasks()
49+
await schd.update_data_structure()
50+
ret = []
51+
await dump(id_, DumpOptions(disp_form='tasks'), write=ret.append)
52+
assert ret == ['a, 1, waiting, not-held, queued, not-runahead']

0 commit comments

Comments
 (0)