Skip to content

Commit

Permalink
Fix setting task run mode in Edit Runtime (#65)
Browse files Browse the repository at this point in the history
* Fix run mode printed in scheduler log

* Fix setting task run mode in Edit Runtime
  • Loading branch information
MetRonnie authored Nov 19, 2024
1 parent 10dbd39 commit 46f29b7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
8 changes: 3 additions & 5 deletions cylc/flow/network/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
from cylc.flow.id import Tokens
from cylc.flow.network.schema import (
DEF_TYPES,
RUNTIME_FIELD_TO_CFG_MAP,
NodesEdges,
PROXY_NODES,
SUB_RESOLVERS,
runtime_schema_to_cfg,
sort_elements,
)

Expand Down Expand Up @@ -791,10 +791,8 @@ def broadcast(
# Convert schema field names to workflow config setting names if
# applicable:
for i, dict_ in enumerate(settings):
settings[i] = {
RUNTIME_FIELD_TO_CFG_MAP.get(key, key): value
for key, value in dict_.items()
}
settings[i] = runtime_schema_to_cfg(dict_)

if mode == 'put_broadcast':
return self.schd.task_events_mgr.broadcast_mgr.put_broadcast(
cycle_points, namespaces, settings)
Expand Down
14 changes: 14 additions & 0 deletions cylc/flow/network/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,20 @@ class Meta:
"""Map GQL Runtime fields' names to workflow config setting names."""


def runtime_schema_to_cfg(runtime: dict) -> dict:
"""Covert GQL Runtime field names to workflow config setting names and
perform any necessary processing on the values."""
# We have to manually lowercase the run_mode field because we don't define
# a proper schema for BroadcastSetting (it's just GenericScalar) so
# Graphene has no way to know that it should be a TaskRunMode enum.
return {
RUNTIME_FIELD_TO_CFG_MAP.get(key, key): (
value.lower() if key == 'run_mode' else value
)
for key, value in runtime.items()
}


class Job(ObjectType):
class Meta:
description = "Jobs."
Expand Down
2 changes: 1 addition & 1 deletion cylc/flow/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def log_start(self) -> None:
# Note that the following lines must be present at the top of
# the workflow log file for use in reference test runs.
LOG.info(
f'Run mode: {self.get_run_mode()}',
f'Run mode: {self.get_run_mode().value}',
extra=RotatingLogFileHandler.header_extra
)
LOG.info(
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/network/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
RUNTIME_FIELD_TO_CFG_MAP,
Mutations,
Runtime,
runtime_schema_to_cfg,
sort_elements,
SortArgs,
)
Expand Down Expand Up @@ -105,6 +106,20 @@ def test_runtime_field_to_cfg_map(field_name: str):
assert WORKFLOW_SPEC.get('runtime', '__MANY__', cfg_name)


@pytest.mark.parametrize('runtime_dict,expected', [
pytest.param(
{'run_mode': 'Skip'}, {'run mode': 'skip'}, id='edit-runtime'
),
pytest.param(
{'run mode': 'skip'}, {'run mode': 'skip'}, id='broadcast'
),
])
def test_runtime_schema_to_cfg(runtime_dict, expected):
"""Test this function can handle Edit Runtime submitted values as well
as normal broadcast values."""
assert runtime_schema_to_cfg(runtime_dict) == expected


@pytest.mark.parametrize('mutation', (
pytest.param(attr, id=name)
for name, attr in Mutations.__dict__.items()
Expand Down

0 comments on commit 46f29b7

Please sign in to comment.