|
9 | 9 | import re |
10 | 10 | import subprocess |
11 | 11 | import time |
| 12 | +from dataclasses import dataclass, field |
12 | 13 | from datetime import datetime, timedelta |
13 | | -from typing import List, Generator |
| 14 | +from typing import List, Generator, Optional |
14 | 15 | import uuid |
15 | 16 | from snakemake_interface_executor_plugins.executors.base import SubmittedJobInfo |
16 | 17 | 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 | +) |
18 | 22 | from snakemake_interface_executor_plugins.jobs import ( |
19 | 23 | JobExecutorInterface, |
20 | 24 | ) |
21 | 25 | from snakemake_interface_common.exceptions import WorkflowError |
22 | 26 | from snakemake_executor_plugin_slurm_jobstep import get_cpus_per_task |
23 | 27 |
|
24 | 28 |
|
| 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 | + |
25 | 44 | # Required: |
26 | 45 | # Specify common settings shared by various executors. |
27 | 46 | common_settings = CommonSettings( |
@@ -56,14 +75,16 @@ def __post_init__(self): |
56 | 75 | self.logger.info(f"SLURM run ID: {self.run_uuid}") |
57 | 76 | self._fallback_account_arg = None |
58 | 77 | self._fallback_partition = None |
| 78 | + # providing a short-hand, even if subsequent calls seem redundant |
| 79 | + self.settings: ExecutorSettings = self.workflow.executor_settings |
59 | 80 |
|
60 | 81 | def warn_on_jobcontext(self, done=None): |
61 | 82 | if not done: |
62 | 83 | if "SLURM_JOB_ID" in os.environ: |
63 | 84 | 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." |
67 | 88 | ) |
68 | 89 | time.sleep(5) |
69 | 90 | done = True |
@@ -140,7 +161,7 @@ def run_job(self, job: JobExecutorInterface): |
140 | 161 | if job.resources.get("nodes", False): |
141 | 162 | call += f" --nodes={job.resources.get('nodes', 1)}" |
142 | 163 |
|
143 | | - # fixes #40 - set ntasks regarlless of mpi, because |
| 164 | + # fixes #40 - set ntasks regardless of mpi, because |
144 | 165 | # SLURM v22.05 will require it for all jobs |
145 | 166 | call += f" --ntasks={job.resources.get('tasks', 1)}" |
146 | 167 | # MPI job |
@@ -195,7 +216,6 @@ async def check_active_jobs( |
195 | 216 | self, active_jobs: List[SubmittedJobInfo] |
196 | 217 | ) -> Generator[SubmittedJobInfo, None, None]: |
197 | 218 | # Check the status of active jobs. |
198 | | - |
199 | 219 | # You have to iterate over the given list active_jobs. |
200 | 220 | # For jobs that have finished successfully, you have to call |
201 | 221 | # self.report_job_success(job). |
@@ -509,10 +529,10 @@ def check_slurm_extra(self, job): |
509 | 529 | jobname = re.compile(r"--job-name[=?|\s+]|-J\s?") |
510 | 530 | if re.search(jobname, job.resources.slurm_extra): |
511 | 531 | 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' " |
513 | 533 | "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." |
516 | 536 | "Please consult the documentation if you are unsure how to " |
517 | 537 | "query the status of your jobs." |
518 | 538 | ) |
0 commit comments