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

Prevent commands which take Tasks IDs taking Job IDs. #6130

Merged
merged 9 commits into from
Jun 24, 2024
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
1 change: 1 addition & 0 deletions changes.d/6130.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent commands taking a list of task ID's from submitting job ids.
36 changes: 36 additions & 0 deletions cylc/flow/command_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,39 @@ def consistency(
"""
if outputs and prereqs:
raise InputError("Use --prerequisite or --output, not both.")


def is_tasks(tasks: List[str]):
"""All tasks in a list of tasks are task ID's
without trailing job ID.
Examples:

# All legal
>>> is_tasks(['1/foo', '1/bar', '*/baz', '*/*'])
True

# Some legal
>>> is_tasks(['1/foo/NN', '1/bar', '*/baz', '*/*/42'])
Traceback (most recent call last):
...
Exception: This command does not take job ids:
* 1/foo/NN
* */*/42

# None legal
>>> is_tasks(['1/', '*/baz/12'])
Traceback (most recent call last):
...
Exception: This command does not take job ids:
* 1/
* */baz/12
"""
bad_tasks: List[str] = []
for task in tasks:
tokens = Tokens('//' + task)
if tokens.lowest_token < 'task':
bad_tasks.append(task)
if bad_tasks:
msg = 'This command does not take job ids:\n * '
raise Exception(msg + '\n * '.join(bad_tasks))
return True
6 changes: 6 additions & 0 deletions cylc/flow/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ async def stop(
@_command('release')
async def release(schd: 'Scheduler', tasks: Iterable[str]):
"""Release held tasks."""
validate.is_tasks(tasks)
yield
yield schd.pool.release_held_tasks(tasks)

Expand All @@ -237,6 +238,7 @@ async def resume(schd: 'Scheduler'):
@_command('poll_tasks')
async def poll_tasks(schd: 'Scheduler', tasks: Iterable[str]):
"""Poll pollable tasks or a task or family if options are provided."""
validate.is_tasks(tasks)
yield
if schd.get_run_mode() == RunMode.SIMULATION:
yield 0
Expand All @@ -248,6 +250,7 @@ async def poll_tasks(schd: 'Scheduler', tasks: Iterable[str]):
@_command('kill_tasks')
async def kill_tasks(schd: 'Scheduler', tasks: Iterable[str]):
"""Kill all tasks or a task/family if options are provided."""
validate.is_tasks(tasks)
yield
itasks, _, bad_items = schd.pool.filter_task_proxies(tasks)
if schd.get_run_mode() == RunMode.SIMULATION:
Expand All @@ -264,6 +267,7 @@ async def kill_tasks(schd: 'Scheduler', tasks: Iterable[str]):
@_command('hold')
async def hold(schd: 'Scheduler', tasks: Iterable[str]):
"""Hold specified tasks."""
validate.is_tasks(tasks)
yield
yield schd.pool.hold_tasks(tasks)

Expand Down Expand Up @@ -304,6 +308,7 @@ async def set_verbosity(schd: 'Scheduler', level: Union[int, str]):
@_command('remove_tasks')
async def remove_tasks(schd: 'Scheduler', tasks: Iterable[str]):
"""Remove tasks."""
validate.is_tasks(tasks)
yield
yield schd.pool.remove_tasks(tasks)

Expand Down Expand Up @@ -430,5 +435,6 @@ async def force_trigger_tasks(
flow_descr: Optional[str] = None,
):
"""Manual task trigger."""
validate.is_tasks(tasks)
yield
yield schd.pool.force_trigger_tasks(tasks, flow, flow_wait, flow_descr)
Loading