1919from collections import deque
2020from contextlib import suppress
2121import itertools
22+ import logging
2223import os
2324from pathlib import Path
2425from queue import (
8283 FLOW_NONE ,
8384 FlowMgr ,
8485 repr_flow_nums ,
86+ stringify_flow_nums ,
8587)
8688from cylc .flow .host_select import (
8789 HostSelectException ,
@@ -440,7 +442,8 @@ async def initialise(self):
440442 self .workflow_db_mgr ,
441443 self .task_events_mgr ,
442444 self .data_store_mgr ,
443- self .bad_hosts
445+ self .bad_hosts ,
446+ self .server ,
444447 )
445448
446449 self .profiler = Profiler (self , self .options .profile_mode )
@@ -910,9 +913,7 @@ def restart_remote_init(self):
910913 if install_target == get_localhost_install_target ():
911914 continue
912915 # set off remote init
913- self .task_job_mgr .task_remote_mgr .remote_init (
914- platform , self .server .curve_auth ,
915- self .server .client_pub_key_dir )
916+ self .task_job_mgr .task_remote_mgr .remote_init (platform )
916917 # Remote init/file-install is done via process pool
917918 self .proc_pool .process ()
918919 # add platform to map (to be picked up on main loop)
@@ -1078,18 +1079,21 @@ def kill_tasks(
10781079 to_kill : List [TaskProxy ] = []
10791080 unkillable : List [TaskProxy ] = []
10801081 for itask in itasks :
1081- if itask .state (* TASK_STATUSES_ACTIVE ):
1082- if itask .state_reset (is_held = True ):
1083- self .data_store_mgr .delta_task_state (itask )
1082+ if not itask .state (TASK_STATUS_PREPARING , * TASK_STATUSES_ACTIVE ):
1083+ unkillable .append (itask )
1084+ continue
1085+ if itask .state_reset (is_held = True ):
1086+ self .data_store_mgr .delta_task_state (itask )
1087+ if itask .state (TASK_STATUS_PREPARING ):
1088+ self .task_job_mgr .kill_prep_task (itask )
1089+ else :
10841090 to_kill .append (itask )
10851091 if jobless :
10861092 # Directly set failed in sim mode:
10871093 self .task_events_mgr .process_message (
10881094 itask , 'CRITICAL' , TASK_STATUS_FAILED ,
10891095 flag = self .task_events_mgr .FLAG_RECEIVED
10901096 )
1091- else :
1092- unkillable .append (itask )
10931097 if warn and unkillable :
10941098 LOG .warning (
10951099 "Tasks not killable: "
@@ -1250,6 +1254,7 @@ def get_contact_data(self) -> Dict[str, str]:
12501254 """
12511255 fields = workflow_files .ContactFileFields
12521256 proc = psutil .Process ()
1257+ platform = get_platform ()
12531258 # fmt: off
12541259 return {
12551260 fields .API :
@@ -1275,11 +1280,11 @@ def get_contact_data(self) -> Dict[str, str]:
12751280 fields .VERSION :
12761281 CYLC_VERSION ,
12771282 fields .SCHEDULER_SSH_COMMAND :
1278- str (get_platform () ['ssh command' ]),
1283+ str (platform ['ssh command' ]),
12791284 fields .SCHEDULER_CYLC_PATH :
1280- str (get_platform () ['cylc path' ]),
1285+ str (platform ['cylc path' ]),
12811286 fields .SCHEDULER_USE_LOGIN_SHELL :
1282- str (get_platform () ['use login shell' ])
1287+ str (platform ['use login shell' ])
12831288 }
12841289 # fmt: on
12851290
@@ -1531,29 +1536,32 @@ def start_job_submission(self, itasks: 'Iterable[TaskProxy]') -> bool:
15311536 self .task_job_mgr .task_remote_mgr .rsync_includes = (
15321537 self .config .get_validated_rsync_includes ())
15331538
1534- log = LOG .debug
1539+ submitted = self .submit_task_jobs (itasks )
1540+ if not submitted :
1541+ return False
1542+
1543+ log_lvl = logging .DEBUG
15351544 if self .options .reftest or self .options .genref :
1536- log = LOG . info
1545+ log_lvl = logging . INFO
15371546
1538- for itask in self .task_job_mgr .submit_task_jobs (
1539- self .workflow ,
1540- itasks ,
1541- self .server .curve_auth ,
1542- self .server .client_pub_key_dir ,
1543- run_mode = self .get_run_mode ()
1544- ):
1545- if itask .flow_nums :
1546- flow = ',' .join (str (i ) for i in itask .flow_nums )
1547- else :
1548- flow = FLOW_NONE
1549- log (
1547+ for itask in submitted :
1548+ flow = stringify_flow_nums (itask .flow_nums ) or FLOW_NONE
1549+ LOG .log (
1550+ log_lvl ,
15501551 f"{ itask .identity } -triggered off "
15511552 f"{ itask .state .get_resolved_dependencies ()} in flow { flow } "
15521553 )
15531554
15541555 # one or more tasks were passed through the submission pipeline
15551556 return True
15561557
1558+ def submit_task_jobs (
1559+ self , itasks : 'Iterable[TaskProxy]'
1560+ ) -> 'List[TaskProxy]' :
1561+ """Submit task jobs, return tasks that attempted submission."""
1562+ # Note: keep this as simple wrapper for task job mgr's method
1563+ return self .task_job_mgr .submit_task_jobs (itasks , self .get_run_mode ())
1564+
15571565 def process_workflow_db_queue (self ):
15581566 """Update workflow DB."""
15591567 self .workflow_db_mgr .process_queued_ops ()
0 commit comments