Skip to content

Commit 5991b5f

Browse files
committed
selection function
1 parent 51b3add commit 5991b5f

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

executorlib/executor/flux.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,13 @@ def __init__(
360360
create_file_executor,
361361
)
362362

363-
if terminate_tasks_on_shutdown:
364-
from executorlib.task_scheduler.file.queue_spawner import (
365-
terminate_with_pysqa,
366-
)
363+
from executorlib.task_scheduler.file.queue_spawner import (
364+
get_terminate_function,
365+
)
367366

368-
terminate_function = terminate_with_pysqa
369-
else:
370-
terminate_function = None
367+
terminate_function = get_terminate_function(
368+
terminate_tasks_on_shutdown=terminate_tasks_on_shutdown
369+
)
371370

372371
super().__init__(
373372
executor=create_file_executor(

executorlib/executor/slurm.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,13 @@ def __init__(
166166
create_file_executor,
167167
)
168168

169-
if terminate_tasks_on_shutdown:
170-
from executorlib.task_scheduler.file.queue_spawner import (
171-
terminate_with_pysqa,
172-
)
169+
from executorlib.task_scheduler.file.queue_spawner import (
170+
get_terminate_function,
171+
)
173172

174-
terminate_function = terminate_with_pysqa
175-
else:
176-
terminate_function = None
173+
terminate_function = get_terminate_function(
174+
terminate_tasks_on_shutdown=terminate_tasks_on_shutdown
175+
)
177176

178177
super().__init__(
179178
executor=create_file_executor(

executorlib/task_scheduler/file/queue_spawner.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,17 @@ def _pysqa_execute_command(
138138
return out.split("\n")
139139
else:
140140
return out
141+
142+
143+
def get_terminate_function(terminate_tasks_on_shutdown: bool) -> Optional[callable]:
144+
"""
145+
Get the appropriate terminate function based on the shutdown configuration.
146+
147+
Args:
148+
terminate_tasks_on_shutdown (bool): Flag indicating whether to terminate tasks on shutdown.
149+
150+
Returns:
151+
Optional[callable]: The terminate function to use, or None if no termination is needed.
152+
"""
153+
if terminate_tasks_on_shutdown:
154+
return terminate_with_pysqa

0 commit comments

Comments
 (0)