[cig-commits] commit: Tell everyone if the job failed

Mercurial hg at geodynamics.org
Sun Jul 3 20:04:30 PDT 2011


changeset:   14:7755cdf1347f
user:        Walter Landry <wlandry at caltech.edu>
date:        Tue Jun 21 15:58:02 2011 -0700
files:       SeismoWebPortal/views.py
description:
Tell everyone if the job failed


diff -r 83f3a2eac2cd -r 7755cdf1347f SeismoWebPortal/views.py
--- a/SeismoWebPortal/views.py	Tue Jun 21 15:54:55 2011 -0700
+++ b/SeismoWebPortal/views.py	Tue Jun 21 15:58:02 2011 -0700
@@ -323,10 +323,7 @@ def updateRunStatus(request, daemonCode,
             run.status = new_data['status']
             if run.status in ['done', 'error']:
                 run.finished = datetime.datetime.now()
-                if run.status == 'error':
-                    notifyAdminsOfFailedRun(run)
-                else:
-                    notifyUserOfSuccessfulRun(run, request, root)
+                notifyEveryoneOfCompletion(run, request, root)
             run.save()
             response.write(repr('OK'))
         return response
@@ -338,27 +335,9 @@ def updateRunStatus(request, daemonCode,
                               {'form': form, 'action': request.path},
                               RequestContext(request, {}))
 
-
-def notifyAdminsOfFailedRun(run):
+def notifyEveryoneOfCompletion(run, request, root):
+    from django.core.mail import send_mail
     from django.core.mail import mail_admins
-
-    subject = 'run %d failed' % run.id
-    message = ["Run %d has failed." % run.id,
-               "",
-               "jobs",
-               "----",
-               ]
-    for job in run.job_set.all():
-        message.append("%d %s %s %s" % (job.id, job.task, job.status, job.url))
-    message = "\n".join(message)
-    
-    mail_admins(subject, message, fail_silently=True)
-    
-    return
-
-
-def notifyUserOfSuccessfulRun(run, request, root):
-    from django.core.mail import send_mail
 
     server = request.META['SERVER_NAME']
     port = request.META['SERVER_PORT']
@@ -371,17 +350,34 @@ def notifyUserOfSuccessfulRun(run, reque
         root = root,
         )
 
-    subject = "Your simulation has finished running."
-    message = ["Your simulation has finished running."
-               "",
-               "To download the output, visit the portal:",
-               "",
-               "%(protocol)s://%(server)s%(root)s/" % kwds,
-               "",
-               "Sincerely,",
-               "The CIG Seismology Web Portal",
-               ]
-    message = "\n".join(message)
+    # If the job failed, tell everyone.  If it succeeded, tell just
+    # the user.
+
+    if run.status=="error":
+        subject = 'run %d failed' % run.id
+        message = ["Run %d has failed." % run.id,
+                   "",
+                   "jobs",
+                   "----",
+                   ]
+        for job in run.job_set.all():
+            message.append("%d %s %s %s" % (job.id, job.task, job.status, job.url))
+        message = "\n".join(message)
+    
+        mail_admins(subject, message, fail_silently=False)
+    else:
+
+        subject = "Your simulation has finished running."
+        message = ["Your simulation has finished running."
+                   "",
+                   "To download the output, visit the portal:",
+                   "",
+                   "%(protocol)s://%(server)s%(root)s/" % kwds,
+                   "",
+                   "Sincerely,",
+                   "The CIG Seismology Web Portal",
+                   ]
+        message = "\n".join(message)
 
     # Currently, we only send e-mail to the user who submitted the
     # request.  But other users may have created Runs which match the



More information about the CIG-COMMITS mailing list