#notification #process #status #running #long #email-notifier

email-notif

Email notification for status of long running processes

2 stable releases

1.0.1 Jan 3, 2023

#186 in Email

MIT license

9KB
119 lines

email-notif-rs

Email notification of process status. For long-running processes (e.g. training a ML model or running a simulation) it can be useful to be sent a notification on completion. Email is a handy way to recieve this.

This is a rust implementation of my python script email_notifier.

Installation

This package is on cargo. Add the dependency to your projects as:

[dependency]
email-notif-rs = "1.0.0"

Usage

You need to tell the library where emails should be sent from. I don't want to put email config in programs, so it's in a config file in your home dir. The sending email should be one you don't mind having a password in plain text in a json file. (i.e. one that was set up for the purposes of sending notifications.)

{
  "smtp_server": "smtp.example.com",
  "sender_email": "notifications@bar.com",
  "password": "notVerySecureAtAll",
  "recipient_email": "foo@bar.com",
  "port": 587
}

With the config set, you can now use the library from a program as follows:

use email_notif::EmailNotifier;
use crate::foo::long_running_process;

fn main() {
  EmailNotifier::new("Simulation Run")
    .capture(
      |em| {
        for i in 0..10 {
          long_running_process();
          em.send_update(format!("iteration {i} complete"));
        }
      }
    );
}

The above will send an update notification every time an iteration is complete, and an email when the process completes successfully. In addition, an email will be sent if the process results in panic. (Only an unwind panic, however.)

Dependencies

~3–14MB
~193K SLoC