Skip to content

Commit

Permalink
fix: handle job array cancellation for arrays that have never started…
Browse files Browse the repository at this point in the history
… (issue #141)
  • Loading branch information
neilmunday committed Sep 1, 2024
1 parent e4c7b66 commit 3311467
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/slurmmail/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,15 @@ def __process_spool_file(
for i in range(field_num):
sacct_dict[fields[i]] = data[i]

if not re.match(r"^([0-9]+|[0-9]+_[0-9]+|[0-9]+\+[0-9]+)$", sacct_dict["JobId"]):
# possible job ID formats:
# [0-9]+
# [0-9]+_[0-9]+ --> job array
# [0-9]+_\[[0-9]+-[0-9]+\] --> job array, not started
# [0-9]+\+[0-9]+ --> HET job
if not re.match(
r"^([0-9]+|[0-9]+_[0-9]+|[0-9]+_\[[0-9]+-[0-9]+\]|[0-9]+\+[0-9]+)$",
sacct_dict["JobId"]
):
logging.debug("job ID %s failed reg ex match", sacct_dict["JobId"])
# grab MaxRSS value
if (
Expand Down Expand Up @@ -356,7 +364,7 @@ def __process_spool_file(
job.save()
jobs.append(job)

if array_summary or len(jobs) == 1:
if (array_summary and len(jobs) > 0) or len(jobs) == 1:
jobs = [jobs[0]]

if not array_summary and 0 < options.array_max_notifications < len(jobs):
Expand Down
13 changes: 10 additions & 3 deletions src/slurmmail/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Job:
"""

GECOS_NAME_FIELD: int = 0
JOB_ARRAY_NOT_STARTED_RE = re.compile(r"([0-9]+)_\[[0-9]+-[0-9]+\]")

def __init__(
self, datetime_format: str,
Expand Down Expand Up @@ -114,9 +115,15 @@ def __init__(
self.workdir: Optional[str] = None

if "_" in job_id:
array_id, index = job_id.split("_")
self.array_id = int(array_id)
self.index = int(index)

# has the job array started?
match = Job.JOB_ARRAY_NOT_STARTED_RE.match(job_id)
if match:
self.array_id = match.group(1)
else:
array_id, index = job_id.split("_")
self.array_id = int(array_id)
self.index = int(index)
elif "+" in job_id:
hetjob_id, index = job_id.split("+")
self.hetjob_id = int(hetjob_id)
Expand Down

0 comments on commit 3311467

Please sign in to comment.