Adding notifications for slurm job status
This guide will expand upon how to write a template file to incorporate ntfy.sh . notifications!
ntfy (pronounced notify) is a simple HTTP-based pub-sub notification service. It allows you to send notifications to your phone or desktop via scripts from any computer, and/or using a REST API. Itโs infinitely flexible, and 100% free software.
Prerequisites
- Familiarity with
submit_slurm_job
- Familiarity with simple template files
ntfy.sh alerts
We can start by adding a notification when the job starts and when it ends. Looking at the ntfy.sh website we can see:
Publishing messages can be done via PUT or POST. Topics are created on the fly by subscribing or publishing to them. If you use ntfy without sign-up, the topic is essentially a password, so pick something thatโs not easily guessable. If you purchase ntfy Pro, you can reserve topic names instead.
With the command to do this is:
curl -d "Backup successful ๐" ntfy.sh/mytopic
Updating template file
We can add this command to our template file to fire off before the nonmem job starts and immediately after it finishes.
#!/bin/bash#SBATCH --job-name="{{job_name}}"#SBATCH --nodes=1#SBATCH --ntasks=1#SBATCH --cpus-per-task={{ncpu}}#SBATCH --partition={{partition}}#SBATCH --account={{project_name}}
#{{project_path}}# submit_slurm_job uses the whisker package to populate template files# https://github.com/edwindj/whisker
{{#ntfy}}curl -d "NONMEM job {{job_name}} is starting" ntfy.sh/{{mytopic}}{{/ntfy}}
{{#parallel}}{{bbi_exe_path}} nonmem run local {{model_path}}.mod --parallel --threads={{ncpu}} --config {{bbi_config_path}}{{/parallel}}
{{^parallel}}{{bbi_exe_path}} nonmem run local {{model_path}}.mod --config {{bbi_config_path}}{{/parallel}}
{{#ntfy}}curl -d "NONMEM job {{job_name}} has finished" ntfy.sh/{{mytopic}}{{/ntfy}}
We can provide the needed arguments (mytopic
and ntfy
) through the slurm_template_opts
argument using the following call to submit_slurm_job
library(slurmtools)library(bbr)
nonmem_path <- file.path("path", "to", "nonmem", "models")
mod <- bbr::read_model(file.path(nonmem_path "1001"))submit_slurm_job( mod, bbi_config_path = file.path(nonmem_path, "new-bbi.yml"), slurm_template_opts = list( ntfy = TRUE, mytopic = 'slurmtools_example_ntfy' ))
Job status alerts
This sends off two messages to ntfy.sh :