Skip to content

Commit

Permalink
Make sure the --batchLogsDir exists if it is set (#4635)
Browse files Browse the repository at this point in the history
* Make sure the batch logs dir exists if it is set

* Test Slurm with nonexistent --batchLogsDir
  • Loading branch information
adamnovak authored Oct 19, 2023
1 parent 6c0fe1e commit c1361d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contrib/slurm-test/slurm_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ docker exec ${LEADER} sudo apt install python3-pip -y
docker exec ${LEADER} pip3 install "git+https://github.com/DataBiosphere/toil.git@${GIT_COMMIT}"
docker exec ${LEADER} sinfo -N -l
# Test 1: A really basic workflow to check Slurm is working correctly
docker exec ${LEADER} python3 /home/admin/toil_workflow.py file:my-job-store --batchSystem slurm --disableCaching --retryCount 0
docker exec ${LEADER} python3 /home/admin/toil_workflow.py file:my-job-store --batchSystem slurm --disableCaching --retryCount 0 --batchLogsDir ./nonexistent/paths
docker cp ${LEADER}:/home/admin/output.txt output_Docker.txt
# Test 2: Make sure that "sort" workflow runs under slurm
docker exec ${LEADER} python3 /home/admin/sort.py file:my-job-store --batchSystem slurm --disableCaching --retryCount 0
Expand Down
5 changes: 5 additions & 0 deletions src/toil/batchSystems/abstractBatchSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from toil.deferred import DeferredFunctionManager
from toil.fileStores.abstractFileStore import AbstractFileStore
from toil.job import JobDescription, ParsedRequirement, Requirer
from toil.lib.memoize import memoize
from toil.resource import Resource

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -392,6 +393,7 @@ def set_message_bus(self, message_bus: MessageBus) -> None:
# We do in fact send messages to the message bus.
self._outbox = message_bus.outbox()

@memoize
def get_batch_logs_dir(self) -> str:
"""
Get the directory where the backing batch system should save its logs.
Expand All @@ -404,6 +406,9 @@ def get_batch_logs_dir(self) -> str:
"""
if self.config.batch_logs_dir:
# Use what is specified
if not os.path.isdir(self.config.batch_logs_dir):
# But if it doesn't exist, make it exist
os.makedirs(self.config.batch_logs_dir, exist_ok=True)
return self.config.batch_logs_dir
# And if nothing is specified use the workDir.
return Toil.getToilWorkDir(self.config.workDir)
Expand Down

0 comments on commit c1361d4

Please sign in to comment.