Skip to content

Commit c1591ff

Browse files
dnerinicmeesters
andauthored
fix: Use sacct syntax that is compatible with slurm < 20.11.0 (#26)
Closes #25 Tested with slurm 20.02.07 Not a great contribution in terms of code readability, but it'd ensure that the plugin works with older slurm versions. --------- Co-authored-by: Christian Meesters <cmeesters@users.noreply.github.com>
1 parent 5dfd514 commit c1591ff

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

snakemake_executor_plugin_slurm/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import subprocess
1010
import time
11+
from datetime import datetime, timedelta
1112
from typing import List, Generator
1213
import uuid
1314
from snakemake_interface_executor_plugins.executors.base import SubmittedJobInfo
@@ -199,14 +200,23 @@ async def check_active_jobs(
199200
active_jobs_ids = {job_info.external_jobid for job_info in active_jobs}
200201
active_jobs_seen_by_sacct = set()
201202

203+
# We use this sacct syntax for argument 'starttime' to keep it compatible
204+
# with slurm < 20.11
205+
sacct_starttime = f"{datetime.now() - timedelta(days=2):%Y-%m-%dT%H:00}"
206+
# previously we had
207+
# f"--starttime now-2days --endtime now --name {self.run_uuid}"
208+
# in line 218 - once v20.11 is definitively not in use any more,
209+
# the more readable version ought to be re-adapted
210+
202211
# this code is inspired by the snakemake profile:
203212
# https://github.com/Snakemake-Profiles/slurm
204213
for i in range(status_attempts):
205214
async with self.status_rate_limiter:
206215
(status_of_jobs, sacct_query_duration) = await self.job_stati(
207216
# -X: only show main job, no substeps
208217
f"sacct -X --parsable2 --noheader --format=JobIdRaw,State "
209-
f"--starttime now-2days --endtime now --name {self.run_uuid}"
218+
f"--starttime {sacct_starttime} "
219+
f"--endtime now --name {self.run_uuid}"
210220
)
211221
if status_of_jobs is None and sacct_query_duration is None:
212222
self.logger.debug(f"could not check status of job {self.run_uuid}")

0 commit comments

Comments
 (0)