Skip to content

Commit b56837e

Browse files
authored
feat: cli (#111)
addresses #73
1 parent af92fd0 commit b56837e

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

docs/further.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Usually, it is advisable to persist such settings via a
3131
[configuration profile](https://snakemake.readthedocs.io/en/latest/executing/cli.html#profiles), which
3232
can be provided system-wide, per user, and in addition per workflow.
3333

34+
The executor waits per default 40 seconds for its first check of the job status. Using `--slurm-init-seconds-before-status-checks=<time in seconds>` this behaviour can be altered.
35+
3436
## Ordinary SMP jobs
3537

3638
Most jobs will be carried out by programs that are either single-core

snakemake_executor_plugin_slurm/__init__.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,38 @@
99
import re
1010
import subprocess
1111
import time
12+
from dataclasses import dataclass, field
1213
from datetime import datetime, timedelta
13-
from typing import List, Generator
14+
from typing import List, Generator, Optional
1415
import uuid
1516
from snakemake_interface_executor_plugins.executors.base import SubmittedJobInfo
1617
from snakemake_interface_executor_plugins.executors.remote import RemoteExecutor
17-
from snakemake_interface_executor_plugins.settings import CommonSettings
18+
from snakemake_interface_executor_plugins.settings import (
19+
ExecutorSettingsBase,
20+
CommonSettings,
21+
)
1822
from snakemake_interface_executor_plugins.jobs import (
1923
JobExecutorInterface,
2024
)
2125
from snakemake_interface_common.exceptions import WorkflowError
2226
from snakemake_executor_plugin_slurm_jobstep import get_cpus_per_task
2327

2428

29+
@dataclass
30+
class ExecutorSettings(ExecutorSettingsBase):
31+
init_seconds_before_status_checks: Optional[int] = field(
32+
default=40,
33+
metadata={
34+
"help": """
35+
Defines the time in seconds before the first status
36+
check is performed after job submission.
37+
""",
38+
"env_var": False,
39+
"required": False,
40+
},
41+
)
42+
43+
2544
# Required:
2645
# Specify common settings shared by various executors.
2746
common_settings = CommonSettings(
@@ -56,14 +75,16 @@ def __post_init__(self):
5675
self.logger.info(f"SLURM run ID: {self.run_uuid}")
5776
self._fallback_account_arg = None
5877
self._fallback_partition = None
78+
# providing a short-hand, even if subsequent calls seem redundant
79+
self.settings: ExecutorSettings = self.workflow.executor_settings
5980

6081
def warn_on_jobcontext(self, done=None):
6182
if not done:
6283
if "SLURM_JOB_ID" in os.environ:
6384
self.logger.warning(
64-
"Running Snakemake in a SLURM within a job may lead"
65-
" to unexpected behavior. Please run Snakemake directly"
66-
" on the head node."
85+
"You are running snakemake in a SLURM job context. "
86+
"This is not recommended, as it may lead to unexpected behavior."
87+
"Please run Snakemake directly on the login node."
6788
)
6889
time.sleep(5)
6990
done = True
@@ -140,7 +161,7 @@ def run_job(self, job: JobExecutorInterface):
140161
if job.resources.get("nodes", False):
141162
call += f" --nodes={job.resources.get('nodes', 1)}"
142163

143-
# fixes #40 - set ntasks regarlless of mpi, because
164+
# fixes #40 - set ntasks regardless of mpi, because
144165
# SLURM v22.05 will require it for all jobs
145166
call += f" --ntasks={job.resources.get('tasks', 1)}"
146167
# MPI job
@@ -195,7 +216,6 @@ async def check_active_jobs(
195216
self, active_jobs: List[SubmittedJobInfo]
196217
) -> Generator[SubmittedJobInfo, None, None]:
197218
# Check the status of active jobs.
198-
199219
# You have to iterate over the given list active_jobs.
200220
# For jobs that have finished successfully, you have to call
201221
# self.report_job_success(job).
@@ -509,10 +529,10 @@ def check_slurm_extra(self, job):
509529
jobname = re.compile(r"--job-name[=?|\s+]|-J\s?")
510530
if re.search(jobname, job.resources.slurm_extra):
511531
raise WorkflowError(
512-
"The '--job-name' option is not allowed in the 'slurm_extra' "
532+
"The --job-name option is not allowed in the 'slurm_extra' "
513533
"parameter. The job name is set by snakemake and must not be "
514-
"overwritten. It is internally used to check the stati of all "
515-
"submitted jobs by this workflow."
534+
"overwritten. It is internally used to check the stati of the "
535+
"all submitted jobs by this workflow."
516536
"Please consult the documentation if you are unsure how to "
517537
"query the status of your jobs."
518538
)

0 commit comments

Comments
 (0)