Skip to content

Commit 24b11ae

Browse files
author
Daniel Dale
committed
created systemd service and email notification helper utility for dc infsvc. changed about to index page.
1 parent 9bd4762 commit 24b11ae

File tree

10 files changed

+63
-28
lines changed

10 files changed

+63
-28
lines changed

dataprep/dataprep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def write_del_topk_sim_tups(self, falsehood_id_tups: List, cand_table_name: str,
216216

217217
def filter_truths(self) -> None:
218218
"""
219-
see diagrams at https://deepclassiflie.org/about.html#data-pipeline
219+
see diagrams at https://deepclassiflie.org/index.html#data-pipeline
220220
"""
221221
base_model_modes = [True, False]
222222
if not self.config.experiment.inference_ckpt:

deep_classiflie_infsvc.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12
source ${HOME}/.bashrc
23
cd `dirname "$(readlink -f "$0")"`
34
curr_branch=`git branch | grep '* ' | awk '{print $2}'`
@@ -23,4 +24,10 @@ then
2324
d=`date +%Y%m%d%H%M%S`
2425
mv $prev_log ${prev_log}_${d}.bkp
2526
fi
26-
nohup /opt/anaconda/envs/${target_env}/bin/python ${DC_BASE}/deep_classiflie.py --config "${DC_BASE}/configs/infsvc.yaml" 1>"${HOME}/${bot_log_name}.out" 2>&1 &
27+
svc_mode=$2
28+
if [ $svc_mode == "svc" ]
29+
then
30+
/opt/anaconda/envs/${target_env}/bin/python ${DC_BASE}/deep_classiflie.py --config "${DC_BASE}/configs/infsvc.yaml" 1>"${HOME}/${bot_log_name}.out" 2>&1
31+
else
32+
nohup /opt/anaconda/envs/${target_env}/bin/python ${DC_BASE}/deep_classiflie.py --config "${DC_BASE}/configs/infsvc.yaml" 1>"${HOME}/${bot_log_name}.out" 2>&1 &
33+
fi

docs/_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ kramdown:
99
theme: jekyll-theme-cayman
1010
google_analytics: UA-26562413-2
1111
show_downloads: false
12-
about_url: about.html
12+
about_url: index.html
1313
pred_explorer_url: pred_explorer.html
1414
perf_explorer_url: perf_explorer.html
1515
current_explorer_url: current_explorer.html

docs/_layouts/redirect.html

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/assets/js/current_pred_nav.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function loadJSON(latest_recs) {
6060
await $("#progress_bar").toggle(); // disable progress bar for firefox the moment, behavior differs from chrome but this should be handled without user-agent detection in the future
6161
}
6262
try {
63-
console.log("Waiting for initial gateway response.");
63+
console.log("Waiting for initial gateway response");
6464
$("#connect_step").html("<br/>Waiting for primary gateway response");
6565
response = await fetch(latest_recs[0]);
6666
await $("#connect_step").toggle();

docs/current_explorer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
---
77
<div class="outer_container">
88
<div class="dt_instructions">Latest Deep Classiflie Predictions<sup id="a0" class="small"><a href="#f0">[0]</a></sup></div>
9-
<div class="loading_msg">Loading latest predictions from IPFS.<span id="connect_step"></span><span class="loading"></span><sup id="a2" class="small"><a href="#f0">[2]</a></sup></div>
9+
<div class="loading_msg">Loading latest predictions from IPFS<span id="connect_step"></span><span class="loading"></span><sup id="a2" class="small"><a href="#f0">[2]</a></sup></div>
1010
<div id="progress_bar" class="label-center"> </div>
1111
<div class="cur-preds-filter-grid-container">
1212
<div class="local-acc-name">Local Accuracy:</div>

docs/index.html

Lines changed: 0 additions & 4 deletions
This file was deleted.
File renamed without changes.

utils/.dc_notify.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MAIL_USER="fake.user"
2+
MAIL_APP_PASS="fakepassword"

utils/notification.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import smtplib
2+
import os
3+
from email.message import EmailMessage
4+
import traceback
5+
import sys
6+
from argparse import ArgumentParser
7+
8+
9+
def send_gmail_notification(email_content: str, mail_subject: str, to_addr: str) -> None:
10+
# collect mail params
11+
mail_dict = {}
12+
for mail_key in ['MAIL_USER', 'MAIL_APP_PASS']:
13+
if mail_key in os.environ.keys():
14+
mail_dict[mail_key] = os.environ[mail_key]
15+
else:
16+
raise ValueError(f"Missing environmental parameter {mail_key} required for authentication. Exiting")
17+
try:
18+
with open(email_content) as fp:
19+
msg = EmailMessage()
20+
msg.set_content(fp.read())
21+
msg['Subject'] = mail_subject
22+
msg['From'] = f"{mail_dict['MAIL_USER']}@gmail.com"
23+
msg['To'] = to_addr if to_addr else f"{mail_dict['MAIL_USER']}@gmail.com"
24+
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
25+
server.ehlo()
26+
server.login(mail_dict['MAIL_USER'], mail_dict['MAIL_APP_PASS'])
27+
server.sendmail(msg['From'], msg['To'], msg.as_string())
28+
server.close()
29+
print('notification email sent')
30+
except Exception as e: # a lot could go wrong here. for now, shamefully using a broad except/logging traceback
31+
exc_type, exc_value, exc_traceback = sys.exc_info()
32+
print(f"error sending notification email: "
33+
f"{repr(traceback.format_exception(exc_type, exc_value, exc_traceback))}")
34+
raise e
35+
36+
37+
def main():
38+
parser = ArgumentParser(description="""\
39+
Sends a gmail email using a from email and password specified via env variables MAIL_USER and MAIL_APP_PASS respectively
40+
""")
41+
parser.add_argument('-f', '--file', required=True, dest='email_content', help="""file to send in the email""")
42+
parser.add_argument('-s', '--subject', dest='mail_subject', default="Service Failure", help='The email subject')
43+
parser.add_argument('-t', '--to', required=False, dest='to_addr', default=None, help='recipient of email')
44+
args = parser.parse_args()
45+
send_gmail_notification(args.email_content, args.mail_subject, args.to_addr)
46+
47+
48+
if __name__ == '__main__':
49+
main()

0 commit comments

Comments
 (0)