From 67cba6ac49d0aed801ab95eabba687d5346f7ac9 Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Wed, 9 Feb 2022 11:02:34 +0000 Subject: [PATCH 1/2] tasks: add the preparing state to active state checks --- cylc/flow/scheduler.py | 2 ++ cylc/flow/task_pool.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cylc/flow/scheduler.py b/cylc/flow/scheduler.py index 9164d950536..dfa0c19c4c5 100644 --- a/cylc/flow/scheduler.py +++ b/cylc/flow/scheduler.py @@ -737,6 +737,8 @@ def restart_remote_init(self): itask.platform['install target'] = ( get_install_target_from_platform(itask.platform)) if ( + # we don't need to remote-init for preparing tasks because + # they will be reset to waiting on restart itask.state(*TASK_STATUSES_ACTIVE) and not ( is_platform_with_target_in_list( diff --git a/cylc/flow/task_pool.py b/cylc/flow/task_pool.py index 6c9cc51148b..fba58236342 100644 --- a/cylc/flow/task_pool.py +++ b/cylc/flow/task_pool.py @@ -822,7 +822,7 @@ def reload_taskdefs(self) -> None: itask.copy_to_reload_successor(new_task) self._swap_out(new_task) LOG.info(f"[{itask}] reloaded task definition") - if itask.state(*TASK_STATUSES_ACTIVE): + if itask.state(*TASK_STATUSES_ACTIVE, TASK_STATUS_PREPARING): LOG.warning( f"[{itask}] active with pre-reload settings" ) @@ -898,6 +898,8 @@ def can_stop(self, stop_mode): and itask.state(*TASK_STATUSES_ACTIVE) and not itask.state.kill_failed ) + # we don't need to check for preparing tasks because they will be + # reset to waiting on restart for itask in self.get_tasks() ) From b0f092abadc3d16f22bfdc38989ce4bc411d7bd0 Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Thu, 10 Feb 2022 10:11:38 +0000 Subject: [PATCH 2/2] tests/i: test preparing tasks are reset to waiting on restart --- tests/integration/test_task_pool.py | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/integration/test_task_pool.py b/tests/integration/test_task_pool.py index 064426b238b..83c2dac4029 100644 --- a/tests/integration/test_task_pool.py +++ b/tests/integration/test_task_pool.py @@ -438,3 +438,34 @@ async def test_trigger_states(status, should_trigger, one, run): # check whether the task triggered assert task.is_manual_submit == should_trigger + + +async def test_preparing_tasks_on_restart(one_conf, flow, scheduler, run): + """Preparing tasks should be reset to waiting on restart. + + This forces preparation to be re-done on restart so that it uses the + new configuration. + + See discussion on: https://github.com/cylc/cylc-flow/pull/4668 + + """ + id_ = flow(one_conf) + + # start the workflow, reset a task to preparing + one = scheduler(id_) + async with run(one): + task = one.pool.filter_task_proxies(['*'])[0][0] + task.state.reset(TASK_STATUS_PREPARING) + + # when we restart the task should have been reset to waiting + one = scheduler(id_) + async with run(one): + task = one.pool.filter_task_proxies(['*'])[0][0] + assert task.state(TASK_STATUS_WAITING) + task.state.reset(TASK_STATUS_SUCCEEDED) + + # whereas if we reset the task to succeeded the state is not reset + one = scheduler(id_) + async with run(one): + task = one.pool.filter_task_proxies(['*'])[0][0] + assert task.state(TASK_STATUS_SUCCEEDED)