Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "rda_python_common"
version = "1.0.27"
version = "1.0.28"
authors = [
{ name="Zaihua Ji", email="zji@ucar.edu" },
]
Expand Down
15 changes: 9 additions & 6 deletions src/rda_python_common/PgDBI.py
Original file line number Diff line number Diff line change
Expand Up @@ -1845,9 +1845,9 @@ def get_specialist(dsid, logact = PGDBI['ERRLOG']):
#
def build_customized_email(table, field, condition, subject, logact = 0):

estat = PgLOG.FAILURE
msg = PgLOG.get_email()

if not msg: return PgLOG.FAILURE
if not msg: return estat

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

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

return estat

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

#
Expand Down
4 changes: 3 additions & 1 deletion src/rda_python_common/PgLOG.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
'PBSTIME' : 86400, # max runtime for SLURM bath job, (7x24x60x60 seconds)
'MSSGRP' : None, # set if set to different HPSS group
'RDAGRP' : "decs",
'EMLSEND' : None, # path to sendmail, None if not exists
'DSCHECK' : None, # carry some cached dscheck information
'PGDBBUF' : None, # reference to a connected database object
'HPSSLMT' : 10, # up limit of HPSS streams
Expand Down Expand Up @@ -1289,7 +1290,8 @@ def set_common_pglog():
SETPGLOG("LOGFILE", "pgdss.log") # log file name
SETPGLOG("EMLFILE", "pgemail.log") # email log file name
SETPGLOG("ERRFILE", '') # error file name
SETPGLOG("EMLSEND", "/usr/lib/sendmail -t") # send email command
sm = "/usr/sbin/sendmail"
if valid_command(sm): SETPGLOG("EMLSEND", f"{sm} -t") # send email command
SETPGLOG("DBGLEVEL", '') # debug level
SETPGLOG("DBGPATH", PGLOG['DSSDBHM']+"/log") # path to debug log file
SETPGLOG("OBJCTBKT", "rda-data") # default Bucket on Object Store
Expand Down
32 changes: 21 additions & 11 deletions src/rda_python_common/PgOPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -1684,25 +1684,35 @@ def send_request_email_notice(pgrqst, errmsg, fcount, rstat, readyfile = None, p
for ekey in einfo:
ebuf = re.sub(r'<{}>'.format(ekey), einfo[ekey], ebuf)


if PgLOG.PGLOG['DSCHECK'] and not pgpart:
tbl = "dscheck"
cnd = "cindex = {}".format(PgLOG.PGLOG['DSCHECK']['cindex'])
else:
tbl = "dsrqst"
cnd = "rindex = {}".format(pgrqst['rindex'])

if not PgDBI.cache_customized_email(tbl, "einfo", cnd, ebuf, 0): return 'E'
if errmsg:
PgLOG.pglog("Error Email {} cached to {}.einfo for {}:\n{}".format(einfo['SENDER'], tbl, cnd, errmsg),
PGOPT['errlog'])
if PgLOG.PGLOG['EMLSEND'] and PgLOG.send_customized_email(f"{tbl}.{cnd}", ebuf, 0):
if errmsg:
PgLOG.pglog("Error Email sent to {} for {}.{}:\n{}".format(einfo['SENDER'], tbl, cnd, errmsg), PGOPT['errlog'])
readyfile = None
else:
PgLOG.pglog("{}Email sent to {} for {}.{}\nSubset: {}".format(("Customized " if pgrqst['enotice'] else ""), einfo['RECEIVER'], tbl, cnd, einfo['SUBJECT']),
PGOPT['wrnlog']|PgLOG.FRCLOG)
else:
PgLOG.pglog("{}Email {} cached to {}.einfo for {}\nSubset: {}".format(("Customized " if pgrqst['enotice'] else ""), einfo['RECEIVER'], tbl, cnd, einfo['SUBJECT']),
PGOPT['wrnlog']|PgLOG.FRCLOG)
if readyfile:
rf = open(readyfile, 'w')
rf.write(ebuf)
rf.close()
PgFile.set_local_mode(readyfile, 1, PgLOG.PGLOG['FILEMODE'])
if not PgDBI.cache_customized_email(tbl, "einfo", cnd, ebuf, 0): return 'E'
if errmsg:
PgLOG.pglog("Error Email {} cached to {}.einfo for {}:\n{}".format(einfo['SENDER'], tbl, cnd, errmsg), PGOPT['errlog'])
readyfile = None
else:
PgLOG.pglog("{}Email {} cached to {}.einfo for {}\nSubset: {}".format(("Customized " if pgrqst['enotice'] else ""), einfo['RECEIVER'], tbl, cnd, einfo['SUBJECT']),
PGOPT['wrnlog']|PgLOG.FRCLOG)

if readyfile:
rf = open(readyfile, 'w')
rf.write(ebuf)
rf.close()
PgFile.set_local_mode(readyfile, 1, PgLOG.PGLOG['FILEMODE'])

return rstat

Expand Down