Skip to content

Commit

Permalink
Distribute log files across subdirs.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleGower committed Oct 26, 2023
1 parent 0782abd commit a22b6a8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/lsst.ctrl.bps.parsl/use.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ The following configuration settings can be used in configuring the plugin:
* ``parsl.log_level`` (`str`): logging level for Parsl; may be one of ``CRITICAL``, ``DEBUG``, ``ERROR``, ``FATAL``, ``INFO``, ``WARN``.
* ``project`` (`str`): project name; defaults to ``bps``.
* ``campaign`` (`str`): campaign name; defaults to the user name (which can also be set via the ``username`` setting).
* ``subDirTemplate`` (`str`): template used to define log subdirectories in order to avoid having too many files in a single directory; defaults to a very generic template defined by ctrl_bps in bps_defaults.yaml_. To run with no subdirectories (original plugin behavior), in the submit yaml set ``subDirTemplate`` to the empty string (``subDirTemplate: ''``).

.. _bps_defaults.yaml: https://github.com/lsst/ctrl_bps/blob/main/python/lsst/ctrl/bps/etc/bps_defaults.yaml

The workflow job name is taken to be ``<project>.<campaign>``.

Expand Down
23 changes: 21 additions & 2 deletions python/lsst/ctrl/bps/parsl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import os
import re
import subprocess
from collections import defaultdict
from collections.abc import Sequence
from functools import partial
from textwrap import dedent
Expand Down Expand Up @@ -120,9 +121,25 @@ def __init__(
self.file_paths = file_paths
self.future = None
self.done = False

# Determine directory for job stdout and stderr
log_dir = os.path.join(get_bps_config_value(self.config, "submitPath", str, required=True), "logs")
self.stdout = os.path.join(log_dir, self.name + ".stdout")
self.stderr = os.path.join(log_dir, self.name + ".stderr")
_, template = self.config.search(

Check warning on line 127 in python/lsst/ctrl/bps/parsl/job.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/bps/parsl/job.py#L127

Added line #L127 was not covered by tests
"subDirTemplate",
opt={
"curvals": {"curr_site": self.config["computeSite"], "curr_cluster": self.generic.label},
"replaceVars": False,
"default": "",
},
)
job_vals = defaultdict(str)
job_vals["label"] = self.generic.label

Check warning on line 136 in python/lsst/ctrl/bps/parsl/job.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/bps/parsl/job.py#L135-L136

Added lines #L135 - L136 were not covered by tests
if self.generic.tags:
job_vals.update(self.generic.tags)
subdir = os.path.normpath(template.format_map(job_vals))

Check warning on line 139 in python/lsst/ctrl/bps/parsl/job.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/bps/parsl/job.py#L138-L139

Added lines #L138 - L139 were not covered by tests

self.stdout = os.path.join(log_dir, subdir, self.name + ".stdout")
self.stderr = os.path.join(log_dir, subdir, self.name + ".stderr")

Check warning on line 142 in python/lsst/ctrl/bps/parsl/job.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/bps/parsl/job.py#L141-L142

Added lines #L141 - L142 were not covered by tests

def __reduce__(self):
"""Recipe for pickling"""
Expand Down Expand Up @@ -288,6 +305,8 @@ def run_local(self):
return
command = self.get_command_line(False)
command = self.evaluate_command_line(command)
os.makedirs(os.path.dirname(self.stdout), exist_ok=True)
os.makedirs(os.path.dirname(self.stderr), exist_ok=True)

Check warning on line 309 in python/lsst/ctrl/bps/parsl/job.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/bps/parsl/job.py#L308-L309

Added lines #L308 - L309 were not covered by tests
with open(self.stdout, "w") as stdout, open(self.stderr, "w") as stderr:
subprocess.check_call(command, shell=True, executable="/bin/bash", stdout=stdout, stderr=stderr)
self.done = True

0 comments on commit a22b6a8

Please sign in to comment.