-
Notifications
You must be signed in to change notification settings - Fork 94
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
Kill tasks during job prep #6535
Open
MetRonnie
wants to merge
7
commits into
cylc:8.4.x
Choose a base branch
from
MetRonnie:kill-prep
base: 8.4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d3be5ec
Tidy
MetRonnie 21be5b0
Kill tasks during job prep
MetRonnie da76cf4
Add tests for `cylc kill` handlers & retries behaviour
MetRonnie 02a025e
Replace functional test with integration test
MetRonnie 9146357
Fix return value of `Scheduler.start_job_submission()`
MetRonnie 475962b
Add test
MetRonnie adf59f3
Mypy
MetRonnie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Ensure tasks can be killed while in the preparing state. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,11 @@ | |
|
||
|
||
if TYPE_CHECKING: | ||
# BACK COMPAT: typing_extensions.Literal | ||
# FROM: Python 3.7 | ||
# TO: Python 3.8 | ||
from typing_extensions import Literal | ||
|
||
from cylc.flow.task_proxy import TaskProxy | ||
from cylc.flow.workflow_db_mgr import WorkflowDatabaseManager | ||
|
||
|
@@ -156,10 +161,10 @@ class TaskJobManager: | |
|
||
def __init__(self, workflow, proc_pool, workflow_db_mgr, | ||
task_events_mgr, data_store_mgr, bad_hosts): | ||
self.workflow = workflow | ||
self.workflow: str = workflow | ||
self.proc_pool = proc_pool | ||
self.workflow_db_mgr: WorkflowDatabaseManager = workflow_db_mgr | ||
self.task_events_mgr = task_events_mgr | ||
self.task_events_mgr: TaskEventsManager = task_events_mgr | ||
self.data_store_mgr = data_store_mgr | ||
self.job_file_writer = JobFileWriter() | ||
self.job_runner_mgr = self.job_file_writer.job_runner_mgr | ||
|
@@ -196,6 +201,15 @@ def kill_task_jobs( | |
self._kill_task_jobs_callback_255 | ||
) | ||
|
||
def kill_prep_task(self, itask: 'TaskProxy') -> None: | ||
"""Kill a preparing task.""" | ||
itask.waiting_on_job_prep = False | ||
itask.local_job_file_path = None # reset for retry | ||
self._set_retry_timers(itask) | ||
self._prep_submit_task_job_error( | ||
self.workflow, itask, '(killed in job prep)', '' | ||
) | ||
|
||
def poll_task_jobs(self, workflow, itasks, msg=None): | ||
"""Poll jobs of specified tasks. | ||
|
||
|
@@ -220,14 +234,19 @@ def poll_task_jobs(self, workflow, itasks, msg=None): | |
self._poll_task_jobs_callback_255 | ||
) | ||
|
||
def prep_submit_task_jobs(self, workflow, itasks, check_syntax=True): | ||
def prep_submit_task_jobs( | ||
self, | ||
workflow: str, | ||
itasks: 'Iterable[TaskProxy]', | ||
check_syntax: bool = True, | ||
) -> 'Tuple[List[TaskProxy], List[TaskProxy]]': | ||
"""Prepare task jobs for submit. | ||
|
||
Prepare tasks where possible. Ignore tasks that are waiting for host | ||
select command to complete. Bad host select command or error writing to | ||
a job file will cause a bad task - leading to submission failure. | ||
|
||
Return [list, list]: list of good tasks, list of bad tasks | ||
Return (good_tasks, bad_tasks) | ||
""" | ||
prepared_tasks = [] | ||
bad_tasks = [] | ||
|
@@ -244,16 +263,16 @@ def prep_submit_task_jobs(self, workflow, itasks, check_syntax=True): | |
prepared_tasks.append(itask) | ||
elif prep_task is False: | ||
bad_tasks.append(itask) | ||
return [prepared_tasks, bad_tasks] | ||
return (prepared_tasks, bad_tasks) | ||
|
||
def submit_task_jobs( | ||
self, | ||
workflow, | ||
itasks, | ||
itasks: 'Iterable[TaskProxy]', | ||
curve_auth, | ||
client_pub_key_dir, | ||
run_mode: RunMode = RunMode.LIVE, | ||
): | ||
) -> 'List[TaskProxy]': | ||
"""Prepare for job submission and submit task jobs. | ||
|
||
Preparation (host selection, remote host init, and remote install) | ||
|
@@ -264,7 +283,7 @@ def submit_task_jobs( | |
Once preparation has completed or failed, reset .waiting_on_job_prep in | ||
task instances so the scheduler knows to stop sending them back here. | ||
|
||
This method uses prep_submit_task_job() as helper. | ||
This method uses prep_submit_task_jobs() as helper. | ||
|
||
Return (list): list of tasks that attempted submission. | ||
""" | ||
|
@@ -327,7 +346,7 @@ def submit_livelike_task_jobs( | |
bc_mgr = self.task_events_mgr.broadcast_mgr | ||
rtconf = bc_mgr.get_updated_rtconfig(itask) | ||
try: | ||
platform = get_platform( | ||
platform = get_platform( # type: ignore[assignment] | ||
rtconf, | ||
bad_hosts=self.bad_hosts | ||
) | ||
|
@@ -1029,7 +1048,7 @@ def _set_retry_timers( | |
def submit_nonlive_task_jobs( | ||
self: 'TaskJobManager', | ||
workflow: str, | ||
itasks: 'List[TaskProxy]', | ||
itasks: 'Iterable[TaskProxy]', | ||
workflow_run_mode: RunMode, | ||
) -> 'Tuple[List[TaskProxy], List[TaskProxy]]': | ||
"""Identify task mode and carry out alternative submission | ||
|
@@ -1152,7 +1171,7 @@ def _prep_submit_task_job( | |
workflow: str, | ||
itask: 'TaskProxy', | ||
check_syntax: bool = True | ||
): | ||
) -> 'Union[TaskProxy, None, Literal[False]]': | ||
"""Prepare a task job submission. | ||
|
||
Returns: | ||
|
@@ -1217,7 +1236,7 @@ def _prep_submit_task_job( | |
else: | ||
# host/platform select not ready | ||
if host_n is None and platform_name is None: | ||
return | ||
return None | ||
elif ( | ||
host_n is None | ||
and rtconfig['platform'] | ||
|
@@ -1259,7 +1278,7 @@ def _prep_submit_task_job( | |
workflow, itask, '(platform not defined)', exc) | ||
return False | ||
else: | ||
itask.platform = platform | ||
itask.platform = platform # type: ignore[assignment] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in #6564 |
||
# Retry delays, needed for the try_num | ||
self._set_retry_timers(itask, rtconfig) | ||
|
||
|
@@ -1292,7 +1311,13 @@ def _prep_submit_task_job( | |
itask.local_job_file_path = local_job_file_path | ||
return itask | ||
|
||
def _prep_submit_task_job_error(self, workflow, itask, action, exc): | ||
def _prep_submit_task_job_error( | ||
self, | ||
workflow: str, | ||
itask: 'TaskProxy', | ||
action: str, | ||
exc: Union[Exception, str], | ||
) -> None: | ||
"""Helper for self._prep_submit_task_job. On error.""" | ||
log_task_job_activity( | ||
SubProcContext(self.JOBS_SUBMIT, action, err=exc, ret_code=1), | ||
|
@@ -1306,11 +1331,12 @@ def _prep_submit_task_job_error(self, workflow, itask, action, exc): | |
# than submit-failed | ||
# provide a dummy job config - this info will be added to the data | ||
# store | ||
try_num = itask.get_try_num() | ||
itask.jobs.append({ | ||
'task_id': itask.identity, | ||
'platform': itask.platform, | ||
'submit_num': itask.submit_num, | ||
'try_num': itask.get_try_num(), | ||
'try_num': try_num, | ||
}) | ||
# create a DB entry for the submit-failed job | ||
self.workflow_db_mgr.put_insert_task_jobs( | ||
|
@@ -1319,7 +1345,7 @@ def _prep_submit_task_job_error(self, workflow, itask, action, exc): | |
'flow_nums': serialise_set(itask.flow_nums), | ||
'job_id': itask.summary.get('submit_method_id'), | ||
'is_manual_submit': itask.is_manual_submit, | ||
'try_num': itask.get_try_num(), | ||
'try_num': try_num, | ||
'time_submit': get_current_time_string(), | ||
'platform_name': itask.platform['name'], | ||
'job_runner_name': itask.summary['job_runner_name'], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bash | ||
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. | ||
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
# Test event handlers when killing running/submitted/preparing tasks. | ||
# Any downstream tasks that depend on the `:submit-fail`/`:fail` outputs | ||
# SHOULD run. | ||
# Handlers for the `submission failed`/`failed` events SHOULD run. | ||
|
||
export REQUIRE_PLATFORM='runner:at' | ||
. "$(dirname "$0")/test_header" | ||
set_test_number 5 | ||
|
||
# Create platform that ensures job will be in submitted state for long enough | ||
create_test_global_config '' " | ||
[platforms] | ||
[[old_street]] | ||
job runner = at | ||
job runner command template = at now + 5 minutes | ||
hosts = localhost | ||
install target = localhost | ||
" | ||
|
||
install_and_validate | ||
reftest_run | ||
|
||
grep_workflow_log_ok "grep-a" "[(('event-handler-00', 'failed'), 1) out] 1/a" -F | ||
|
||
for task in b c; do | ||
grep_workflow_log_ok "grep-${task}" \ | ||
"[(('event-handler-00', 'submission failed'), 1) out] 1/${task}" -F | ||
done | ||
|
||
purge |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in #6564