From 3cca5ecf8e6bf8781691be5b5f3319e11776e187 Mon Sep 17 00:00:00 2001 From: S-Stephen Date: Thu, 16 Feb 2017 11:05:23 +0000 Subject: [PATCH] #7 queue all notifications, add a cron script and configure in cron on mws3 setup, added array of admin contacts in case sendingn fails --- deploy/mws3.cron | 20 ++++++++++++++++++++ deploy/setup_mws3.py | 5 +++++ edpcmentoring/edpcmentoring/settings.py | 8 +++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 deploy/mws3.cron diff --git a/deploy/mws3.cron b/deploy/mws3.cron new file mode 100644 index 0000000..11ee8ca --- /dev/null +++ b/deploy/mws3.cron @@ -0,0 +1,20 @@ +import subprocess + +def subprocess_cmd(command): + """ + Function used to run shell commands + This is Python that creates a Python env + which then runs Python commands - hhmmm + """ + process = subprocess.Popen(command,stdout=subprocess.PIPE, shell=True) + proc_stdout = process.communicate()[0].strip() + print proc_stdout + + +import os + +filedir_path = "%s/.." % os.path.dirname(os.path.realpath(__file__)) + +schemacmd=". %s/env/bin/activate; %s/edpcmentoring/manage.py emit_notices --settings=edpcmentoring.settings_mws3 2>&1 | sed -e '/RemovedInDjango110Warning/d' | sed -e '/raven_return, name/d'" % (filedir_path,filedir_path) +subprocess_cmd(schemacmd) + diff --git a/deploy/setup_mws3.py b/deploy/setup_mws3.py index 197202b..ffb9ba6 100644 --- a/deploy/setup_mws3.py +++ b/deploy/setup_mws3.py @@ -178,6 +178,11 @@ def subprocess_cmd(command): subprocess_cmd(copystatic) print "done\n" +#install the cron job NB this wipes all other cron entries!: +print "installing the cronjob" +installcron = "(crontab -l | head -n6; echo \"*/5 * * * * python %s/deploy/mws3.cron\") | crontab -" % (filedir_path) +subprocess_cmd(installcron) +print "installed cron" diff --git a/edpcmentoring/edpcmentoring/settings.py b/edpcmentoring/edpcmentoring/settings.py index 27002a3..a678474 100644 --- a/edpcmentoring/edpcmentoring/settings.py +++ b/edpcmentoring/edpcmentoring/settings.py @@ -135,11 +135,17 @@ # Uncomment to activate the email notifications # PS you may wish to update user record emails to test messages: update auth_user set email = concat('crsid+',username.'@cam.ac.uk') #PINAX_NOTIFICATIONS_BACKENDS=[("email", "pinax.notifications.backends.email.EmailBackend"),] +# queue all notifications until emit_notices is called +#We can there for check for queued notifications and failed mail_logs (can we join the two?) +PINAX_NOTIFICATIONS_QUEUE_ALL=True EMAIL_BACKEND = 'email_log.backends.EmailBackend' EMAIL_SUBJECT_PREFIX = '[EDPC Mentoring] ' -EMAIL_LOG_BACKEND = 'django.core.mail.backends.dummy.EmailBackend' +#EMAIL_LOG_BACKEND = 'django.core.mail.backends.dummy.EmailBackend' DEFAULT_FROM_EMAIL = 'edpc-mentoring@eng.cam.ac.uk' +#exception info (eg failure to run emit_notices) emailed to: +ADMIN = [('S.Shorrock','sms67+edpc@cam.ac.uk'),('Mentoring App','edpc-mentoring@eng.cam.ac.uk')] + # Login URLs LOGIN_URL = 'raven_login' LOGIN_REDIRECT_URL = 'mentoring:index'