Skip to content

Commit

Permalink
fix: Use sacct syntax that is compatible with slurm < 20.11.0 (#26)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dnerini and cmeesters committed Feb 14, 2024
1 parent 5dfd514 commit c1591ff
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion snakemake_executor_plugin_slurm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import subprocess
import time
from datetime import datetime, timedelta
from typing import List, Generator
import uuid
from snakemake_interface_executor_plugins.executors.base import SubmittedJobInfo
Expand Down Expand Up @@ -199,14 +200,23 @@ async def check_active_jobs(
active_jobs_ids = {job_info.external_jobid for job_info in active_jobs}
active_jobs_seen_by_sacct = set()

# We use this sacct syntax for argument 'starttime' to keep it compatible
# with slurm < 20.11
sacct_starttime = f"{datetime.now() - timedelta(days=2):%Y-%m-%dT%H:00}"
# previously we had
# f"--starttime now-2days --endtime now --name {self.run_uuid}"
# in line 218 - once v20.11 is definitively not in use any more,
# the more readable version ought to be re-adapted

# this code is inspired by the snakemake profile:
# https://github.com/Snakemake-Profiles/slurm
for i in range(status_attempts):
async with self.status_rate_limiter:
(status_of_jobs, sacct_query_duration) = await self.job_stati(
# -X: only show main job, no substeps
f"sacct -X --parsable2 --noheader --format=JobIdRaw,State "
f"--starttime now-2days --endtime now --name {self.run_uuid}"
f"--starttime {sacct_starttime} "
f"--endtime now --name {self.run_uuid}"
)
if status_of_jobs is None and sacct_query_duration is None:
self.logger.debug(f"could not check status of job {self.run_uuid}")
Expand Down

0 comments on commit c1591ff

Please sign in to comment.