Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f50794c
feat: added flags for intended logfile behaviour - no code, yet
cmeesters Oct 20, 2024
b64b3a9
fix: syntax errors and formatting
cmeesters Oct 21, 2024
a7d9df7
fix: working interface
cmeesters Oct 31, 2024
5133877
Merge branch 'main' into feat/logfeatures
cmeesters Nov 7, 2024
9c68936
fix: log prefix instead of logdir. - not working
cmeesters Nov 7, 2024
099292e
Merge branch 'main' into feat/logfeatures
cmeesters Nov 11, 2024
db4172a
feat: implementing all features as described
cmeesters Nov 18, 2024
0d6a200
fix: removed unnecessary pathlib import
cmeesters Nov 18, 2024
34adb4e
fix: lininting issues
cmeesters Nov 18, 2024
730433f
fix: using atexit to decouple the function from __del__, moved all co…
cmeesters Nov 19, 2024
490a7c3
fix: deleted unused import
cmeesters Nov 19, 2024
a9ff35c
fix: deleted unused import
cmeesters Nov 19, 2024
e567349
fix: linting issues
cmeesters Nov 19, 2024
4770c8b
fix: linting issues II
cmeesters Nov 19, 2024
9cc019b
feat: not rellying on '/home/$USER' any more, this is dangerous. Inst…
cmeesters Nov 19, 2024
bfd9cd6
fix: removed trailing whitespace
cmeesters Nov 19, 2024
d7e0e93
fix: using os.path.join for path concatenation, like it should be
cmeesters Nov 19, 2024
39cf201
Update snakemake_executor_plugin_slurm/__init__.py
cmeesters Nov 19, 2024
568080a
Merge branch 'feat/logfeatures' of github.com:snakemake/snakemake-exe…
cmeesters Nov 19, 2024
e727989
fix: formatting and linting
cmeesters Nov 19, 2024
51ae157
fix: moved cleanup code before __post_init__
cmeesters Nov 19, 2024
e43f108
fix: removed one more trailing whitespace
cmeesters Nov 19, 2024
88b6705
fix: those who want to keep all logs should be pleased
cmeesters Nov 19, 2024
009e216
docs: documenting the new feature
cmeesters Nov 19, 2024
8260f6b
fix: removed table of command line flags special to the executor - it…
cmeesters Dec 5, 2024
f750600
feat: same code - based on on the pathlib library
cmeesters Dec 9, 2024
b661dd8
Update snakemake_executor_plugin_slurm/utils.py
cmeesters Jan 2, 2025
aaad25d
fix: no multiline warnings
cmeesters Jan 2, 2025
6f74d18
fix: removed outcommented code
cmeesters Jan 2, 2025
63b4f59
fix: reordered such that functions follow 'post_init'
cmeesters Jan 2, 2025
829a889
fix: converted help strings to single line strings
cmeesters Jan 2, 2025
c9c0eed
fix: reverted to previous default of logging in workdir
cmeesters Jan 6, 2025
8a18089
fix: back to default SLURM logdir NOT being in HOME, all code now bas…
cmeesters Jan 7, 2025
1ef9e98
fix: removed (once more) the additional flags section
cmeesters Jan 7, 2025
9764842
feat: documentation on the new features
cmeesters Jan 7, 2025
59cf40e
Update snakemake_executor_plugin_slurm/utils.py
cmeesters Jan 7, 2025
c9c7b8e
fix: recursively deleting log subdirs
cmeesters Jan 8, 2025
739f878
Update snakemake_executor_plugin_slurm/__init__.py
johanneskoester Jan 8, 2025
d6f5567
Update snakemake_executor_plugin_slurm/__init__.py
johanneskoester Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions snakemake_executor_plugin_slurm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class ExecutorSettings(ExecutorSettingsBase):
default=40,
metadata={
"help": """
Defines the time in seconds before the first status
check is performed after job submission.
Defines the time in seconds before the first
status check is performed after job submission.
""",
"env_var": False,
"required": False,
Expand All @@ -47,7 +47,8 @@ class ExecutorSettings(ExecutorSettingsBase):
metadata={
"help": """
Allow requeuing preempted of failed jobs,
if no cluster default. Results in `sbatch ... --requeue ...`
if no cluster default. Results in
`sbatch ... --requeue ...`.
This flag has no effect, if not set.
""",
"env_var": False,
Expand All @@ -62,7 +63,8 @@ class ExecutorSettings(ExecutorSettingsBase):
# define whether your executor plugin executes locally
# or remotely. In virtually all cases, it will be remote execution
# (cluster, cloud, etc.). Only Snakemake's standard execution
# plugins (snakemake-executor-plugin-dryrun, snakemake-executor-plugin-local)
# plugins (snakemake-executor-plugin-dryrun,
# snakemake-executor-plugin-local)
# are expected to specify False here.
non_local_exec=True,
# Define whether your executor plugin implies that there is no shared
Expand Down Expand Up @@ -107,6 +109,30 @@ def warn_on_jobcontext(self, done=None):
def additional_general_args(self):
return "--executor slurm-jobstep --jobs 1"

def run_jobs(
self,
jobs: List[JobExecutorInterface],
):
"""Run a list of jobs that is ready at a given point in time.

By default, this method just runs each job individually.
This method is overwritten in the executor plugin to implement
- SLURM array jobs.
- pooled jobs (currently in planning)
"""
self.logger.debug(f"jobs: {jobs}")
# self.logger.debug(f"job attributes: {dir(jobs[0])}")
self.logger.debug(f"jobs length: {len(jobs)}")
# sys.exit(1)
# g = groupby(jobs, key=Job.rule)
# self.logger.debug(f"Jobs grouped by rule: {g}")
# sys.exit(1)
for job in jobs:
if job.name == "foo":
break
self.run_job_pre(job)
self.run_job(job)

def run_job(self, job: JobExecutorInterface):
# Implement here how to run a job.
# You can access the job's resources, etc.
Expand Down Expand Up @@ -140,9 +166,9 @@ def run_job(self, job: JobExecutorInterface):
# we use a run_uuid as the job-name, to allow `--name`-based
# filtering in the job status checks (`sacct --name` and `squeue --name`)
if wildcard_str == "":
comment_str = f"rule_{job.name}"
comment_str = f"{group_or_rule}"
else:
comment_str = f"rule_{job.name}_wildcards_{wildcard_str}"
comment_str = f"{group_or_rule}_wildcards_{wildcard_str}"
call = (
f"sbatch "
f"--parsable "
Expand Down Expand Up @@ -475,7 +501,8 @@ async def job_stati(self, command):
}
except subprocess.CalledProcessError as e:
self.logger.error(
f"The job status query failed with command: {command}\n"
"The job status query failed with"
f" command: {command}\n"
f"Error message: {e.stderr.strip()}\n"
)
pass
Expand Down
18 changes: 18 additions & 0 deletions snakemake_executor_plugin_slurm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,21 @@ def delete_slurm_environment():
for var in os.environ:
if var.startswith("SLURM_"):
del os.environ[var]


def clean_old_logs(logdir, age_cutoff):
"""
Function to delete files older than 'age_cutoff'
in the SLURM 'logdir'
"""
cutoff_secs = age_cutoff * 86400
for root, _, files in os.walk(logdir, topdown=False):
for fname in files:
file_path = os.path.join(root, fname)
if age_cutoff > 0:
filestamp = os.stat(file_path).st_mtime
if filestamp > cutoff_secs:
os.remove(file_path)
# remove empty rule top dir, if empty
if len(os.listdir(root)) == 0:
os.rmdir(root)
Loading