diff --git a/changes.d/6440.feat.md b/changes.d/6440.feat.md new file mode 100644 index 00000000000..e0bf1b68b3e --- /dev/null +++ b/changes.d/6440.feat.md @@ -0,0 +1 @@ +The "cylc dump" command now prints task IDs. Use "--legacy" if you need the old format. diff --git a/cylc/flow/scripts/dump.py b/cylc/flow/scripts/dump.py index f47ee8d2df8..e8dc7fe2cb2 100755 --- a/cylc/flow/scripts/dump.py +++ b/cylc/flow/scripts/dump.py @@ -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") @@ -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 = [ @@ -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' diff --git a/tests/flakyfunctional/hold-release/14-hold-kill/flow.cylc b/tests/flakyfunctional/hold-release/14-hold-kill/flow.cylc index 9a2c51a88fd..5c5e3f4ae17 100644 --- a/tests/flakyfunctional/hold-release/14-hold-kill/flow.cylc +++ b/tests/flakyfunctional/hold-release/14-hold-kill/flow.cylc @@ -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 diff --git a/tests/flakyfunctional/restart/21-task-elapsed.t b/tests/flakyfunctional/restart/21-task-elapsed.t index 3d47e2eeae5..4fb644f32ad 100755 --- a/tests/flakyfunctional/restart/21-task-elapsed.t +++ b/tests/flakyfunctional/restart/21-task-elapsed.t @@ -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' diff --git a/tests/functional/queues/qsize/flow.cylc b/tests/functional/queues/qsize/flow.cylc index e8f65d6816f..82f15a2fdac 100644 --- a/tests/functional/queues/qsize/flow.cylc +++ b/tests/functional/queues/qsize/flow.cylc @@ -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 diff --git a/tests/functional/reload/03-queues/flow.cylc b/tests/functional/reload/03-queues/flow.cylc index 8520a61e15a..564ffba70cd 100644 --- a/tests/functional/reload/03-queues/flow.cylc +++ b/tests/functional/reload/03-queues/flow.cylc @@ -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 diff --git a/tests/functional/runahead/06-release-update.t b/tests/functional/runahead/06-release-update.t index 45fb680c69f..3b7a2a784d4 100644 --- a/tests/functional/runahead/06-release-update.t +++ b/tests/functional/runahead/06-release-update.t @@ -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 diff --git a/tests/functional/spawn-on-demand/13-trigger-runahead/flow.cylc b/tests/functional/spawn-on-demand/13-trigger-runahead/flow.cylc index a98b03bbfe6..964153a4cbf 100644 --- a/tests/functional/spawn-on-demand/13-trigger-runahead/flow.cylc +++ b/tests/functional/spawn-on-demand/13-trigger-runahead/flow.cylc @@ -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 diff --git a/tests/functional/spawn-on-demand/14-trigger-flow-blocker/flow.cylc b/tests/functional/spawn-on-demand/14-trigger-flow-blocker/flow.cylc index 9c205e301c5..7e41a3abcb7 100644 --- a/tests/functional/spawn-on-demand/14-trigger-flow-blocker/flow.cylc +++ b/tests/functional/spawn-on-demand/14-trigger-flow-blocker/flow.cylc @@ -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 diff --git a/tests/integration/scripts/test_dump.py b/tests/integration/scripts/test_dump.py index 681167a564f..2dff651020a 100644 --- a/tests/integration/scripts/test_dump.py +++ b/tests/integration/scripts/test_dump.py @@ -24,7 +24,6 @@ get_option_parser, ) - DumpOptions = Options(get_option_parser()) @@ -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]', + ]