i like to have a hook (eventtype: queuejob) that sets the job attribute Mail_Users to a default value if it the job was submitted without an email address. Please see the following code:
import pbs
import sys
try:
e = pbs.event()
j = e.job
who = e.requestor
mailusers = str(j.Mail_Users)
user = str(who)
if (mailusers == 'None'):
j.Mail_Users = pbs.email_list(user.split('@')[0] + '@mailserver.example.com')
except SystemExit:
pass
except:
pbs.logmsg(pbs.EVENT_DEBUG2, "redirect_mail: exception %s" % '.'.join([repr(sys.exc_info([0]),repr(sys.exc_info()[1])]))
e.accept()
If I print j.Mail_Users to a file after it has been set, the new mail address is there. The problem is that it seems to not get pushed back to pbs. What am I doing wrong?
Thank you for your help!
@roemer2201 I have tested the below code and it worked for me:
import pbs
import sys
e = pbs.event()
j = e.job
who = e.requestor
mailusers = str(j.Mail_Users)
pbs.logmsg(pbs.LOG_DEBUG, 'The mail users are %s' % str(mailusers))
user = str(who)
pbs.logmsg(pbs.LOG_DEBUG, 'The users is %s' % str(user))
if mailusers == "None":
pbs.logmsg(pbs.LOG_DEBUG, 'I am here')
j.Mail_Users = pbs.email_list('ilovepbspro@pbspro.org')
e.accept()
Thank you for your reply! Unfortunately it is not working on my side: According to the logs, the script does indeed set “j.Mail_Users” correctly, but it does not apply to the job. I submit a testjob with
echo "sleep 300" | qsub -m abe
But the Mail_Users attribute is not added to the job:
[user@login01 ~]$ qstat -f | grep Mail
Mail_Points = abe
This results in an outgoing mail to “user@login01.cluster”. Can you please check, if your jobs get the Mail_Users attribute after the hook has run?
I have added an extra Debug Line at the end:
mailusers2 = str(j.Mail_Users)
pbs.logmsg(pbs.LOG_DEBUG, 'The mail users are now %s' % str(mailusers2))
Server Logs:
08/09/2019 10:13:25;0086;Server@hpcc1;Svr;Server@hpcc1;Compiling script file: </var/spool/pbs/server_priv/hooks/redirect_mail.PY>
08/09/2019 10:13:25;0006;Server@hpcc1;Hook;Server@hpcc1;The mail users are None
08/09/2019 10:13:25;0006;Server@hpcc1;Hook;Server@hpcc1;The users is user
08/09/2019 10:13:25;0006;Server@hpcc1;Hook;Server@hpcc1;I am here
08/09/2019 10:13:25;0006;Server@hpcc1;Hook;Server@hpcc1;The mail users are now ilovepbspro@pbspro.org
I tried to implement the hook on a PBS v14.2.1 system and this shows the results above. I tried it again on PBS v19.2.2 and here it works. So what does PBS v14 do different?