Skip to content

Commit 8929570

Browse files
authored
Merge pull request #33 from NCAR/hua-work-common
use /usr/sbin/sendmail on capsers
2 parents 995c470 + 6cf8749 commit 8929570

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "rda_python_common"
7-
version = "1.0.27"
7+
version = "1.0.28"
88
authors = [
99
{ name="Zaihua Ji", email="zji@ucar.edu" },
1010
]

src/rda_python_common/PgDBI.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,9 +1845,9 @@ def get_specialist(dsid, logact = PGDBI['ERRLOG']):
18451845
#
18461846
def build_customized_email(table, field, condition, subject, logact = 0):
18471847

1848+
estat = PgLOG.FAILURE
18481849
msg = PgLOG.get_email()
1849-
1850-
if not msg: return PgLOG.FAILURE
1850+
if not msg: return estat
18511851

18521852
sender = PgLOG.PGLOG['CURUID'] + "@ucar.edu"
18531853
receiver = PgLOG.PGLOG['EMLADDR'] if PgLOG.PGLOG['EMLADDR'] else (PgLOG.PGLOG['CURUID'] + "@ucar.edu")
@@ -1857,9 +1857,12 @@ def build_customized_email(table, field, condition, subject, logact = 0):
18571857
if not subject: subject = "Message from {}-{}".format(PgLOG.PGLOG['HOSTNAME'], PgLOG.get_command())
18581858
ebuf += "Subject: {}!\n\n{}\n".format(subject, msg)
18591859

1860-
estat = cache_customized_email(table, field, condition, ebuf, logact)
1861-
if estat and logact:
1862-
PgLOG.pglog("Email {} cached to '{}.{}' for {}, Subject: {}".format(receiver, table, field, condition, subject), logact)
1860+
if PgLOG.PGLOG['EMLSEND']:
1861+
estat = PgLOG.send_customized_email(f"{table}.{condition}", ebuf, logact)
1862+
if estat != PgLOG.SUCCESS:
1863+
estat = cache_customized_email(table, field, condition, ebuf, 0)
1864+
if estat and logact:
1865+
PgLOG.pglog("Email {} cached to '{}.{}' for {}, Subject: {}".format(receiver, table, field, condition, subject), logact)
18631866

18641867
return estat
18651868

@@ -1924,7 +1927,7 @@ def cache_customized_email(table, field, condition, emlmsg, logact = 0):
19241927
return PgLOG.SUCCESS
19251928
else:
19261929
msg = "cache email to '{}.{}' for {}".format(table, field, condition)
1927-
PgLOG.pglog("Error msg, try to send directly now", logact|PgLOG.ERRLOG)
1930+
PgLOG.pglog(f"Error {msg}, try to send directly now", logact|PgLOG.ERRLOG)
19281931
return PgLOG.send_customized_email(msg, emlmsg, logact)
19291932

19301933
#

src/rda_python_common/PgLOG.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
'PBSTIME' : 86400, # max runtime for SLURM bath job, (7x24x60x60 seconds)
120120
'MSSGRP' : None, # set if set to different HPSS group
121121
'RDAGRP' : "decs",
122+
'EMLSEND' : None, # path to sendmail, None if not exists
122123
'DSCHECK' : None, # carry some cached dscheck information
123124
'PGDBBUF' : None, # reference to a connected database object
124125
'HPSSLMT' : 10, # up limit of HPSS streams
@@ -1289,7 +1290,8 @@ def set_common_pglog():
12891290
SETPGLOG("LOGFILE", "pgdss.log") # log file name
12901291
SETPGLOG("EMLFILE", "pgemail.log") # email log file name
12911292
SETPGLOG("ERRFILE", '') # error file name
1292-
SETPGLOG("EMLSEND", "/usr/lib/sendmail -t") # send email command
1293+
sm = "/usr/sbin/sendmail"
1294+
if valid_command(sm): SETPGLOG("EMLSEND", f"{sm} -t") # send email command
12931295
SETPGLOG("DBGLEVEL", '') # debug level
12941296
SETPGLOG("DBGPATH", PGLOG['DSSDBHM']+"/log") # path to debug log file
12951297
SETPGLOG("OBJCTBKT", "rda-data") # default Bucket on Object Store

src/rda_python_common/PgOPT.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,25 +1684,35 @@ def send_request_email_notice(pgrqst, errmsg, fcount, rstat, readyfile = None, p
16841684
for ekey in einfo:
16851685
ebuf = re.sub(r'<{}>'.format(ekey), einfo[ekey], ebuf)
16861686

1687+
16871688
if PgLOG.PGLOG['DSCHECK'] and not pgpart:
16881689
tbl = "dscheck"
16891690
cnd = "cindex = {}".format(PgLOG.PGLOG['DSCHECK']['cindex'])
16901691
else:
16911692
tbl = "dsrqst"
16921693
cnd = "rindex = {}".format(pgrqst['rindex'])
16931694

1694-
if not PgDBI.cache_customized_email(tbl, "einfo", cnd, ebuf, 0): return 'E'
1695-
if errmsg:
1696-
PgLOG.pglog("Error Email {} cached to {}.einfo for {}:\n{}".format(einfo['SENDER'], tbl, cnd, errmsg),
1697-
PGOPT['errlog'])
1695+
if PgLOG.PGLOG['EMLSEND'] and PgLOG.send_customized_email(f"{tbl}.{cnd}", ebuf, 0):
1696+
if errmsg:
1697+
PgLOG.pglog("Error Email sent to {} for {}.{}:\n{}".format(einfo['SENDER'], tbl, cnd, errmsg), PGOPT['errlog'])
1698+
readyfile = None
1699+
else:
1700+
PgLOG.pglog("{}Email sent to {} for {}.{}\nSubset: {}".format(("Customized " if pgrqst['enotice'] else ""), einfo['RECEIVER'], tbl, cnd, einfo['SUBJECT']),
1701+
PGOPT['wrnlog']|PgLOG.FRCLOG)
16981702
else:
1699-
PgLOG.pglog("{}Email {} cached to {}.einfo for {}\nSubset: {}".format(("Customized " if pgrqst['enotice'] else ""), einfo['RECEIVER'], tbl, cnd, einfo['SUBJECT']),
1700-
PGOPT['wrnlog']|PgLOG.FRCLOG)
1701-
if readyfile:
1702-
rf = open(readyfile, 'w')
1703-
rf.write(ebuf)
1704-
rf.close()
1705-
PgFile.set_local_mode(readyfile, 1, PgLOG.PGLOG['FILEMODE'])
1703+
if not PgDBI.cache_customized_email(tbl, "einfo", cnd, ebuf, 0): return 'E'
1704+
if errmsg:
1705+
PgLOG.pglog("Error Email {} cached to {}.einfo for {}:\n{}".format(einfo['SENDER'], tbl, cnd, errmsg), PGOPT['errlog'])
1706+
readyfile = None
1707+
else:
1708+
PgLOG.pglog("{}Email {} cached to {}.einfo for {}\nSubset: {}".format(("Customized " if pgrqst['enotice'] else ""), einfo['RECEIVER'], tbl, cnd, einfo['SUBJECT']),
1709+
PGOPT['wrnlog']|PgLOG.FRCLOG)
1710+
1711+
if readyfile:
1712+
rf = open(readyfile, 'w')
1713+
rf.write(ebuf)
1714+
rf.close()
1715+
PgFile.set_local_mode(readyfile, 1, PgLOG.PGLOG['FILEMODE'])
17061716

17071717
return rstat
17081718

0 commit comments

Comments
 (0)