Skip to content

Commit

Permalink
Added support for STAGE_OUT mail type for issue #36
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Munday committed May 9, 2022
1 parent e4b4141 commit 7797931
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Date: 2022-05-09
* Changed spool mail file to use JSON format.
* Moved templates into conf.d/templates.
* Created e-mail signature template.
* Added support for REQUEUE, INVALID_DEPEND, TIME_LIMIT_50, TIME_LIMIT_80, TIME_LIMIT_90, and TIME_LIMIT mail types (issue #36).
* Added support for REQUEUE, INVALID_DEPEND, STAGE_OUT, TIME_LIMIT_50, TIME_LIMIT_80, TIME_LIMIT_90, and TIME_LIMIT mail types (issue #36).

Version 2.5
-----------
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Slurm-Mail uses Python's [string.Template](https://docs.python.org/3/library/str
| invalid-dependency | Used when a job has an invalid dependency. |
| job_table.tpl | Used to create the job info table in e-mails. |
| signature.tpl | Used to create the e-mail signature. |
| staged-out.tpl | Used when a job's burst buffer stage has completed. |
| started.tpl | Used for jobs that have started. |
| started-array-summary.tpl | Used when the first job in an array has started. |
| started-array.tpl | Used for the first job in an array that has started. |
Expand Down
20 changes: 14 additions & 6 deletions bin/slurm-send-mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def process_spool_file(json_file: pathlib.Path):
"Failed",
"Invalid dependency",
"Requeued",
"Staged Out",
"Time reached 50%",
"Time reached 80%",
"Time reached 90%",
Expand Down Expand Up @@ -529,12 +530,6 @@ def process_spool_file(json_file: pathlib.Path):
USER=pwd.getpwnam(job.user).pw_gecos, JOB_TABLE=job_table,
CLUSTER=job.cluster
)
elif state == "Invalid dependency":
tpl = Template(get_file_contents(templates['invalid_dependency']))
body = tpl.substitute(
CSS=css, CLUSTER=job.cluster, JOB_ID=job.id, SIGNATURE=signature,
USER=pwd.getpwnam(job.user).pw_gecos, JOB_TABLE=job_table,
)
elif state in ["Ended", "Failed", "Requeued", "Time limit reached"]:
end_txt = state.lower()
job_output = ""
Expand Down Expand Up @@ -596,6 +591,18 @@ def process_spool_file(json_file: pathlib.Path):
)
# change state value for upcomming e-mail send
state = "{0}% of time limit reached".format(reached)
elif state == "Invalid dependency":
tpl = Template(get_file_contents(templates['invalid_dependency']))
body = tpl.substitute(
CSS=css, CLUSTER=job.cluster, JOB_ID=job.id, SIGNATURE=signature,
USER=pwd.getpwnam(job.user).pw_gecos, JOB_TABLE=job_table,
)
elif state == "Staged Out":
tpl = Template(get_file_contents(templates['staged_out']))
body = tpl.substitute(
CSS=css, CLUSTER=job.cluster, JOB_ID=job.id, SIGNATURE=signature,
USER=pwd.getpwnam(job.user).pw_gecos, JOB_TABLE=job_table,
)

msg = MIMEMultipart("alternative")
msg['subject'] = Template(email_subject).substitute(
Expand Down Expand Up @@ -695,6 +702,7 @@ def tail_file(f: str, num_lines: int) -> str:
templates['job_output'] = tpl_dir / "job-output.tpl"
templates['job_table'] = tpl_dir / "job-table.tpl"
templates['signature'] = tpl_dir / "signature.tpl"
templates['staged_out'] = tpl_dir / "staged-out.tpl"
templates['started'] = tpl_dir / "started.tpl"
templates['time'] = tpl_dir / "time.tpl"

Expand Down
4 changes: 2 additions & 2 deletions bin/slurm-spool-mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ def die(msg: str):
match = None
if "Array" in info:
match = re.search(
r"Slurm ((?P<array_summary>Array Summary)|Array Task) Job_id=[0-9]+_([0-9]+|\*) \((?P<job_id>[0-9]+)\).*?(?P<state>(Began|Ended|Failed|Requeued|Invalid dependency|Reached time limit|Reached (?P<limit>[0-9]+)% of time limit))",
r"Slurm ((?P<array_summary>Array Summary)|Array Task) Job_id=[0-9]+_([0-9]+|\*) \((?P<job_id>[0-9]+)\).*?(?P<state>(Began|Ended|Failed|Requeued|Invalid dependency|Reached time limit|Reached (?P<limit>[0-9]+)% of time limit|Staged Out))",
info
)
if not match:
die("Failed to parse Slurm info.")
array_summary = (match.group("array_summary") is not None)
else:
match = re.search(
r"Slurm Job_id=(?P<job_id>[0-9]+).*?(?P<state>(Began|Ended|Failed|Requeued|Invalid dependency|Reached time limit|Reached (?P<limit>[0-9]+)% of time limit))",
r"Slurm Job_id=(?P<job_id>[0-9]+).*?(?P<state>(Began|Ended|Failed|Requeued|Invalid dependency|Reached time limit|Reached (?P<limit>[0-9]+)% of time limit|Staged Out))",
info
)
if not match:
Expand Down
24 changes: 24 additions & 0 deletions conf.d/templates/staged-out.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<html>
<head>
<style>
$CSS
tr.jobEnd {
display: none;
}
</style>
</head>
<body>

<p>Dear $USER,</p>

<p>Your job $JOB_ID on $CLUSTER has completed its burst buffer stage out.</p>

<p>Details about the job can be found in the table below:</p>

$JOB_TABLE

$SIGNATURE

</body>
</html>

0 comments on commit 7797931

Please sign in to comment.